示例#1
0
        public FastDictionary(int initialBucketCount, FastDictionary <TKey, TValue> src, IEqualityComparer <TKey> comparer)
        {
            Contract.Requires(src != null);
            Contract.Ensures(_capacity >= initialBucketCount);
            Contract.Ensures(_capacity >= src._capacity);

            this.comparer = comparer ?? EqualityComparer <TKey> .Default;

            this._initialCapacity     = DictionaryHelper.NextPowerOf2(initialBucketCount);
            this._capacity            = Math.Max(src._capacity, initialBucketCount);
            this._size                = src._size;
            this._numberOfUsed        = src._numberOfUsed;
            this._numberOfDeleted     = src._numberOfDeleted;
            this._nextGrowthThreshold = src._nextGrowthThreshold;

            int newCapacity = _capacity;

            if (comparer == src.comparer)
            {
                // Initialization through copy (very efficient) because the comparer is the same.
                this._entries = new Entry[newCapacity];
                Array.Copy(src._entries, _entries, newCapacity);
            }
            else
            {
                // Initialization through rehashing because the comparer is not the same.
                var entries = new Entry[newCapacity];
                BlockCopyMemoryHelper.Memset(entries, new Entry(kUnusedHash, default(TKey), default(TValue)));

                // Creating a temporary alias to use for rehashing.
                this._entries = src._entries;

                // This call will rewrite the aliases
                Rehash(entries);
            }
        }
示例#2
0
            public ValueCollection(FastDictionary <TKey, TValue> dictionary)
            {
                Contract.Requires(dictionary != null);

                this.dictionary = dictionary;
            }
示例#3
0
 internal Enumerator(FastDictionary <TKey, TValue> dictionary)
 {
     this.dictionary = dictionary;
     index           = 0;
     currentKey      = default(TKey);
 }
示例#4
0
 internal Enumerator(FastDictionary <TKey, TValue> dictionary)
 {
     this.dictionary = dictionary;
     this.index      = 0;
     this.current    = new KeyValuePair <TKey, TValue>();
 }
示例#5
0
 public FastDictionary(FastDictionary <TKey, TValue> src)
     : this(src._capacity, src, src.comparer)
 {
 }
示例#6
0
 public FastDictionary(FastDictionary <TKey, TValue> src, IEqualityComparer <TKey> comparer)
     : this(src._capacity, src, comparer)
 {
 }