Skip to content

Commit f26a064

Browse files
committed
Fixes a codesearch bug in the index writer.
1 parent c68f905 commit f26a064

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

codesearch/index/write.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ func (h *postHeap) siftUp(j int) {
483483
break
484484
}
485485
ch[i], ch[j] = ch[j], ch[i]
486+
j = i
486487
}
487488
}
488489

codesearch/index/write_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,19 @@ func TestTrivialWrite(t *testing.T) {
163163
func TestTrivialWriteDisk(t *testing.T) {
164164
testTrivialWrite(t, true)
165165
}
166+
167+
func TestHeap(t *testing.T) {
168+
h := &postHeap{}
169+
es := []postEntry{7, 4, 3, 2, 4}
170+
for _, e := range es {
171+
h.addMem([]postEntry{e})
172+
}
173+
if len(h.ch) != len(es) {
174+
t.Fatalf("wrong heap size: %d, want %d", len(h.ch), len(es))
175+
}
176+
for a, b := h.next(), h.next(); b.trigram() != (1<<24 - 1); a, b = b, h.next() {
177+
if a > b {
178+
t.Fatalf("%d should <= %d", a, b)
179+
}
180+
}
181+
}

0 commit comments

Comments
 (0)