Skip to content

Commit

Permalink
Fixed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshil Goel committed Oct 11, 2023
1 parent 36b2722 commit 170f37c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
11 changes: 4 additions & 7 deletions algo/uidlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,11 @@ func IntersectCompressedWithBin(dec *codec.Decoder, q []uint64, o *[]uint64) {
if len(blockUids) == 0 {
break
}
if ld*linVsBinRatio < len(q) {
q = q[IntersectWithBin(blockUids, q, o):]
} else {
// For small enough difference between two arrays, we should just
// do lin intersect
_, off := IntersectWithLin(blockUids, q, o)
q = q[off:]
_, off := IntersectWithJump(blockUids, q, o)
if off == 0 {
off = 1 // if v[k] isn't in u, move forward
}
q = q[off:]
if len(q) == 0 {
return
}
Expand Down
16 changes: 8 additions & 8 deletions codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ func (d *Decoder) ApproxLen() int {

type searchFunc func(int) bool

// SeekToBlock will find the nearest block, and unpack it. Unlike Seek, it doesn't
// apply search in the resulting uid list and then move the pointer forward. When we are going
// to intersect the list later, this function is useful.
// SeekToBlock will find the block containing the uid, and unpack it. When we are going to
// intersect the list later, this function is useful. As this function skips the search function
// and returns the entire block, it is faster than Seek. Unlike seek, we don't truncate the uids
// returned, which would be done by the intersect function anyways.
func (d *Decoder) SeekToBlock(uid uint64, whence seekPos) []uint64 {
if d.Pack == nil {
return []uint64{}
Expand All @@ -241,25 +242,24 @@ func (d *Decoder) SeekToBlock(uid uint64, whence seekPos) []uint64 {
prevBlockIdx = 0
}

pack := d.Pack
blocksFunc := func() searchFunc {
var f searchFunc
switch whence {
case SeekStart:
f = func(i int) bool { return pack.Blocks[i+prevBlockIdx].Base >= uid }
f = func(i int) bool { return d.Pack.Blocks[i+prevBlockIdx].Base >= uid }
case SeekCurrent:
f = func(i int) bool { return pack.Blocks[i+prevBlockIdx].Base > uid }
f = func(i int) bool { return d.Pack.Blocks[i+prevBlockIdx].Base > uid }
}
return f
}

idx := sort.Search(len(pack.Blocks[prevBlockIdx:]), blocksFunc()) + prevBlockIdx
idx := sort.Search(len(d.Pack.Blocks[prevBlockIdx:]), blocksFunc()) + prevBlockIdx
// The first block.Base >= uid.
if idx == 0 {
return d.UnpackBlock()
}
// The uid is the first entry in the block.
if idx < len(pack.Blocks) && pack.Blocks[idx].Base == uid {
if idx < len(d.Pack.Blocks) && d.Pack.Blocks[idx].Base == uid {
d.blockIdx = idx
return d.UnpackBlock()
}
Expand Down

0 comments on commit 170f37c

Please sign in to comment.