예제 #1
0
func (pl PostingList) readBlock(idx uint, lastDoc match.DocId) (uint, Block) {
	bytes := pl.Raw[idx:]

	if bytes[0]&blockTypeDoc == blockTypeDoc {
		docSize, docOffset := varint.Read(bytes)

		doc := match.DocId(docOffset) + lastDoc
		data := Block{idx, false, 1, doc, 0}

		return docSize, data
	}

	nextBlockOffset := readUInt(bytes[1:])
	nextDocOffset := readUInt64(bytes[5:])

	data := Block{idx, true, nextBlockOffset, lastDoc, match.DocId(uint64(lastDoc) + nextDocOffset)}
	return 1 + SKIP_PAYLOAD, data
}
예제 #2
0
func FromBytes(raw []byte) *PostingList {
	maxId := readUInt64(raw)
	raw = raw[8:]

	n, rawLen := varint.Read(raw)
	raw = raw[n:]
	raw = raw[:rawLen]

	return &PostingList{raw, match.DocId(maxId)}
}
예제 #3
0
func (pl PostingList) blocks(visit func(Block)) {
	i := uint(0)
	lastDoc := match.DocId(0)

	// walk through the blocks
	numBlocks := uint(len(pl.Raw))
	for i < numBlocks {
		r, block := pl.readBlock(i, lastDoc)

		lastDoc = block.doc

		visit(block)

		i += r
	}
}
예제 #4
0
func docId(block, bit uint) (doc match.DocId) {
	return match.DocId(block*32 + bit)
}