Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ternary search tree panic on prefix search #16

Open
Salve opened this issue Jun 30, 2023 · 0 comments
Open

Ternary search tree panic on prefix search #16

Salve opened this issue Jun 30, 2023 · 0 comments

Comments

@Salve
Copy link

Salve commented Jun 30, 2023

https://github.com/timtadh/data-structures/blob/master/trie/tst.go#L173

This line panics if the prefix being searched for is longer than the capacity of the key being checked, e.g. this panics:

	tst := trie.New()
	tst.Put([]byte("abc"), nil)
	_, _, _ = tst.PrefixFind([]byte("abcxxxxxxxxxxxxxxxxxxxx"))()
panic: runtime error: slice bounds out of range [:23] with capacity 8
...
github.com/timtadh/data-structures/trie.(*TST).PrefixFind(0xc000092760?, {0xc000092749, 0x17, 0x3?})
	/go/pkg/mod/github.com/timtadh/[email protected]/trie/tst.go:173 +0x297
...

Since the slice operation succeeds if the index is larger than the length but smaller than the capacity this doesn't always occur for prefixes that are slightly longer than the found leaf node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant