protected virtual TempHashMap <MapEntry <K, V>, K, V> CreateEmptyInstance() { SmartCopyMap <K, V> This = this; return(new TempHashMap <MapEntry <K, V>, K, V>(table.Length, this.loadFactor, delegate(int hash, K key, V value, MapEntry <K, V> nextEntry) { return This.CreateEntry(hash, key, value, nextEntry); }, delegate(K key, MapEntry <K, V> entry) { return This.EqualKeys(key, entry); }, delegate(K key) { return This.ExtractHash(key); }, delegate(MapEntry <K, V> entry, MapEntry <K, V> nextEntry) { This.SetNextEntry(entry, nextEntry); }, delegate(MapEntry <K, V> entry, V value) { return This.SetValueForEntry(entry, value); })); }
protected TempHashMap <MapEntry <K, V>, K, V> CreateCopy() { SmartCopyMap <K, V> This = this; // Copy existing data in FULLY NEW STRUCTURE MapEntry <K, V>[] table = this.table; TempHashMap <MapEntry <K, V>, K, V> backupMap = CreateEmptyInstance(); if (AutoCleanupNullValue) { for (int a = table.Length; a-- > 0;) { MapEntry <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.NextEntryReal; } } } else { for (int a = table.Length; a-- > 0;) { MapEntry <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 = GetNextEntry(entry); } } } return(backupMap); }