Beispiel #1
0
        protected FastDictionaryBase(int initialBucketCount, FastDictionaryBase <TKey, TValue, TComparer> src, TComparer comparer)
        {
            Contract.Requires(src != null);
            Contract.Requires(comparer != null);
            Contract.Ensures(_capacity >= initialBucketCount);
            Contract.Ensures(_capacity >= src._capacity);

            this._comparer = comparer;

            this._initialCapacity     = Bits.NextPowerOf2(initialBucketCount);
            this._capacity            = Math.Max(src._capacity, initialBucketCount);
            this._capacityMask        = this._capacity - 1;
            this._size                = src._size;
            this._numberOfUsed        = src._numberOfUsed;
            this._numberOfDeleted     = src._numberOfDeleted;
            this._nextGrowthThreshold = src._nextGrowthThreshold;

            if (comparer.Equals(src._comparer))
            {
                // Initialization through copy (very efficient) because the comparer is the same.
                this._entries = new Entry[_capacity];
                Array.Copy(src._entries, _entries, _capacity);

                _usedEntries = new int[src._usedEntries.Length];
                Array.Copy(src._usedEntries, _usedEntries, src._usedEntries.Length);
                _usedEntriesIndex = src._usedEntriesIndex;
            }
            else
            {
                // Initialization through rehashing because the comparer is not the same.
                var entries = new Entry[_capacity];
                BlockCopyMemoryHelper.Memset(entries, new Entry(KUnusedHash, default(TKey), default(TValue)));

                // Creating a temporary alias to use for rehashing.
                this._entries = src._entries;
                _usedEntries  = new int[_capacity];

                // This call will rewrite the aliases
                Rehash(entries);
            }
        }
Beispiel #2
0
            public KeyCollection(FastDictionaryBase <TKey, TValue, TComparer> dictionary)
            {
                Contract.Requires(dictionary != null);

                this._dictionary = dictionary;
            }
Beispiel #3
0
 internal Enumerator(FastDictionaryBase <TKey, TValue, TComparer> dictionary)
 {
     this._dictionary = dictionary;
     this._index      = 0;
     this._current    = new KeyValuePair <TKey, TValue>();
 }
Beispiel #4
0
 protected FastDictionaryBase(FastDictionaryBase <TKey, TValue, TComparer> src)
     : this(src._capacity, src, src._comparer)
 {
 }
Beispiel #5
0
 internal Enumerator(FastDictionaryBase <TKey, TValue, TComparer> dictionary)
 {
     _dictionary   = dictionary;
     _index        = 0;
     _currentValue = default(TValue);
 }