MCPcopy
hub / github.com/google/codesearch / mergePost

Method mergePost

index/write.go:284–325  ·  view source on GitHub ↗

mergePost reads the flushed index entries and merges them into posting lists, writing the resulting lists to out.

(out *bufWriter)

Source from the content-addressed store, hash-verified

282// mergePost reads the flushed index entries and merges them
283// into posting lists, writing the resulting lists to out.
284func (ix *IndexWriter) mergePost(out *bufWriter) {
285 var h postHeap
286
287 log.Printf("merge %d files + mem", len(ix.postFile))
288 for _, f := range ix.postFile {
289 h.addFile(f)
290 }
291 sortPost(ix.post)
292 h.addMem(ix.post)
293
294 npost := 0
295 e := h.next()
296 offset0 := out.offset()
297 for {
298 npost++
299 offset := out.offset() - offset0
300 trigram := e.trigram()
301 ix.buf[0] = byte(trigram >> 16)
302 ix.buf[1] = byte(trigram >> 8)
303 ix.buf[2] = byte(trigram)
304
305 // posting list
306 fileid := ^uint32(0)
307 nfile := uint32(0)
308 out.write(ix.buf[:3])
309 for ; e.trigram() == trigram && trigram != 1<<24-1; e = h.next() {
310 out.writeUvarint(e.fileid() - fileid)
311 fileid = e.fileid()
312 nfile++
313 }
314 out.writeUvarint(0)
315
316 // index entry
317 ix.postIndex.write(ix.buf[:3])
318 ix.postIndex.writeUint32(nfile)
319 ix.postIndex.writeUint32(offset)
320
321 if trigram == 1<<24-1 {
322 break
323 }
324 }
325}
326
327// A postChunk represents a chunk of post entries flushed to disk or
328// still in memory.

Callers 1

FlushMethod · 0.95

Calls 10

addFileMethod · 0.95
addMemMethod · 0.95
nextMethod · 0.95
sortPostFunction · 0.85
offsetMethod · 0.80
writeMethod · 0.80
writeUvarintMethod · 0.80
writeUint32Method · 0.80
trigramMethod · 0.45
fileidMethod · 0.45

Tested by

no test coverage detected