openacid / slim

Surprisingly space efficient trie in Golang(11 bits/key; 100 ns/get).

Home Page:https://openacid.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

scan only one key slim trie

rederry opened this issue · comments

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

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.