summaryrefslogtreecommitdiff
path: root/src/cli/runtime
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/cli/runtime
parentac3c1ae28a18395a15b8a4f85ea2ad90a3e9e540 (diff)
equals fixes
Diffstat (limited to 'src/cli/runtime')
-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
4 files changed, 47 insertions, 15 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