Skip to content

Commit 7bf9605

Browse files
fixed test
1 parent b8b96d6 commit 7bf9605

File tree

2 files changed

+19
-39
lines changed

2 files changed

+19
-39
lines changed

algo/uidlist_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ func TestIntersectCompressedWithLinJump(t *testing.T) {
554554
}
555555

556556
func TestIntersectCompressedWithBin(t *testing.T) {
557-
lengths := []int{0, 1, 3, 11, 100}
557+
lengths := []int{0, 1, 3, 11, 100, 500, 1000}
558558

559559
for _, N1 := range lengths {
560560
for _, N2 := range lengths {
@@ -579,7 +579,7 @@ func TestIntersectCompressedWithBin(t *testing.T) {
579579
}
580580

581581
func TestIntersectCompressedWithBinMissingSize(t *testing.T) {
582-
lengths := []int{0, 1, 3, 11, 100}
582+
lengths := []int{0, 1, 3, 11, 100, 500, 1000}
583583

584584
for _, N1 := range lengths {
585585
for _, N2 := range lengths {

codec/codec.go

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -286,59 +286,39 @@ func (d *Decoder) Seek(uid uint64, whence seekPos) []uint64 {
286286
if d.Pack == nil {
287287
return []uint64{}
288288
}
289-
290-
prevBlockIdx := d.blockIdx
291-
pack := d.Pack
292-
blocksToSearch := pack.Blocks
293-
offset := 0
294-
if len(d.uids) > 0 {
295-
first := d.uids[0]
296-
second := d.uids[len(d.uids)-1]
297-
298-
if uid >= first && uid <= second {
299-
blocksToSearch = nil
300-
} else if uid > second {
301-
blocksToSearch = blocksToSearch[prevBlockIdx:]
302-
offset = prevBlockIdx
303-
} else {
304-
blocksToSearch = blocksToSearch[:prevBlockIdx]
305-
}
306-
}
307-
289+
d.blockIdx = 0
308290
if uid == 0 {
309291
return d.UnpackBlock()
310292
}
311293

294+
pack := d.Pack
312295
blocksFunc := func() searchFunc {
313296
var f searchFunc
314297
switch whence {
315298
case SeekStart:
316-
f = func(i int) bool { return blocksToSearch[i].Base >= uid }
299+
f = func(i int) bool { return pack.Blocks[i].Base >= uid }
317300
case SeekCurrent:
318-
f = func(i int) bool { return blocksToSearch[i].Base > uid }
301+
f = func(i int) bool { return pack.Blocks[i].Base > uid }
319302
}
320303
return f
321304
}
322305

306+
idx := sort.Search(len(pack.Blocks), blocksFunc())
307+
// The first block.Base >= uid.
308+
if idx == 0 {
309+
return d.UnpackBlock()
310+
}
311+
// The uid is the first entry in the block.
312+
if idx < len(pack.Blocks) && pack.Blocks[idx].Base == uid {
313+
d.blockIdx = idx
314+
return d.UnpackBlock()
315+
}
316+
323317
// Either the idx = len(pack.Blocks) that means it wasn't found in any of the block's base. Or,
324318
// we found the first block index whose base is greater than uid. In these cases, go to the
325319
// previous block and search there.
326-
if blocksToSearch != nil {
327-
idx := sort.Search(len(blocksToSearch), blocksFunc()) + offset
328-
// The first block.Base >= uid.
329-
if idx == 0 {
330-
return d.UnpackBlock()
331-
}
332-
333-
// The uid is the first entry in the block.
334-
if idx < len(pack.Blocks) && pack.Blocks[idx].Base == uid {
335-
d.blockIdx = idx
336-
return d.UnpackBlock()
337-
}
338-
339-
d.blockIdx = idx - 1 // Move to the previous block. If blockIdx<0, unpack will deal with it.
340-
d.UnpackBlock() // And get all their uids.
341-
}
320+
d.blockIdx = idx - 1 // Move to the previous block. If blockIdx<0, unpack will deal with it.
321+
d.UnpackBlock() // And get all their uids.
342322

343323
uidsFunc := func() searchFunc {
344324
var f searchFunc

0 commit comments

Comments
 (0)