Add Ceiling and Floor functions to redblacktree #4

Merged
otnt merged 6 commits from master into master 2016-03-28 05:01:54 +00:00
otnt commented 2016-03-27 06:08:07 +00:00 (Migrated from github.com)

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.

Request: The redblacktree implementation now is :sparkles: great :sparkles: , 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.
emirpasic commented 2016-03-27 10:12:29 +00:00 (Migrated from github.com)

@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

@otnt Please check the following example on how to extend [red-black tree](https://github.com/emirpasic/gods/blob/master/examples/redblacktreeextended.go). This is the IMHO better approach rather than injecting each requested feature directly into the implementation. See discussion #2
otnt commented 2016-03-27 19:24:12 +00:00 (Migrated from github.com)

@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.

@emirpasic That makes sense. So you think it would be nice to put these two functions in [redblacktreeextended.go](https://github.com/emirpasic/gods/blob/master/examples/redblacktreeextended.go)? If so, I'll do that in these two days.
emirpasic commented 2016-03-28 01:06:36 +00:00 (Migrated from github.com)

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.

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.
otnt commented 2016-03-28 02:02:45 +00:00 (Migrated from github.com)

@emirpasic

Thanks for your quick reply.

I moved Ceiling and Floor functions to redblacktreeextended.go. Also, to make comparing nodes possible, I added a Comparator function in redblacktree.go to get comparator of the red black tree.

Besides, I checked the Root of Tree is already an *Node, so it seems no need to worry that the node is not a pointer.

@emirpasic Thanks for your quick reply. I moved `Ceiling` and `Floor` functions to `redblacktreeextended.go`. Also, to make comparing nodes possible, I added a `Comparator` function in `redblacktree.go` to get comparator of the red black tree. Besides, I checked the `Root` of `Tree` is already an `*Node`, so it seems no need to worry that the node is not a pointer.
emirpasic commented 2016-03-28 02:59:40 +00:00 (Migrated from github.com)

BTW, thanks for contributing!

BTW, thanks for contributing!
otnt commented 2016-03-28 05:25:33 +00:00 (Migrated from github.com)

No problem! I'm new to open source world, glad to contribute 😄

No problem! I'm new to open source world, glad to contribute :smile:
emirpasic commented 2016-03-28 05:57:00 +00:00 (Migrated from github.com)

Merged and changed some minor cosmetics (exposed Comporator, so no getter)

Cheers

Merged and changed some minor cosmetics (exposed Comporator, so no getter) Cheers
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
golibs/gms-gods!4
No description provided.