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

Hash#rehash does not properly rehash #4958

Closed
ChrisBr opened this issue Jan 8, 2018 · 1 comment
Closed

Hash#rehash does not properly rehash #4958

ChrisBr opened this issue Jan 8, 2018 · 1 comment
Milestone

Comments

@ChrisBr
Copy link
Contributor

ChrisBr commented Jan 8, 2018

Environment

  • jruby 9.3.0.0-SNAPSHOT (2.5.0) 2018-01-08 4b5cea6 OpenJDK 64-Bit Server VM 25.151-b12 on 1.8.0_151-b12 +jit [linux-x86_64]

Expected Behavior

When rehashing a hash with equal objects in it, they don't get removed.

a = [1,2]
b = [1]
h = {}
h[a] = true
h[b] = true
b << 2
puts h.rehash # { [1,2]: true, [1,2]: true } 

I already looked into the issue and it seems that the problem is that Hash#rehash does not handle collisions properly. When two objects have the same hash / bucket number, they get inserted even if they are the same (see example).

Actual Behavior

Hash#rehash should remove the duplicate entries.

@ChrisBr ChrisBr mentioned this issue Jan 8, 2018
@headius
Copy link
Member

headius commented Jan 8, 2018

I looked at your impl, and it was fine except for a couple things:

  • entry.equals checks equality of values too, which we don't want
  • we need to remove not-added entries from the insertion-order chain; if an entry is not kept, prevAdded and nextAdded entries need to be fixed up
  • we need to check the whole chain of entries, not just the first one

I almost had a fix but I'm pulled away to finish something else.

ChrisBr added a commit to ChrisBr/jruby that referenced this issue Jan 9, 2018
Duplicate keys where just ignored before and inserted again.
Fix jruby#4958.
ChrisBr added a commit to ChrisBr/jruby that referenced this issue Jan 9, 2018
Duplicate keys where just ignored before and inserted again.
Fix jruby#4958.
ChrisBr added a commit to ChrisBr/jruby that referenced this issue Jan 10, 2018
Duplicate keys where just ignored before and inserted again.
Fix jruby#4958.
@headius headius added this to the JRuby 9.2.0.0 milestone Jan 10, 2018
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