public override bool PutIfNotExists(K key, V value) { Object writeLock = GetWriteLock(); lock (writeLock) { TempHashMap <MapEntry <K, V>, K, V> backupMap = CreateCopy(); // Write new data in the copied structure if (!backupMap.PutIfNotExists(key, value)) { return(false); } SaveCopy(backupMap); return(true); } }
public override void Clear() { Object writeLock = GetWriteLock(); lock (writeLock) { if (Count == 0) { return; } TempHashMap <IMapEntry <K, V>, K, V> backupMap = CreateCopy(); // Write new data in the copied structure backupMap.Clear(); SaveCopy(backupMap); } }
protected TempHashMap <IMapEntry <K, V>, K, V> CreateCopy() { // Copy existing data in FULLY NEW STRUCTURE IMapEntry <K, V>[] table = this.table; TempHashMap <IMapEntry <K, V>, K, V> backupMap = CreateEmptyInstance(); if (AutoCleanupNullValue) { for (int a = table.Length; a-- > 0;) { IMapEntry <K, V> entry = table[a]; while (entry != null) { K key = entry.Key; if (key != null) { V value = entry.Value; WeakReference valueAsRef = value as WeakReference; if (valueAsRef.Target != null) { // Only copy the entry if the value content is still valid backupMap.Put(CloneKey(key), CloneValue(value)); } } entry = entry.NextEntry; } } } else { for (int a = table.Length; a-- > 0;) { IMapEntry <K, V> entry = table[a]; while (entry != null) { K key = entry.Key; if (key != null) { V value = entry.Value; backupMap.Put(CloneKey(key), CloneValue(value)); } entry = entry.NextEntry; } } } return(backupMap); }