diff dwtx/dwtxhelper/Collection.d @ 159:7926b636c282

...
author Frank Benoit <benoit@tionex.de>
date Wed, 27 Aug 2008 01:57:58 +0200
parents 8df1d4193877
children f8d52b926852
line wrap: on
line diff
--- a/dwtx/dwtxhelper/Collection.d	Tue Aug 26 02:46:34 2008 +0200
+++ b/dwtx/dwtxhelper/Collection.d	Wed Aug 27 01:57:58 2008 +0200
@@ -362,6 +362,137 @@
 
 }
 
+class IdentityHashMap : Map {
+    alias tango.util.container.HashMap.HashMap!(Object,Object) MapType;
+    private MapType map;
+
+    public this(){
+        implMissing(__FILE__, __LINE__ );
+        map = new MapType();
+    }
+    public this(int initialCapacity){
+        implMissing(__FILE__, __LINE__ );
+        this();
+    }
+    public this(int initialCapacity, float loadFactor){
+        implMissing(__FILE__, __LINE__ );
+        map = new MapType(loadFactor);
+    }
+    public this(Map m){
+        implMissing(__FILE__, __LINE__ );
+        this();
+        putAll(m);
+    }
+    public void clear(){
+        map.clear();
+    }
+    public bool containsKey(Object key){
+        Object v;
+        return map.get(key, v );
+    }
+    public bool containsKey(String key){
+        return containsKey(stringcast(key));
+    }
+    public bool containsValue(Object value){
+        return map.contains(value);
+    }
+    public Set  entrySet(){
+        HashSet res = new HashSet();
+        foreach( k, v; map ){
+            res.add( new MapEntry(this,k));
+        }
+        return res;
+    }
+    public override int opEquals(Object o){
+        if( auto other = cast(HashMap) o ){
+            if( other.size() !is size() ){
+                return false;
+            }
+            foreach( k, v; map ){
+                Object vo = other.get(k);
+                if( v != vo ){
+                    return false;
+                }
+            }
+            return true;
+        }
+        return false;
+    }
+    public Object get(Object key){
+        if( auto v = key in map ){
+            return *v;
+        }
+        return null;
+    }
+    public Object get(String key){
+        return get(stringcast(key));
+    }
+    public override hash_t toHash(){
+        return super.toHash();
+    }
+    public bool isEmpty(){
+        return map.isEmpty();
+    }
+    public Set    keySet(){
+        HashSet res = new HashSet();
+        foreach( k, v; map ){
+            res.add(k);
+        }
+        return res;
+    }
+    public Object put(Object key, Object value){
+        Object res = null;
+        if( auto vold = key in map ){
+            res = *vold;
+        }
+        map[ key ] = value;
+        return res;
+    }
+    public Object put(String key, Object value){
+        return put( stringcast(key), value );
+    }
+    public Object put(Object key, String value){
+        return put( key, stringcast(value) );
+    }
+    public Object put(String key, String value){
+        return put( stringcast(key), stringcast(value) );
+    }
+    public void   putAll(Map t){
+        foreach( k, v; t ){
+            map[k] = v;
+        }
+    }
+    public Object remove(Object key){
+        if( auto v = key in map ){
+            Object res = *v;
+            map.remove(key);
+            return res;
+        }
+        map.remove(key);
+        return null;
+    }
+    public Object remove(String key){
+        return remove(stringcast(key));
+    }
+    public int    size(){
+        return map.size();
+    }
+    public Collection values(){
+        ArrayList res = new ArrayList( size() );
+        foreach( k, v; map ){
+            res.add( v );
+        }
+        return res;
+    }
+
+    public int opApply (int delegate(ref Object value) dg){
+        return map.opApply( dg );
+    }
+    public int opApply (int delegate(ref Object key, ref Object value) dg){
+        return map.opApply( dg );
+    }
+}
+
 class Dictionary {
     public this(){
     }