off by one take two

This commit is contained in:
Todd Gruben 2014-09-25 14:10:43 +00:00
parent 5557f529a7
commit 7ec48f2385
2 changed files with 7 additions and 7 deletions

View file

@ -224,7 +224,7 @@ func dump(r RankList, n int) {
func (self *Brand) TopNAll(n int, categories []uint64) []Pair {
self.checkRank()
results := make([]Pair, n+1)
results := make([]Pair, 0, 0)
category := NewIntSet()
needCat := false
@ -244,10 +244,10 @@ func (self *Brand) TopNAll(n int, categories []uint64) []Pair {
if count >= n {
break
}
results[count] = Pair{pair.Key, pair.Count}
results = append(results, Pair{pair.Key, pair.Count})
count++
}
return results[:count]
return results
}
func (self *Brand) TopNCat(src_bitmap IBitmap, n int, category *IntSet) []Pair {

View file

@ -141,17 +141,17 @@ func (self *General) Load(requestChan chan Command, f *Fragment) {
func (self *General) TopNAll(n int, categories []uint64) []Pair {
results := make([]Pair, n)
results := make([]Pair, 0, 0)
count := 0
for k, _ := range self.keys {
if count > n {
if count >= n {
break
}
bm := self.Get(k)
results[count] = Pair{k, bm.Count()}
results = append(results, Pair{k, bm.Count()})
count++
}
return results[:count]
return results
}