Add Ceiling and Floor functions to redblacktree #4
No reviewers
Labels
No labels
bug
discussion
documentation
duplicate
ignore
new feature
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
golibs/gms-gods!4
Loading…
Reference in a new issue
No description provided.
Delete branch "master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Request: The redblacktree implementation now is ✨ great ✨ , and it would be nicer to have Ceiling and Floor functions.
Reasons: Ceiling and Floor functions are frequently used, and are almost standard functions for tree data structure.
My implementation: I implemented these two functions in an iterative way. It's time complexity is O(log(N)), and space complexity is O(1). I also implemented test cases for these two functions.
@otnt
Please check the following example on how to extend red-black tree.
This is the IMHO better approach rather than injecting each requested feature directly into the implementation. See discussion #2
@emirpasic
That makes sense. So you think it would be nice to put these two functions in redblacktreeextended.go?
If so, I'll do that in these two days.
Sure, I can add that to the examples or you could change this PR and add that to the redblacktreeextended.go example?
This made be realize a blunder of my own, I should have used pointers as an optimization to the tree, so I will try to fix that ASAP.
@emirpasic
Thanks for your quick reply.
I moved
CeilingandFloorfunctions toredblacktreeextended.go. Also, to make comparing nodes possible, I added aComparatorfunction inredblacktree.goto get comparator of the red black tree.Besides, I checked the
RootofTreeis already an*Node, so it seems no need to worry that the node is not a pointer.BTW, thanks for contributing!
No problem! I'm new to open source world, glad to contribute 😄
Merged and changed some minor cosmetics (exposed Comporator, so no getter)
Cheers