Skip to content
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

First element of treebidimap #85

Closed
linhnt89 opened this issue Sep 5, 2018 · 2 comments
Closed

First element of treebidimap #85

linhnt89 opened this issue Sep 5, 2018 · 2 comments
Labels

Comments

@linhnt89
Copy link

linhnt89 commented Sep 5, 2018

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 emirpasic added the bug label Sep 20, 2018
@emirpasic
Copy link
Owner

@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
Copy link
Owner

interesting find @linhnt89
fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants