Skip to content

Commit

Permalink
optmized lowerbound with some flakybug
Browse files Browse the repository at this point in the history
  • Loading branch information
absolutelightning committed Jun 15, 2024
1 parent f2b0c77 commit 1077c92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 77 deletions.
78 changes: 3 additions & 75 deletions iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,81 +405,9 @@ func TestIterateLowerBound(t *testing.T) {
[]string{"ge", "gfff"},
},
{
[]string{"a",
"aa",
"aagbeec",
"ab",
"abc",
"ac",
"ad",
"adgffag",
"afbbb",
"afd",
"afg",
"agacbdb",
"agefeb",
"bafed",
"bb",
"bbde",
"bceggd",
"bdfd",
"bfceged",
"bfgefdg",
"bgd",
"c",
"ca",
"cabgfcc",
"cad",
"cafaf",
"cagba",
"cagfd",
"cdbcg",
"cdfff",
"ceb",
"cfa",
"cfc",
"cffabdg",
"cga",
"d",
"daage",
"dacgea",
"db",
"dbagb",
"dbbe",
"dbcgba",
"dcdb",
"dd",
"dfbdg",
"dfbgb",
"dfcgbgb",
"dfedab",
"dg",
"dgcefe",
"e",
"eabf",
"ec",
"ecadgef",
"eceag",
"ecffge",
"eecbdeg",
"egfdccf",
"f",
"fafaeff",
"fecg",
"fedecag",
"fedgga",
"ffbadc",
"ffgad",
"g",
"gbcbcc",
"gbgff",
"gddcdgg",
"gdfdg",
"geefd",
"gefbc",
"ggag"},
"a",
[]string{"a", "aa", "aagbeec", "ab", "abc", "ac", "ad", "adgffag", "afbbb", "afd", "afg", "agacbdb", "agefeb", "bafed", "bb", "bbde", "bceggd", "bdfd", "bfceged", "bfgefdg", "bgd", "c", "ca", "cabgfcc", "cad", "cafaf", "cagba", "cagfd", "cdbcg", "cdfff", "ceb", "cfa", "cfc", "cffabdg", "cga", "d", "daage", "dacgea", "db", "dbagb", "dbbe", "dbcgba", "dcdb", "dd", "dfbdg", "dfbgb", "dfcgbgb", "dfedab", "dg", "dgcefe", "e", "eabf", "ec", "ecadgef", "eceag", "ecffge", "eecbdeg", "egfdccf", "f", "fafaeff", "fecg", "fedecag", "fedgga", "ffbadc", "ffgad", "g", "gbcbcc", "gbgff", "gddcdgg", "gdfdg", "geefd", "gefbc", "ggag"},
[]string{"ggab", "ggafe"},
"ggagfdf",
[]string{"ggab"},
},
}

Expand Down
17 changes: 15 additions & 2 deletions lower_bound_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ func (i *LowerBoundIterator[T]) SeekLowerBound(prefixKey []byte) {
if bytes.Compare(parent.getNodeLeaf().getKey(), i.path) >= 0 {
i.stack = append(i.stack, parent.getNodeLeaf())
}
return
}
return
}
Expand All @@ -277,7 +276,17 @@ func (i *LowerBoundIterator[T]) SeekLowerBound(prefixKey []byte) {
i.stack = append(i.stack, node)
}
} else {
i.stack = append(i.stack, node)
for itr := int(node.getNumChildren()) - 1; itr >= idx+1; itr-- {
nCh := node.getChild(itr)
nChL := nCh.getNodeLeaf()
if nChL == nil {
i.stack = append(i.stack, node.getChild(itr))
} else {
if bytes.Compare(nChL.key, i.path) >= 0 {
i.stack = append(i.stack, node.getChild(itr))
}
}
}
}
node = nil
return
Expand Down Expand Up @@ -307,6 +316,10 @@ func (i *LowerBoundIterator[T]) SeekLowerBound(prefixKey []byte) {
}
}

if idx == -1 {
return
}

parent = node
// Move to the next level in the tree
node = node.getChild(idx)
Expand Down

0 comments on commit 1077c92

Please sign in to comment.