diff --git a/index.go b/index.go index c012b7c76..0108358f4 100644 --- a/index.go +++ b/index.go @@ -702,7 +702,7 @@ func (r *indexReader) Postings(name, value string) (Postings, error) { if len(b)%4 != 0 { return nil, errors.Wrap(errInvalidSize, "plain postings entry") } - return newBytePostings(b), nil + return newBigEndianPostings(b), nil } type stringTuples struct { diff --git a/postings.go b/postings.go index 3d6e32759..2c6f89022 100644 --- a/postings.go +++ b/postings.go @@ -241,26 +241,28 @@ func (it *listPostings) Err() error { return nil } -type bytePostings struct { +// bigEndianPostings implements the Postings interface over a byte stream of +// big endian numbers. +type bigEndianPostings struct { list []byte idx int } -func newBytePostings(list []byte) *bytePostings { - return &bytePostings{list: list, idx: -1} +func newBigEndianPostings(list []byte) *bigEndianPostings { + return &bigEndianPostings{list: list, idx: -1} } -func (it *bytePostings) At() uint32 { +func (it *bigEndianPostings) At() uint32 { idx := 4 * it.idx return binary.BigEndian.Uint32(it.list[idx : idx+4]) } -func (it *bytePostings) Next() bool { +func (it *bigEndianPostings) Next() bool { it.idx++ return it.idx*4 < len(it.list) } -func (it *bytePostings) Seek(x uint32) bool { +func (it *bigEndianPostings) Seek(x uint32) bool { num := len(it.list) / 4 // Do binary search between current position and end. it.idx += sort.Search(num-it.idx, func(i int) bool { @@ -271,7 +273,7 @@ func (it *bytePostings) Seek(x uint32) bool { return it.idx*4 < len(it.list) } -func (it *bytePostings) Err() error { +func (it *bigEndianPostings) Err() error { return nil }