示例#1
0
            public ValueCollection(FastDictionary <TKey, TValue, TComparer> dictionary)
            {
                Contract.Requires(dictionary != null);
                Contract.EndContractBlock();

                this.dictionary = dictionary;
            }
示例#2
0
        public FastDictionary(
            int initialBucketCount,
            FastDictionary <TKey, TValue, TComparer> src)
        {
            Contract.Requires(src != null);
            Contract.Ensures(this.Capacity >= initialBucketCount);
            Contract.Ensures(this.Capacity >= src.Capacity);
            Contract.EndContractBlock();

            this.initialCapacity     = DictionaryHelper.NextPowerOf2(initialBucketCount);
            this.Capacity            = Math.Max(src.Capacity, initialBucketCount);
            this.Count               = src.Count;
            this.numberOfUsed        = src.numberOfUsed;
            this.numberOfDeleted     = src.numberOfDeleted;
            this.nextGrowthThreshold = src.nextGrowthThreshold;

            var newCapacity = this.Capacity;

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

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

                // This call will rewrite the aliases
                this.Rehash(e);
            }
        }
示例#3
0
 internal ValueEnumerator(FastDictionary <TKey, TValue, TComparer> dictionary)
 {
     this.dictionary = dictionary;
     this.index      = 0;
     this.Current    = default(TValue);
 }
示例#4
0
 public FastDictionary(FastDictionary <TKey, TValue, TComparer> src)
     : this(src.Capacity, src)
 {
 }
示例#5
0
 internal Enumerator(FastDictionary <TKey, TValue, TComparer> dictionary)
 {
     this.dictionary = dictionary;
     this.index      = 0;
     this.Current    = new KeyValuePair <TKey, TValue>();
 }