summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2006-08-09 13:57:48 +0000
committerRich Hickey <richhickey@gmail.com>2006-08-09 13:57:48 +0000
commitbe12a746746c53c1f00758df7daa1fa5edc03935 (patch)
tree02ec20ec0b00c34deddcb7500e7b77ecd54a8767 /src
parentac3c1ae28a18395a15b8a4f85ea2ad90a3e9e540 (diff)
equals fixes
Diffstat (limited to 'src')
-rw-r--r--src/cli/runtime/APersistentArray.cs15
-rw-r--r--src/cli/runtime/APersistentMap.cs2
-rw-r--r--src/cli/runtime/ASeq.cs16
-rw-r--r--src/cli/runtime/PersistentQueue.cs29
-rw-r--r--src/jvm/clojure/lang/APersistentArray.java9
-rw-r--r--src/jvm/clojure/lang/APersistentMap.java2
-rw-r--r--src/jvm/clojure/lang/ASeq.java15
-rw-r--r--src/jvm/clojure/lang/PersistentQueue.java30
8 files changed, 91 insertions, 27 deletions
diff --git a/src/cli/runtime/APersistentArray.cs b/src/cli/runtime/APersistentArray.cs
index de9b548c..b78f502d 100644
--- a/src/cli/runtime/APersistentArray.cs
+++ b/src/cli/runtime/APersistentArray.cs
@@ -36,7 +36,7 @@ override public bool Equals(Object obj) {
if(obj is IPersistentArray)
{
IPersistentArray ma = (IPersistentArray) obj;
- if(ma.count() != count())
+ if (ma.count() != count() || ma.GetHashCode() != GetHashCode())
return false;
for(int i=0;i<count();i++)
{
@@ -48,11 +48,14 @@ override public bool Equals(Object obj) {
{
if(!(obj is Sequential))
return false;
- for(ISeq s = seq(), ms = ((IPersistentCollection)obj).seq();s!=null;s = s.rest(), ms = ms.rest())
- {
- if(ms == null || !RT.equal(s.first(),ms.first()))
- return false;
- }
+ ISeq ms = ((IPersistentCollection)obj).seq();
+ for (int i = 0; i < count(); i++, ms = ms.rest())
+ {
+ if (ms == null || !RT.equal(nth(i), ms.first()))
+ return false;
+ }
+ if(ms.rest() != null)
+ return false;
}
return true;
diff --git a/src/cli/runtime/APersistentMap.cs b/src/cli/runtime/APersistentMap.cs
index 8c082d23..e107e857 100644
--- a/src/cli/runtime/APersistentMap.cs
+++ b/src/cli/runtime/APersistentMap.cs
@@ -31,7 +31,7 @@ override public bool Equals(Object obj) {
if(obj == null)
return false;
- if(m.count() != count())
+ if(m.count() != count() || m.GetHashCode() != GetHashCode())
return false;
for(ISeq s = seq();s!=null;s = s.rest())
diff --git a/src/cli/runtime/ASeq.cs b/src/cli/runtime/ASeq.cs
index 252a69f6..112c9f73 100644
--- a/src/cli/runtime/ASeq.cs
+++ b/src/cli/runtime/ASeq.cs
@@ -26,14 +26,16 @@ int _hash = -1;
}
override public bool Equals(Object obj) {
- if(!(obj is Sequential))
- return false;
- for(ISeq s = seq(), ms = ((IPersistentCollection)obj).seq();s!=null;s = s.rest(), ms = ms.rest())
- {
- if(ms == null || !RT.equal(s.first(),ms.first()))
+ if(!(obj is Sequential))
+ return false;
+ ISeq ms = ((IPersistentCollection)obj).seq();
+ for(ISeq s = seq();s!=null;s = s.rest(), ms = ms.rest())
+ {
+ if(ms == null || !RT.equal(s.first(),ms.first()))
+ return false;
+ }
+ if(ms.rest() != null)
return false;
- }
-
return true;
}
diff --git a/src/cli/runtime/PersistentQueue.cs b/src/cli/runtime/PersistentQueue.cs
index 77b72035..2ed5d966 100644
--- a/src/cli/runtime/PersistentQueue.cs
+++ b/src/cli/runtime/PersistentQueue.cs
@@ -28,6 +28,7 @@ readonly public static PersistentQueue EMPTY = new PersistentQueue(null,null,nul
readonly ISeq f;
readonly PersistentArrayList r;
static readonly int INITIAL_REAR_SIZE = 4;
+int _hash = -1;
PersistentQueue(ISeq f, PersistentArrayList r, IPersistentMap meta) {
@@ -36,6 +37,33 @@ PersistentQueue(ISeq f, PersistentArrayList r, IPersistentMap meta) {
this._meta = meta;
}
+override public bool Equals(Object obj)
+ {
+ if (!(obj is Sequential))
+ return false;
+ ISeq ms = ((IPersistentCollection)obj).seq();
+ for (ISeq s = seq(); s != null; s = s.rest(), ms = ms.rest())
+ {
+ if (ms == null || !RT.equal(s.first(), ms.first()))
+ return false;
+ }
+ return ms.rest() == null;
+ }
+
+override public int GetHashCode()
+ {
+ if (_hash == -1)
+ {
+ int hash = 0;
+ for (ISeq s = seq(); s != null; s = s.rest())
+ {
+ hash = RT.hashCombine(hash, RT.hash(s.first()));
+ }
+ this._hash = hash;
+ }
+ return _hash;
+ }
+
public Object peek() {
return RT.first(f);
}
@@ -65,7 +93,6 @@ public ISeq seq() {
}
public IPersistentCollection cons(Object o) {
- PersistentQueue ret;
if(f == null) //empty
return new PersistentQueue(RT.list(o), null,_meta);
else
diff --git a/src/jvm/clojure/lang/APersistentArray.java b/src/jvm/clojure/lang/APersistentArray.java
index f1fb426a..ae2e6602 100644
--- a/src/jvm/clojure/lang/APersistentArray.java
+++ b/src/jvm/clojure/lang/APersistentArray.java
@@ -38,7 +38,7 @@ public boolean equals(Object obj) {
if(obj instanceof IPersistentArray)
{
IPersistentArray ma = (IPersistentArray) obj;
- if(ma.count() != count())
+ if(ma.count() != count() || ma.hashCode() != hashCode())
return false;
for(int i=0;i<count();i++)
{
@@ -50,11 +50,14 @@ public boolean equals(Object obj) {
{
if(!(obj instanceof Sequential))
return false;
- for(ISeq s = seq(), ms = ((IPersistentCollection)obj).seq();s!=null;s = s.rest(), ms = ms.rest())
+ ISeq ms = ((IPersistentCollection)obj).seq();
+ for(int i=0;i<count();i++, ms = ms.rest())
{
- if(ms == null || !RT.equal(s.first(),ms.first()))
+ if(ms == null || !RT.equal(nth(i),ms.first()))
return false;
}
+ if(ms.rest() != null)
+ return false;
}
return true;
diff --git a/src/jvm/clojure/lang/APersistentMap.java b/src/jvm/clojure/lang/APersistentMap.java
index 6a29f2d4..f0e2d8da 100644
--- a/src/jvm/clojure/lang/APersistentMap.java
+++ b/src/jvm/clojure/lang/APersistentMap.java
@@ -37,7 +37,7 @@ public boolean equals(Object obj) {
return false;
IPersistentMap m = (IPersistentMap)obj;
- if(m.count() != count())
+ if(m.count() != count() || m.hashCode() != hashCode())
return false;
for(ISeq s = seq();s!=null;s = s.rest())
diff --git a/src/jvm/clojure/lang/ASeq.java b/src/jvm/clojure/lang/ASeq.java
index 663d5b00..0a4b2c12 100644
--- a/src/jvm/clojure/lang/ASeq.java
+++ b/src/jvm/clojure/lang/ASeq.java
@@ -15,13 +15,16 @@ int _hash = -1;
public boolean equals(Object obj) {
- if(!(obj instanceof Sequential))
- return false;
- for(ISeq s = seq(), ms = ((IPersistentCollection)obj).seq();s!=null;s = s.rest(), ms = ms.rest())
- {
- if(ms == null || !RT.equal(s.first(),ms.first()))
+ if(!(obj instanceof Sequential))
+ return false;
+ ISeq ms = ((IPersistentCollection)obj).seq();
+ for(ISeq s = seq();s!=null;s = s.rest(), ms = ms.rest())
+ {
+ if(ms == null || !RT.equal(s.first(),ms.first()))
+ return false;
+ }
+ if(ms.rest() != null)
return false;
- }
return true;
}
diff --git a/src/jvm/clojure/lang/PersistentQueue.java b/src/jvm/clojure/lang/PersistentQueue.java
index 29092f38..32346a40 100644
--- a/src/jvm/clojure/lang/PersistentQueue.java
+++ b/src/jvm/clojure/lang/PersistentQueue.java
@@ -29,7 +29,7 @@ final public static PersistentQueue EMPTY = new PersistentQueue(null,null,null);
final ISeq f;
final PersistentArrayList r;
static final int INITIAL_REAR_SIZE = 4;
-
+int _hash = -1;
PersistentQueue(ISeq f, PersistentArrayList r, IPersistentMap meta) {
this.f = f;
@@ -37,6 +37,33 @@ PersistentQueue(ISeq f, PersistentArrayList r, IPersistentMap meta) {
this._meta = meta;
}
+public boolean equals(Object obj) {
+
+ if(!(obj instanceof Sequential))
+ return false;
+ ISeq ms = ((IPersistentCollection)obj).seq();
+ for(ISeq s = seq();s!=null;s = s.rest(), ms = ms.rest())
+ {
+ if(ms == null || !RT.equal(s.first(),ms.first()))
+ return false;
+ }
+ return ms.rest() == null;
+
+}
+
+public int hashCode() {
+ if(_hash == -1)
+ {
+ int hash = 0;
+ for(ISeq s = seq();s!=null;s = s.rest())
+ {
+ hash = RT.hashCombine(hash, RT.hash(s.first()));
+ }
+ this._hash = hash;
+ }
+ return _hash;
+}
+
public Object peek() {
return RT.first(f);
}
@@ -66,7 +93,6 @@ public ISeq seq() {
}
public PersistentQueue cons(Object o) {
- PersistentQueue ret;
if(f == null) //empty
return new PersistentQueue(RT.list(o), null,_meta);
else