@@ -223,9 +223,10 @@ func (d *Decoder) ApproxLen() int {
223223
224224type searchFunc func (int ) bool
225225
226- // SeekToBlock will find the nearest block, and unpack it. Unlike Seek, it doesn't
227- // apply search in the resulting uid list and then move the pointer forward. When we are going
228- // to intersect the list later, this function is useful.
226+ // SeekToBlock will find the block containing the uid, and unpack it. When we are going to
227+ // intersect the list later, this function is useful. As this function skips the search function
228+ // and returns the entire block, it is faster than Seek. Unlike seek, we don't truncate the uids
229+ // returned, which would be done by the intersect function anyways.
229230func (d * Decoder ) SeekToBlock (uid uint64 , whence seekPos ) []uint64 {
230231 if d .Pack == nil {
231232 return []uint64 {}
@@ -241,25 +242,24 @@ func (d *Decoder) SeekToBlock(uid uint64, whence seekPos) []uint64 {
241242 prevBlockIdx = 0
242243 }
243244
244- pack := d .Pack
245245 blocksFunc := func () searchFunc {
246246 var f searchFunc
247247 switch whence {
248248 case SeekStart :
249- f = func (i int ) bool { return pack .Blocks [i + prevBlockIdx ].Base >= uid }
249+ f = func (i int ) bool { return d . Pack .Blocks [i + prevBlockIdx ].Base >= uid }
250250 case SeekCurrent :
251- f = func (i int ) bool { return pack .Blocks [i + prevBlockIdx ].Base > uid }
251+ f = func (i int ) bool { return d . Pack .Blocks [i + prevBlockIdx ].Base > uid }
252252 }
253253 return f
254254 }
255255
256- idx := sort .Search (len (pack .Blocks [prevBlockIdx :]), blocksFunc ()) + prevBlockIdx
256+ idx := sort .Search (len (d . Pack .Blocks [prevBlockIdx :]), blocksFunc ()) + prevBlockIdx
257257 // The first block.Base >= uid.
258258 if idx == 0 {
259259 return d .UnpackBlock ()
260260 }
261261 // The uid is the first entry in the block.
262- if idx < len (pack . Blocks ) && pack .Blocks [idx ].Base == uid {
262+ if idx < len (d . Pack . Blocks ) && d . Pack .Blocks [idx ].Base == uid {
263263 d .blockIdx = idx
264264 return d .UnpackBlock ()
265265 }
0 commit comments