The Closest | Btree #72

Closed
alexandrestein wants to merge 4 commits from closest into master
alexandrestein commented 2018-04-04 17:28:11 +00:00 (Migrated from github.com)

This add a function to be able to get the values next to the pointed one.

Let me know if this is correctly done.

Best regards

This add a function to be able to get the values next to the pointed one. Let me know if this is correctly done. Best regards
emirpasic commented 2018-09-20 17:01:30 +00:00 (Migrated from github.com)

@alexandrestein I think the same comment/question to you applies here as well, read on #82

edit: actually just noted that you added more functionality than in the other case, so let me check this out...

@alexandrestein I think the same comment/question to you applies here as well, read on #82 edit: actually just noted that you added more functionality than in the other case, so let me check this out...
emirpasic (Migrated from github.com) reviewed 2018-09-23 11:57:49 +00:00
@ -98,0 +115,4 @@
func (tree *Tree) getClosest(key interface{}, keyWanted bool) (prev, next interface{}, found bool) {
// The first part of the function is almost a clone of tree.searchRecursively
if tree.Empty() {
return nil, nil, false
emirpasic (Migrated from github.com) commented 2018-09-23 11:57:49 +00:00

returning 3 params is a bit hard to handle for consumers of gods. i'd rather split this function into Ceiling and Floor which has also been added to RedBlackTree/TreeMap. we could add a GetClosest that would simply return two parameters (key-value pair) of the closest node be it ceiling or floow... otherwise nil if the tree is empty.

returning 3 params is a bit hard to handle for consumers of gods. i'd rather split this function into Ceiling and Floor which has also been added to RedBlackTree/TreeMap. we could add a GetClosest that would simply return two parameters (key-value pair) of the closest node be it ceiling or floow... otherwise nil if the tree is empty.
emirpasic (Migrated from github.com) reviewed 2018-09-23 12:04:12 +00:00
@ -98,0 +149,4 @@
// Returns the interator at the right position
return Iterator{
tree: tree,
node: node,
emirpasic (Migrated from github.com) commented 2018-09-23 12:04:12 +00:00

IteratorAt is an interesting idea also asked for by https://github.com/emirpasic/gods/issues/66

IteratorAt is an interesting idea also asked for by https://github.com/emirpasic/gods/issues/66
emirpasic (Migrated from github.com) reviewed 2018-09-23 12:07:37 +00:00
@ -98,0 +156,4 @@
}
// The key is not in the node but this is a leaf node.
// This means that the key is not in the tree and the returned pointer will
emirpasic (Migrated from github.com) commented 2018-09-23 12:07:37 +00:00

Not sure if search is the correct function to call.

/ search searches only within the single node among its entries
func (tree *Tree) search(node *Node, key interface{}) (index int, found bool) {

i think you wanted the searchRecursively function

// searchRecursively searches recursively down the tree starting at the startNode
func (tree *Tree) searchRecursively(startNode *Node, key interface{}) (node *Node, index int, found bool) {
Not sure if search is the correct function to call. ```go / search searches only within the single node among its entries func (tree *Tree) search(node *Node, key interface{}) (index int, found bool) { ``` i think you wanted the searchRecursively function ```go // searchRecursively searches recursively down the tree starting at the startNode func (tree *Tree) searchRecursively(startNode *Node, key interface{}) (node *Node, index int, found bool) { ```

Pull request closed

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!72
No description provided.