protected void SaveCopy(TempHashSet <K> copy) { // Now the structure contains all necessary data, so we "retarget" the existing table table = copy.GetTable(); threshold = copy.GetThreshold(); size = copy.Count; }
protected TempHashSet <K> CreateCopy() { // Copy existing data in FULLY NEW STRUCTURE SetEntry <K>[] table = this.table; TempHashSet <K> backupSet = new TempHashSet <K>(table.Length, this.loadFactor, delegate(K key, SetEntry <K> entry) { return(EqualKeys(key, entry)); }, delegate(K key) { return(ExtractHash(key)); }); for (int a = table.Length; a-- > 0;) { SetEntry <K> entry = table[a]; while (entry != null) { K key = GetKeyOfEntry(entry); if (key != null) { backupSet.Add(CloneKey(key)); } entry = GetNextEntry(entry); } } return(backupSet); }
public override K RemoveAndGet(K key) { Object writeLock = GetWriteLock(); lock (writeLock) { TempHashSet <K> backupMap = CreateCopy(); // Write new data in the copied structure K existingKey = backupMap.RemoveAndGet(key); SaveCopy(backupMap); return(existingKey); } }
public override void Clear() { Object writeLock = GetWriteLock(); lock (writeLock) { if (Count == 0) { return; } TempHashSet <K> backupMap = CreateCopy(); backupMap.Clear(); SaveCopy(backupMap); } }
public override bool RemoveAll(IEnumerable c) { Object writeLock = GetWriteLock(); lock (writeLock) { TempHashSet <K> backupMap = CreateCopy(); // Write new data in the copied structure if (!backupMap.RemoveAll(c)) { return(false); } SaveCopy(backupMap); return(true); } }
public override bool Add(K key) { Object writeLock = GetWriteLock(); lock (writeLock) { TempHashSet <K> backupMap = CreateCopy(); // Write new data in the copied structure if (!backupMap.Add(key)) { return(false); } SaveCopy(backupMap); return(true); } }