From 7ec48f238563b02c8d04ef2f7a0783c647503822 Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Thu, 25 Sep 2014 14:10:43 +0000 Subject: [PATCH] off by one take two --- index/brand.go | 6 +++--- index/general.go | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/index/brand.go b/index/brand.go index 94658d3c7..a0f64bbd1 100644 --- a/index/brand.go +++ b/index/brand.go @@ -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 { diff --git a/index/general.go b/index/general.go index 96485db3b..5c30276b7 100644 --- a/index/general.go +++ b/index/general.go @@ -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 }