MCPcopy
hub / github.com/dgraph-io/dgraph / Encode

Function Encode

codec/codec.go:393–399  ·  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

391// bytes. Our benchmarks on artificial data show compressed size to be 13% of the original. This
392// mechanism is a LOT simpler to understand and if needed, debug.
393func Encode(uids []uint64, blockSize int) *pb.UidPack {
394 enc := Encoder{BlockSize: blockSize}
395 for _, uid := range uids {
396 enc.Add(uid)
397 }
398 return enc.Done()
399}
400
401// EncodeFromBuffer is the same as Encode but it accepts a byte slice instead of a uint64 slice.
402func EncodeFromBuffer(buf []byte, blockSize int) *pb.UidPack {

Callers 11

benchmarkPackFunction · 0.92
benchmarkUnpackFunction · 0.92
FromBackupPostingListFunction · 0.92
TestUidPackFunction · 0.85
TestBufferUidPackFunction · 0.85
benchmarkUidPackEncodeFunction · 0.85
benchmarkUidPackDecodeFunction · 0.85
TestEncodingFunction · 0.85

Calls 2

AddMethod · 0.95
DoneMethod · 0.95

Tested by 8

TestUidPackFunction · 0.68
TestBufferUidPackFunction · 0.68
benchmarkUidPackEncodeFunction · 0.68
benchmarkUidPackDecodeFunction · 0.68
TestEncodingFunction · 0.68