Skip to content

Commit

Permalink
Merge pull request #1247 from ruslansennov/hamt
Browse files Browse the repository at this point in the history
LeafSingleton: compare hashCodes before checking equality #1243
  • Loading branch information
danieldietrich committed Mar 30, 2016
2 parents 30f89f1 + 9c2fbd2 commit c0f695f
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ final class LeafSingleton<K, V> extends LeafNode<K, V> implements Serializable {

@Override
Option<V> lookup(int shift, int keyHashCode, K key) {
if (Objects.equals(key, this.key)) {
if (keyHashCode == hash && Objects.equals(key, this.key)) {
return Option.some(value);
} else {
return Option.none();
Expand All @@ -296,7 +296,7 @@ Option<V> lookup(int shift, int keyHashCode, K key) {

@Override
AbstractNode<K, V> modify(int shift, int keyHashCode, K key, V value, Action action) {
if (Objects.equals(key, this.key)) {
if (keyHashCode == hash && Objects.equals(key, this.key)) {
return (action == REMOVE) ? EmptyNode.instance() : new LeafSingleton<>(hash, key, value);
} else {
return (action == REMOVE) ? this : mergeLeaves(shift, this, new LeafSingleton<>(keyHashCode, key, value));
Expand Down

0 comments on commit c0f695f

Please sign in to comment.