MCPcopy Index your code
hub / github.com/dgraph-io/dgraph-benchmarks / Encode

Function Encode

bitmap/codec.go:358–364  ·  view source on GitHub ↗

Encode takes in a list of uids and a block size. It would pack these uids into blocks of the given size, with the last block having fewer uids. Within each block, it stores the first uid as base. For each next uid, a delta = uids[i] - uids[i-1] is stored. Protobuf uses Varint encoding, as mentioned

(uids []uint64, blockSize int)

Source from the content-addressed store, hash-verified

356// bytes. Our benchmarks on artificial data show compressed size to be 13% of the original. This
357// mechanism is a LOT simpler to understand and if needed, debug.
358func Encode(uids []uint64, blockSize int) *UidPack {
359 enc := Encoder{BlockSize: blockSize}
360 for _, uid := range uids {
361 enc.Add(uid)
362 }
363 return enc.Done()
364}
365
366// EncodeFromBuffer is the same as Encode but it accepts a byte slice instead of a uint64 slice.
367func EncodeFromBuffer(buf []byte, blockSize int) *UidPack {

Callers 3

BenchmarkMarshalFunction · 0.85
BenchmarkUnmarshalFunction · 0.85
BenchmarkContainsFunction · 0.85

Calls 2

AddMethod · 0.95
DoneMethod · 0.95

Tested by 3

BenchmarkMarshalFunction · 0.68
BenchmarkUnmarshalFunction · 0.68
BenchmarkContainsFunction · 0.68