Permalink
Browse files

Make sure EString and EList representing the same value have equal ha…

…shCodes.
  • Loading branch information...
1 parent 4eed71d commit 8d87f12ec89fb8b128a7a98c9059a98170e09889 @krestenkrab krestenkrab committed Jun 15, 2010
Showing with 18 additions and 5 deletions.
  1. +13 −0 src/main/java/erjang/EList.java
  2. +5 −5 src/main/java/erjang/ESmall.java
View
13 src/main/java/erjang/EList.java
@@ -39,6 +39,19 @@ public EList(EObject h, ESeq tail) {
this.tail = tail;
}
+ @Override
+ public int hashCode() {
+
+ int h = 0;
+ ESeq curr = this;
+ do {
+ h = 31*h + curr.head().hashCode();
+ curr = curr.tail();
+ } while (curr != ERT.NIL);
+
+ return h;
+ }
+
public ECons testNonEmptyList() {
return this;
}
View
10 src/main/java/erjang/ESmall.java
@@ -42,6 +42,11 @@ public ESmall(int value) {
this.value = value;
}
+ @Override
+ public int hashCode() {
+ return value;
+ }
+
public long longValue() {
return value;
}
@@ -122,11 +127,6 @@ public int asInt() {
}
@Override
- public int hashCode() {
- return (int) ((long) value ^ (((long) value) >>> 32));
- }
-
- @Override
public boolean equals(Object obj) {
if (obj instanceof ESmall) {
ESmall o = (ESmall) obj;

0 comments on commit 8d87f12

Please sign in to comment.