caio/go-tdigest · summary.go
go logo
func (s *summary) HeadSum(idx int) (sum float64) {
	return float64(sumUntilIndex(s.counts, idx))
}
Similar code snippets
1.
caio/go-tdigest · summary.go
Match rating: 61.33% · See similar code snippets
go logo
func (s *summary) FloorSum(sum float64) (index int, cumSum float64) {
	index = -1
	for i, count := range s.counts {
		if cumSum <= sum {
			index = i
		} else {
			break
		}
		cumSum += float64(count)
	}
	if index != -1 {
		cumSum -= float64(s.counts[index])
	}
	return index, cumSum
}
2.
yourbasic/fenwick · list.go
Match rating: 55.47% · See similar code snippets
go logo
func (l *List) Sum(i int) int64 {
	var sum int64
	for i > 0 {
		sum += l.tree[i-1]
		i -= i & -i
	}
	return sum
}
3.
hprose/hprose-golang · fasthttp_hello_server.go
Match rating: 55.12% · See similar code snippets
go logo
func (Service) Sum(a ...int) int {
	sum := 0
	for _, i := range a {
		sum += i
	}
	return sum
}
4.
golang/tour · named-results.go
Match rating: 54.98% · See similar code snippets
go logo
func split(sum int) (x, y int) {
	x = sum * 4 / 9
	y = sum - x
	return
}
5.
golang/tour · channels.go
Match rating: 54.38% · See similar code snippets
go logo
func sum(s []int, c chan int) {
	sum := 0
	for _, v := range s {
		sum += v
	}
	c <- sum // send sum to c
}
6.
thoas/go-funk · typesafe.go
Match rating: 53.87% · See similar code snippets
go logo
func SumInt(s []int) (sum int) {
	for _, v := range s {
		sum += v
	}
	return
}
7.
aclements/go-moremath · alg.go
Match rating: 53.81% · See similar code snippets
go logo
func sumint(xs []int) int {
	sum := 0
	for _, x := range xs {
		sum += x
	}
	return sum
}
8.
gizak/termui · utils.go
Match rating: 51.31% · See similar code snippets
go logo
func SumIntSlice(slice []int) int {
	sum := 0
	for _, val := range slice {
		sum += val
	}
	return sum
}
9.
src-d/go-git · repository.go
Match rating: 51.05% · See similar code snippets
go logo
func countTrue(vals ...bool) int {
	sum := 0
	for _, v := range vals {
		if v {
			sum++
		}
	}
	return sum
}
10.
heroku/instruments · aggregate.go
Match rating: 50.95% · See similar code snippets
go logo
func Mean(values []int64) float64 {
	if len(values) == 0 {
		return 0.0
	}
	var sum int64
	for _, v := range values {
		sum += v
	}
	return float64(sum) / float64(len(values))
}