diff options
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/runtime/PersistentArrayIdentityMap.cs | 2 | ||||
-rw-r--r-- | src/cli/runtime/PersistentArrayMap.cs | 4 | ||||
-rw-r--r-- | src/cli/runtime/PersistentHashtableIdentityMap.cs | 13 | ||||
-rw-r--r-- | src/cli/runtime/PersistentHashtableMap.cs | 8 | ||||
-rw-r--r-- | src/cli/runtime/PersistentHybridIdentityMap.cs | 50 | ||||
-rw-r--r-- | src/cli/runtime/PersistentHybridMap.cs | 105 |
6 files changed, 172 insertions, 10 deletions
diff --git a/src/cli/runtime/PersistentArrayIdentityMap.cs b/src/cli/runtime/PersistentArrayIdentityMap.cs index 4cd4a1af..b6cc57bc 100644 --- a/src/cli/runtime/PersistentArrayIdentityMap.cs +++ b/src/cli/runtime/PersistentArrayIdentityMap.cs @@ -22,7 +22,7 @@ public PersistentArrayIdentityMap() { public PersistentArrayIdentityMap(Object[] init) :base(init) {
}
-bool equalKey(Object k1, Object k2) {
+internal override bool equalKey(Object k1, Object k2) {
return k1 == k2;
}
}
diff --git a/src/cli/runtime/PersistentArrayMap.cs b/src/cli/runtime/PersistentArrayMap.cs index dd1d2e29..cffe1738 100644 --- a/src/cli/runtime/PersistentArrayMap.cs +++ b/src/cli/runtime/PersistentArrayMap.cs @@ -27,7 +27,7 @@ namespace org.clojure.runtime public class PersistentArrayMap : IPersistentMap {
-readonly Object[] array;
+internal readonly Object[] array;
public PersistentArrayMap(){
this.array = RT.EMPTY_ARRAY;
@@ -122,7 +122,7 @@ int indexOf(Object key){ return -1;
}
-bool equalKey(Object k1,Object k2){
+internal virtual bool equalKey(Object k1,Object k2){
if(k1 == null)
return k2 == null;
return k1.Equals(k2);
diff --git a/src/cli/runtime/PersistentHashtableIdentityMap.cs b/src/cli/runtime/PersistentHashtableIdentityMap.cs index f9dd13d8..1fb191bf 100644 --- a/src/cli/runtime/PersistentHashtableIdentityMap.cs +++ b/src/cli/runtime/PersistentHashtableIdentityMap.cs @@ -25,6 +25,9 @@ public PersistentHashtableIdentityMap(Object[] init) : base(init){ PersistentHashtableIdentityMap(int count, PersistentArray array) : base(count, array) {
}
+PersistentHashtableIdentityMap(int i, PersistentArray newArray, int growAtCount):base(i,newArray,growAtCount){
+}
+
override public IEnumerator GetEnumerator()
{
@@ -81,15 +84,19 @@ internal class Iter2 : IEnumerator }
-IPersistentMap create(int capacity) {
+internal override IPersistentMap create(int capacity) {
return new PersistentHashtableIdentityMap(capacity);
}
-IPersistentMap create(int count, PersistentArray array) {
+internal override IPersistentMap create(int count, PersistentArray array) {
return new PersistentHashtableIdentityMap(count, array);
}
-IPersistentMap createListMap(Object key, Object val){
+internal override IPersistentMap create(int i, PersistentArray newArray, int growAtCount){
+return new PersistentHashtableIdentityMap(i, newArray, growAtCount);
+}
+
+internal override IPersistentMap createListMap(Object key, Object val){
return PersistentListIdentityMap.create(key,val);
}
diff --git a/src/cli/runtime/PersistentHashtableMap.cs b/src/cli/runtime/PersistentHashtableMap.cs index 502d71f1..cb4e2f1a 100644 --- a/src/cli/runtime/PersistentHashtableMap.cs +++ b/src/cli/runtime/PersistentHashtableMap.cs @@ -206,20 +206,20 @@ static int bucketFor(Object key, PersistentArray array) { return (key.GetHashCode() & 0x7fffffff) % array.length();
}
-IPersistentMap create(int capacity) {
+virtual internal IPersistentMap create(int capacity) {
return new PersistentHashtableMap(capacity);
}
-IPersistentMap create(int count,PersistentArray array) {
+virtual internal IPersistentMap create(int count,PersistentArray array) {
return new PersistentHashtableMap(count, array);
}
-IPersistentMap create(int i, PersistentArray newArray, int growAtCount){
+virtual internal IPersistentMap create(int i, PersistentArray newArray, int growAtCount){
return new PersistentHashtableMap(i, newArray, growAtCount);
}
-IPersistentMap createListMap(Object key, Object val){
+virtual internal IPersistentMap createListMap(Object key, Object val){
return PersistentListMap.create(key,val);
}
diff --git a/src/cli/runtime/PersistentHybridIdentityMap.cs b/src/cli/runtime/PersistentHybridIdentityMap.cs new file mode 100644 index 00000000..069a14fb --- /dev/null +++ b/src/cli/runtime/PersistentHybridIdentityMap.cs @@ -0,0 +1,50 @@ +/**
+ * Copyright (c) Rich Hickey. All rights reserved.
+ * The use and distribution terms for this software are covered by the
+ * Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
+ * which can be found in the file CPL.TXT at the root of this distribution.
+ * By using this software in any fashion, you are agreeing to be bound by
+ * the terms of this license.
+ * You must not remove this notice, or any other, from this software.
+ **/
+
+using System;
+using System.Collections;
+ +namespace org.clojure.runtime
+{ + +public class PersistentHybridIdentityMap : PersistentHybridMap{
+
+public PersistentHybridIdentityMap(Object[] init) :base(init) {
+}
+
+public PersistentHybridIdentityMap(int initialCapacity) :base(initialCapacity) {
+}
+
+PersistentHybridIdentityMap(IPersistentMap impl) :base(impl) {
+}
+
+override public IPersistentMap create(IPersistentMap impl) {
+ return new PersistentHybridIdentityMap(impl);
+}
+
+override public PersistentArrayMap createArrayMap(Object[] init) {
+ return new PersistentArrayIdentityMap(init);
+}
+
+override internal IPersistentMap createArrayMap() {
+ return new PersistentArrayIdentityMap();
+}
+
+override internal IPersistentMap createHashtableMap(Object[] init) {
+ return new PersistentHashtableIdentityMap(init);
+}
+
+override internal IPersistentMap createHashtableMap(int initialCapacity) {
+ return new PersistentHashtableIdentityMap(initialCapacity);
+}
+
+}
+
+}
diff --git a/src/cli/runtime/PersistentHybridMap.cs b/src/cli/runtime/PersistentHybridMap.cs new file mode 100644 index 00000000..5ca17c9c --- /dev/null +++ b/src/cli/runtime/PersistentHybridMap.cs @@ -0,0 +1,105 @@ +/**
+ * Copyright (c) Rich Hickey. All rights reserved.
+ * The use and distribution terms for this software are covered by the
+ * Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
+ * which can be found in the file CPL.TXT at the root of this distribution.
+ * By using this software in any fashion, you are agreeing to be bound by
+ * the terms of this license.
+ * You must not remove this notice, or any other, from this software.
+ **/
+
+using System;
+using System.Collections;
+ +namespace org.clojure.runtime
+{ +
+public class PersistentHybridMap : IPersistentMap{
+
+IPersistentMap impl;
+static readonly int CAPACITY_THRESHOLD = 42;
+
+public PersistentHybridMap(Object[] init){
+ if(init.Length/2 < CAPACITY_THRESHOLD)
+ impl = createArrayMap(init);
+ impl = createHashtableMap(init);
+}
+
+public PersistentHybridMap(int initialCapacity){
+ if(initialCapacity < CAPACITY_THRESHOLD)
+ impl = createArrayMap();
+ else
+ impl = createHashtableMap(initialCapacity);
+}
+
+internal PersistentHybridMap(IPersistentMap impl){
+ this.impl = impl;
+}
+
+public int count() {
+ return impl.count();
+}
+
+public bool contains(Object key) {
+ return impl.contains(key);
+}
+
+public IMapEntry find(Object key) {
+ return impl.find(key);
+}
+
+public IPersistentMap add(Object key) {
+ return put(key, null);
+}
+
+public IPersistentMap put(Object key, Object val) {
+ IPersistentMap newImpl = impl.put(key,val);
+ if(newImpl.capacity() == CAPACITY_THRESHOLD)
+ {
+ newImpl = createHashtableMap(((PersistentArrayMap)newImpl).array);
+ }
+ return create(newImpl);
+}
+
+public IPersistentMap remove(Object key) {
+ IPersistentMap newImpl = impl.remove(key);
+ if(newImpl != impl)
+ return create(newImpl);
+ return this;
+}
+
+public Object get(Object key) {
+ return impl.get(key);
+}
+
+public int capacity() {
+ return impl.capacity();
+}
+
+public IEnumerator GetEnumerator() {
+ return impl.GetEnumerator();
+}
+
+virtual public IPersistentMap create(IPersistentMap impl) {
+ return new PersistentHybridMap(impl);
+}
+
+virtual public PersistentArrayMap createArrayMap(Object[] init) {
+ return new PersistentArrayMap(init);
+}
+
+virtual internal IPersistentMap createArrayMap() {
+ return new PersistentArrayMap();
+}
+
+virtual internal IPersistentMap createHashtableMap(Object[] init) {
+ return new PersistentHashtableMap(init);
+}
+
+virtual internal IPersistentMap createHashtableMap(int initialCapacity) {
+ return new PersistentHashtableMap(initialCapacity);
+}
+
+}
+
+}
|