diff options
author | Rich Hickey <richhickey@gmail.com> | 2006-07-04 18:02:35 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2006-07-04 18:02:35 +0000 |
commit | 45928ffe7f2b9e59633fb7931f2a3c75c9d6589f (patch) | |
tree | cdade057178a2795ee134ea946cefff882c7c035 /src/cli/runtime/PersistentArrayMap.cs | |
parent | 86a8196bbba908bf6cf3f5d9ab3d3ebb7f94a646 (diff) |
added val to add(), throws exception if key present
Diffstat (limited to 'src/cli/runtime/PersistentArrayMap.cs')
-rw-r--r-- | src/cli/runtime/PersistentArrayMap.cs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/cli/runtime/PersistentArrayMap.cs b/src/cli/runtime/PersistentArrayMap.cs index 6cc42aad..df874d1a 100644 --- a/src/cli/runtime/PersistentArrayMap.cs +++ b/src/cli/runtime/PersistentArrayMap.cs @@ -62,10 +62,23 @@ public IMapEntry find(Object key) { return null;
}
-public IPersistentMap add(Object key) {
-
- return put(key,null);
-}
+public IPersistentMap add(Object key, Object val) {
+ int i = indexOf(key);
+ Object[] newArray;
+ if(i >= 0)
+ {
+ throw new Exception("Key already present");
+ }
+ else //didn't have key, grow
+ {
+ newArray = new Object[array.Length + 2];
+ if(array.Length > 0)
+ Array.Copy(array,0,newArray,2,array.Length);
+ newArray[0] = key;
+ newArray[1] = val;
+ }
+ return create(newArray);
+ }
public IPersistentMap put(Object key, Object val) {
int i = indexOf(key);
|