Esempio n. 1
0
func (pl *PostingList) ToBytes(dst []byte) {
	if cap(dst) < pl.Size() {
		panic("dst is too small")
	}

	writeUInt64(dst, uint64(pl.MaxId))
	dst = dst[8:]

	written := varint.VarInt(len(pl.Raw)).Write(dst[8:])
	dst = dst[written:]

	copy(dst, pl.Raw)
}
Esempio n. 2
0
func (pl *PostingList) Add(doc match.DocId) (err os.Error) {
	numBlocks := uint(len(pl.Raw))
	if numBlocks > 0 && doc < pl.MaxId {
		return os.NewError("doc isn't larger than current max doc")
	}

	diff := varint.VarInt(doc - pl.MaxId)

	size := diff.Size()

	if size+numBlocks >= uint(cap(pl.Raw)) {
		return os.NewError("Out of space")
	}

	pl.Raw = pl.Raw[0 : numBlocks+size]
	diff.Write(pl.Raw[numBlocks:])

	// Set the high bit
	pl.Raw[numBlocks] = blockTypeDoc | pl.Raw[numBlocks]
	pl.MaxId = doc

	return nil
}
Esempio n. 3
0
func (pl *PostingList) Size() int {
	return len(pl.Raw) + int(varint.VarInt(len(pl.Raw)).Size()) + 8
}