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

tree.find: fix the issue that null key cased 100% cpu usage. #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

melochale
Copy link

If the arg key of tree.find is null, the node couldn't be responsive because of the 100% cpu usage.

@melochale melochale changed the title tree.find: fix the issue that null key cased 100% cpu useage. tree.find: fix the issue that null key cased 100% cpu usage. Oct 29, 2014
@scttnlsn
Copy link
Owner

@melote Would tree.find enter an infinite loop? Could you provide a minimal test case to demonstrate this?

@melochale
Copy link
Author

@scttnlsn OK,this is a mocha test case, I don't know whether tree.find enter an infinite loop, but I guest so, I got this issue in my project. anyway, thanks for your nice redblack.O(∩_∩)O

it("should return null if key is null." ,function() {
  var tree = redblack.tree();
  tree.insert('foo', 'bar');
  var node = tree.get(null);
  assert.equal(null, node);  //freeze here.
)};

@scttnlsn
Copy link
Owner

@melote Ahh, I see. Yeah, looks like there's an infinite loop in that case. Perhaps we should also prevent null keys from being inserted. Could you also remove the comment about 100% CPU usage or change it to something about infinite looping? Then I'll merge this in.

Thanks!

@melochale
Copy link
Author

@scttnlsn, yeah,that would be great! I will remove it.

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

Successfully merging this pull request may close these issues.

None yet

2 participants