示例#1
0
 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;
 }
示例#2
0
        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);
        }
示例#3
0
        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);
            }
        }
示例#4
0
        public override void Clear()
        {
            Object writeLock = GetWriteLock();

            lock (writeLock)
            {
                if (Count == 0)
                {
                    return;
                }
                TempHashSet <K> backupMap = CreateCopy();
                backupMap.Clear();
                SaveCopy(backupMap);
            }
        }
示例#5
0
        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);
            }
        }
示例#6
0
        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);
            }
        }