Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…shCodes.
  • Loading branch information...
commit 8d87f12ec89fb8b128a7a98c9059a98170e09889 1 parent 4eed71d
@krestenkrab krestenkrab authored
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;
Please sign in to comment.
Something went wrong with that request. Please try again.