scan only one key slim trie
rederry opened this issue · comments
rederry commented
Describe the bug
Using scan api to scan only 1 key slim trie, found no key.
To Reproduce
func TestSlimTrieOneKeyScan(t *testing.T) {
st, err := trie.NewSlimTrie(encode.Int{}, []string{"ab"}, []int{1}, trie.Opt{Complete: trie.Bool(true)})
require.NoError(t, err)
keyCount := 0
st.ScanFrom("ab", true, false, func(key []byte, value []byte) bool {
keyCount++
return true
})
require.Equal(t, 1, keyCount)
}
Expected behavior
keyCount = 1
Actual behavior
keyCount = 0
张炎泼 commented
Thank you so much for reporting this bug!
A trie with only one key is a special case that it does not have a parent node.
Such a trie has to be dealt with specially.