-
Notifications
You must be signed in to change notification settings - Fork 375
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
feat(examples): Implement Indexed AVL Tree #2703
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2703 +/- ##
==========================================
+ Coverage 60.44% 60.45% +0.01%
==========================================
Files 563 563
Lines 75157 75157
==========================================
+ Hits 45427 45437 +10
+ Misses 26341 26329 -12
- Partials 3389 3391 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you publish some benchmarks demonstrating how this would make lookups for objects with particular faster than using the existing AVL tree implementation? On first look, it seems like QueryByField
still requires scanning the entire tree. If doing a lookup for a field using an indexed subtree, wouldn't you want to limit iteration to values prefixed by what you are looking up? Like "|"? Here's an example of how you could more efficiently iterate:
package hello
import (
"gno.land/p/demo/avl"
)
var tree avl.Tree
func init() {
tree.Set("hello|world", "asfasdf")
tree.Set("hello|goodbye", "hhhhhhh")
tree.Set("other", "bbbbb")
}
func GetMatches() []string {
var matches []string
lookup := "hello"
start := lookup + "|"
end := lookup + string('|'+1)
tree.Iterate(start, end, func(key string, value interface{}) bool {
matches = append(matches, key, value.(string))
return false
})
return matches
}
In what cases would using something like this be most useful? I can think of one -- when the values being stored in the tree are different struct types with different fields. I'd be curious to see a realm that has such a use case.
Thank you for the improvement suggestion that you provided, i have implemented it and support multiple objects now. However, I am facing a challenge regarding where to write the benchmark for the |
Removed the "review team" label because this is already reviewed by deelawn. |
Description:
AVL tree
implementationIndexedTree
structure, supporting field-based indexing and efficient data retrievalKey Features:
Indexable
valuesAVL Tree
: Provides a balanced binary search tree for efficient data operationsAdvantages:
AVL tree
ensures O(log N) complexity for insertions, deletions, and lookupsIndexedTree
consolidates indexing into a single structure, reducing the complexity associated with managing and synchronizing multiple AVL trees. While it doesn’t directly reduce memory usage compared to using separate trees for different fields, it streamlines the process of maintaining index consistency and simplifies the overall management of indexed dataIndexedTree
can index and manage various object types efficiently, offering flexibility in how data is stored and queried. This allows for versatile use cases where different types of objects need to be indexed and retrieved based on different fieldsLimitations:
Indexable
interface for their data types to be used with theIndexedTree
, adding an extra step for integrationIndexedTree
requires addition memory to maintain indexes and it may impact the performance ofSet
andRemove
operations due to the need to update multiple indexesGno
, lacking support for reflection or advanced type handlingUsage Demo:
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description