-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Feature Request] Method to count entries starting with a prefix #38
Comments
I might be wrong but just summing the number o children from each node would give the wrong result, imagine a case where we have Also iterating over the tree it self would probably be slower than over the leafs with the |
Whoops, I meant to post a comment here a day ago and lost it. I agree with @Gab-Menezes that the most likely implementation of this would be to add a new field to the header of internal nodes to track the number of leaf node descendants. This would imply some changes to the insert and delete operations, so that the counter would be incremented or decremented on a successful operation. On the pros side, then we would have the ability to cheaply implement
|
The other performance related reason is that it allows me to decide on the most efficient way to iterate the collection. In my case, I run matching functions (including regexes) against items matching a prefix. Above a certain count, it's worth it to switch to optimized predicates, but those require a compilation step which can then be amortized over the length of longer iterators. |
IDK how I feel about this, this will definitely make insertions/deletions way slower, since right now we just find the writing point and apply the changes. With this we somehow need to find a way to keep track of all the parents while inserting/deleting (basically creating a stack, or doing recursion and both have performance implications) to increment this number if the insertion was successful. |
If this makes general case insertions/deletions measurably slower, I'd be Ok without it. |
I'd like to be able to get a count of entries starting with a given prefix. Currently its possible iterating through a
prefix
iterator and counting elements, however we can optimize this by visiting nodes and summing children.The text was updated successfully, but these errors were encountered: