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

Method UnpackBlock

bitmap/codec.go:177–223  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

175}
176
177func (d *Decoder) UnpackBlock() []uint64 {
178 if len(d.uids) > 0 {
179 // We were previously preallocating the d.uids slice to block size. This caused slowdown
180 // because many blocks are small and only contain a few ints, causing wastage while still
181 // paying cost of allocation.
182 d.uids = d.uids[:0]
183 }
184
185 if d.blockIdx >= len(d.Pack.Blocks) {
186 return d.uids
187 }
188 block := d.Pack.Blocks[d.blockIdx]
189
190 last := block.Base
191 d.uids = append(d.uids, last)
192
193 tmpUids := make([]uint32, 4)
194 var sum uint64
195 encData := block.Deltas
196
197 for uint32(len(d.uids)) < block.NumUids {
198 if len(encData) < 17 {
199 // Decode4 decodes 4 uids from encData. It moves slice(encData) forward while
200 // decoding and expects it to be of length >= 4 at all the stages.
201 // The SSE code tries to read 16 bytes past the header(1 byte).
202 // So we are padding encData to increase its length to 17 bytes.
203 // This is a workaround for https://github.com/dgryski/go-groupvarint/issues/1
204 //
205 // We should NEVER write to encData, because it references block.Deltas, which is laid
206 // out on an allocator.
207 tmp := make([]byte, 17)
208 copy(tmp, encData)
209 encData = tmp
210 }
211
212 groupvarint.Decode4(tmpUids, encData)
213 encData = encData[groupvarint.BytesUsed[encData[0]]:]
214 for i := 0; i < 4; i++ {
215 sum = last + uint64(tmpUids[i])
216 d.uids = append(d.uids, sum)
217 last = sum
218 }
219 }
220
221 d.uids = d.uids[:block.NumUids]
222 return d.uids
223}
224
225// ApproxLen returns the approximate number of UIDs in the UidPack object.
226func (d *Decoder) ApproxLen() int {

Callers 3

SeekMethod · 0.95
LinearSeekMethod · 0.95
NextMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected