Skip to content

Commit

Permalink
fix iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
absolutelightning committed Jun 13, 2024
1 parent 8ed4051 commit bcad086
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
14 changes: 13 additions & 1 deletion iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ func (i *Iterator[T]) SeekLowerBound(prefixKey []byte) {
findMin(node)
if parent != nil && parent.getNodeLeaf() != nil {
i.stack = append(i.stack, NodeWrapper[T]{parent.getNodeLeaf(), 0})
return
}
return
}

if prefixCmp < 0 && !i.seenMismatch {
Expand Down Expand Up @@ -397,6 +397,18 @@ func (i *Iterator[T]) SeekLowerBound(prefixKey []byte) {
idx = 0
}

if i.seenMismatch {
for itr := int(node.getNumChildren()) - 1; itr >= idx; itr-- {
if node.getChild(itr) != nil {
i.stack = append(i.stack, NodeWrapper[T]{node.getChild(itr), 0})
}
}
if node.getNodeLeaf() != nil {
i.stack = append(i.stack, NodeWrapper[T]{node.getNodeLeaf(), 0})
}
return
}

for itr := int(node.getNumChildren()) - 1; itr >= idx+1; itr-- {
if node.getChild(itr) != nil {
i.stack = append(i.stack, NodeWrapper[T]{node.getChild(itr), 0})
Expand Down
24 changes: 23 additions & 1 deletion iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ func TestIterateLowerBoundFuzz(t *testing.T) {
return result
}

if err := quick.CheckEqual(radixAddAndScan, sliceAddSortAndFilter, nil); err != nil {
if err := quick.CheckEqual(radixAddAndScan, sliceAddSortAndFilter, &quick.Config{
MaxCount: 1000,
}); err != nil {
t.Error(err)
}
}
Expand Down Expand Up @@ -351,6 +353,26 @@ func TestIterateLowerBound(t *testing.T) {
"dfcda",
[]string{"e", "ebfbbda", "eedg", "fcgcfgd", "fgbgefa", "g", "gfab"},
},
{
[]string{"eace", "cbecg", "eacee", "eadfcdc", "eadgbc", "eafga", "ebbggd", "ebdcd", "ecc", "ececb", "ecefaef", "edbffd", "edbge", "eddd", "ede", "edeb", "edgbgf", "ee", "eedee", "ef", "efa", "efadaf", "effb", "efg", "eg", "egcbbd", "egdcaff", "f", "fa", "fadbff", "fagfec", "fbgfaf", "fcadb", "fcde", "fcegb", "fcfbfgd", "fd", "fdagf", "fdc", "fdcbf", "fdfb", "fdgc", "fefb", "ff", "ffce", "ffd", "ffec", "ffeef", "ffeg", "fff", "fgbde", "fgdbebc", "fgegaf", "g", "gaaff", "gab", "gaeddc", "gbaead", "gbbgcgf", "gbcdbac", "gbef", "gcf", "gddb", "ge", "gea", "geaga", "gebe", "gecgae", "gfb", "gfeba", "gfgeecd", "gg", "ggdac"},
"eaccfd",
[]string{"eace", "eacee", "eadfcdc", "eadgbc", "eafga", "ebbggd", "ebdcd", "ecc", "ececb", "ecefaef", "edbffd", "edbge", "eddd", "ede", "edeb", "edgbgf", "ee", "eedee", "ef", "efa", "efadaf", "effb", "efg", "eg", "egcbbd", "egdcaff", "f", "fa", "fadbff", "fagfec", "fbgfaf", "fcadb", "fcde", "fcegb", "fcfbfgd", "fd", "fdagf", "fdc", "fdcbf", "fdfb", "fdgc", "fefb", "ff", "ffce", "ffd", "ffec", "ffeef", "ffeg", "fff", "fgbde", "fgdbebc", "fgegaf", "g", "gaaff", "gab", "gaeddc", "gbaead", "gbbgcgf", "gbcdbac", "gbef", "gcf", "gddb", "ge", "gea", "geaga", "gebe", "gecgae", "gfb", "gfeba", "gfgeecd", "gg", "ggdac"},
},
{
[]string{"dbacgg", "gfg", "gfggefe", "ggggde"},
"gfd",
[]string{"gfg", "gfggefe", "ggggde"},
},
{
[]string{"gccdcc", "gcc", "gccdf", "gcdbdde", "gcdgac", "gcea", "gcebb", "gcedg", "gcefbgd", "gcf", "gcgaff", "gcgddgg", "gd", "gda", "gdaefc", "gdbebe", "gdbeffd", "gdceb", "gdcefcd", "ge", "gebeag", "gecd", "gecead", "gede", "geeaff", "gefacgc", "gefag", "geg", "gf", "gfa", "gfc", "gfca", "gfe", "gfeg", "gfg", "gfgcbg", "gfgdae", "gga", "ggadd", "ggafdbd", "ggbad", "ggbgadg", "ggfec", "ggffeb", "gggce"},
"gcafede",
[]string{"gcc", "gccdcc", "gccdf", "gcdbdde", "gcdgac", "gcea", "gcebb", "gcedg", "gcefbgd", "gcf", "gcgaff", "gcgddgg", "gd", "gda", "gdaefc", "gdbebe", "gdbeffd", "gdceb", "gdcefcd", "ge", "gebeag", "gecd", "gecead", "gede", "geeaff", "gefacgc", "gefag", "geg", "gf", "gfa", "gfc", "gfca", "gfe", "gfeg", "gfg", "gfgcbg", "gfgdae", "gga", "ggadd", "ggafdbd", "ggbad", "ggbgadg", "ggfec", "ggffeb", "gggce"},
},
{
[]string{"g", "gfaabb"},
"g",
[]string{"g", "gfaabb"},
},
}

for idx, test := range cases {
Expand Down

0 comments on commit bcad086

Please sign in to comment.