First element of treebidimap #85

Closed
opened 2018-09-05 10:00:17 +00:00 by linhnt89 · 2 comments
linhnt89 commented 2018-09-05 10:00:17 +00:00 (Migrated from github.com)

I'm trying to use treebidimap and detect this strange behavior:

Procedure :

  • Create new map : t := treebidimap.NewWith(utils.IntComparator, utils.StringComparator)
  • Add first element : t.Put(1,1)
  • Add second element : t.Put(1,1)

Expected:

  • The panic happens when adding first element

Actual:

  • The panic only happens when adding second element

Tried to check [redblacktree.go] and got the following :

// Put inserts node into the tree.
// Key should adhere to the comparator's type assertion, otherwise method panics.
func (tree *Tree) Put(key interface{}, value interface{}) {
	var insertedNode *Node
	if tree.Root == nil {
		tree.Root = &Node{Key: key, Value: value, color: red}
		insertedNode = tree.Root
	} else {
		node := tree.Root
		loop := true
		for loop {
			compare := tree.Comparator(key, node.Key)

There seems the Comparator is not used for first node/element, it is inserted directly to the map. Is this case as your expected? Did I miss any information in README?

I'm trying to use treebidimap and detect this strange behavior: ### Procedure : - Create new map : `t := treebidimap.NewWith(utils.IntComparator, utils.StringComparator)` - Add first element : `t.Put(1,1)` - Add second element : `t.Put(1,1)` ### Expected: - The panic happens when adding first element ### Actual: - The panic only happens when adding second element Tried to check [redblacktree.go] and got the following : ``` // Put inserts node into the tree. // Key should adhere to the comparator's type assertion, otherwise method panics. func (tree *Tree) Put(key interface{}, value interface{}) { var insertedNode *Node if tree.Root == nil { tree.Root = &Node{Key: key, Value: value, color: red} insertedNode = tree.Root } else { node := tree.Root loop := true for loop { compare := tree.Comparator(key, node.Key) ``` There seems the Comparator is not used for first node/element, it is inserted directly to the map. Is this case as your expected? Did I miss any information in README?
emirpasic commented 2018-09-20 15:47:07 +00:00 (Migrated from github.com)

@linhnt89 thank you for the detailed report. on the first glance this looks like a bug and i will investigate now what's going on. willl keep you posted... for now labeling as a bug

@linhnt89 thank you for the detailed report. on the first glance this looks like a bug and i will investigate now what's going on. willl keep you posted... for now labeling as a bug
emirpasic commented 2018-09-20 16:08:50 +00:00 (Migrated from github.com)

interesting find @linhnt89 fixed

interesting find @linhnt89 fixed
Sign in to join this conversation.
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#85
No description provided.