From f26a0642648ad56bd3143db70dbefd7f85dc44a8 Mon Sep 17 00:00:00 2001 From: Kelly Norton Date: Thu, 23 Mar 2017 07:46:26 -0400 Subject: [PATCH] Fixes a codesearch bug in the index writer. --- codesearch/index/write.go | 1 + codesearch/index/write_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/codesearch/index/write.go b/codesearch/index/write.go index 9905bdea..ff0f280f 100644 --- a/codesearch/index/write.go +++ b/codesearch/index/write.go @@ -483,6 +483,7 @@ func (h *postHeap) siftUp(j int) { break } ch[i], ch[j] = ch[j], ch[i] + j = i } } diff --git a/codesearch/index/write_test.go b/codesearch/index/write_test.go index d2653aec..4b3e2fcd 100644 --- a/codesearch/index/write_test.go +++ b/codesearch/index/write_test.go @@ -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) + } + } +}