Skip to content

Commit

Permalink
Fixes a codesearch bug in the index writer.
Browse files Browse the repository at this point in the history
  • Loading branch information
kellegous committed Mar 23, 2017
1 parent c68f905 commit f26a064
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions codesearch/index/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ func (h *postHeap) siftUp(j int) {
break
}
ch[i], ch[j] = ch[j], ch[i]
j = i
}
}

Expand Down
16 changes: 16 additions & 0 deletions codesearch/index/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,19 @@ func TestTrivialWrite(t *testing.T) {
func TestTrivialWriteDisk(t *testing.T) {
testTrivialWrite(t, true)
}

func TestHeap(t *testing.T) {
h := &postHeap{}
es := []postEntry{7, 4, 3, 2, 4}
for _, e := range es {
h.addMem([]postEntry{e})
}
if len(h.ch) != len(es) {
t.Fatalf("wrong heap size: %d, want %d", len(h.ch), len(es))
}
for a, b := h.next(), h.next(); b.trigram() != (1<<24 - 1); a, b = b, h.next() {
if a > b {
t.Fatalf("%d should <= %d", a, b)
}
}
}

0 comments on commit f26a064

Please sign in to comment.