Skip to content

Commit 170f37c

Browse files
Fixed comments
1 parent 36b2722 commit 170f37c

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

algo/uidlist.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,11 @@ func IntersectCompressedWithBin(dec *codec.Decoder, q []uint64, o *[]uint64) {
112112
if len(blockUids) == 0 {
113113
break
114114
}
115-
if ld*linVsBinRatio < len(q) {
116-
q = q[IntersectWithBin(blockUids, q, o):]
117-
} else {
118-
// For small enough difference between two arrays, we should just
119-
// do lin intersect
120-
_, off := IntersectWithLin(blockUids, q, o)
121-
q = q[off:]
115+
_, off := IntersectWithJump(blockUids, q, o)
116+
if off == 0 {
117+
off = 1 // if v[k] isn't in u, move forward
122118
}
119+
q = q[off:]
123120
if len(q) == 0 {
124121
return
125122
}

codec/codec.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ func (d *Decoder) ApproxLen() int {
223223

224224
type 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.
229230
func (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

Comments
 (0)