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

need to add equality comparator #9

Open
noname0310 opened this issue Jan 13, 2022 · 3 comments
Open

need to add equality comparator #9

noname0310 opened this issue Jan 13, 2022 · 3 comments

Comments

@noname0310
Copy link

noname0310 commented Jan 13, 2022

202 line's key !== node.key is acts like a reference comparison for an Object.
so, It is impossible to process a case where an object of the nature of a record is used as a key.

It would be better to add comparator like equalOp?: (a: K, b: K) => boolean in Tree<K, V> constructor parameter.

/** @internal */_findNode(
  key: K,
  node: Node<K, V> = this._root,
): Node<K, V> {
  while (node.ok && key !== node.key)
//                  ^^^^^^^^^^^^^^^^ --- here is problem
    node = this._less(key, node) ? node._left : node._right
  return node
}
@nalply
Copy link
Owner

nalply commented Jan 13, 2022 via email

@noname0310
Copy link
Author

noname0310 commented Jan 13, 2022

Is there no change in this repository regarding this topic?
If so, it would be better to write down an additional explanation of this problem in the documentation.

@nalply
Copy link
Owner

nalply commented Jan 13, 2022 via email

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

No branches or pull requests

2 participants