-
Notifications
You must be signed in to change notification settings - Fork 252
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
Splay tree amortized time issues #923
Comments
Just for your information: search, delete, and insert in SortedSet, SortedDict, and SortedMultiDict are all O(log n) operations. However, these data structures do not have the splay-tree property of faster access time to items that are accessed more frequently, so this doesn't directly fix your issue. |
Great catch, btw!
Yeah, go ahead and implement this change. It's been a while since I last looked at this implementation in this much depth. Will be happy to review it. Make sure to change the function signature to On a related note, if you have some time on your hand, you can also add a benchmark script for different kind of trees in the |
Thanks for the fast reply; I'll send something tomorrow! |
Hello,
Thanks for your work on this package !
The documentation at https://juliacollections.github.io/DataStructures.jl/stable/splay_tree/#Splay-Tree-1 indicates the splay tree implementation should guarantee
But I think this can be violated by the current implementation because it doesn't splay on unsuccessful searches, or on redundant insertions.
Here's a short test script to show the behavior; I have a particularly slow computer so you might need to increase the "10000" to see useful timing info:
In its default configuration, this:
The result (at least on my machine) is very poor scaling behavior.
Notably, it is significantly faster if an AVL tree is used or if we push nonredundant elements, so I think the explanation above of the cause of the slowdown is correct. And I think it also affects, e.g., sequences of unsuccessful
haskey
s (replacepush!(t, 1)
withhaskey(t, 0)
).I think the basic fix is to have
search_node
always splay the very last node it encounters, as suggested in the splay tree paper. Alternatively, if this is expected behavior, it would be nice IMO to document that. If this package is still maintained + there's interest in either of those two changes I'm happy to send a PR.Also sorry if I've misunderstood something about the implementation or use of the package; I'm new to Julia.
The text was updated successfully, but these errors were encountered: