summaryrefslogtreecommitdiffstats
path: root/src/merger_test.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-07-18 03:10:49 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-07-18 03:14:33 +0900
commitbbe10f4f7745000c121b629ff68e81bba5a497f6 (patch)
treef166d6e6d649763db438407ddc7a749d237df11e /src/merger_test.go
parent5e72709613b816531c1e0aed6a710257e08bb5d8 (diff)
Consolidate Result and rank structs
By not storing item index twice, we can cut down the size of Result struct and now it makes more sense to store and pass Results by values. Benchmarks show no degradation of performance by additional pointer indirection for looking up index.
Diffstat (limited to 'src/merger_test.go')
-rw-r--r--src/merger_test.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/merger_test.go b/src/merger_test.go
index a4adee18..b98aca8a 100644
--- a/src/merger_test.go
+++ b/src/merger_test.go
@@ -15,11 +15,11 @@ func assert(t *testing.T, cond bool, msg ...string) {
}
}
-func randResult() *Result {
+func randResult() Result {
str := fmt.Sprintf("%d", rand.Uint32())
- return &Result{
- item: &Item{text: util.RunesToChars([]rune(str))},
- rank: rank{index: rand.Int31()}}
+ chars := util.RunesToChars([]rune(str))
+ chars.Index = rand.Int31()
+ return Result{item: &Item{text: chars}}
}
func TestEmptyMerger(t *testing.T) {
@@ -29,14 +29,14 @@ func TestEmptyMerger(t *testing.T) {
assert(t, len(EmptyMerger.merged) == 0, "Invalid merged list")
}
-func buildLists(partiallySorted bool) ([][]*Result, []*Result) {
+func buildLists(partiallySorted bool) ([][]Result, []Result) {
numLists := 4
- lists := make([][]*Result, numLists)
+ lists := make([][]Result, numLists)
cnt := 0
for i := 0; i < numLists; i++ {
numResults := rand.Int() % 20
cnt += numResults
- lists[i] = make([]*Result, numResults)
+ lists[i] = make([]Result, numResults)
for j := 0; j < numResults; j++ {
item := randResult()
lists[i][j] = item
@@ -45,7 +45,7 @@ func buildLists(partiallySorted bool) ([][]*Result, []*Result) {
sort.Sort(ByRelevance(lists[i]))
}
}
- items := []*Result{}
+ items := []Result{}
for _, list := range lists {
items = append(items, list...)
}