예제 #1
0
 public DictionarySlim(int capacity)
 {
     if (capacity < 2)
     {
         capacity = 2; // 1 would indicate the dummy array
     }
     capacity = HashHelpers.PowerOf2(capacity);
     _buckets = new int[capacity];
     _entries = new Entry[capacity];
 }
예제 #2
0
 public RefDictionary(int capacity)
 {
     if (capacity < 0)
     {
         HashHelpers.ThrowCapacityArgumentOutOfRangeException();
     }
     if (capacity < 2)
     {
         capacity = 2;
     }
     capacity = HashHelpers.PowerOf2(capacity);
     _buckets = new int[capacity];
     _entries = new Entry[capacity];
 }
예제 #3
0
            public DictionarySlim1(IEnumerable <KeyValuePair <TKey, TValue> > dictionary, int count)
            {
                Count = count;
                var size    = HashHelpers.PowerOf2(count);
                var buckets = new int[size];
                var entries = new Entry[size];
                var i       = 0;

                if (dictionary != null)
                {
                    foreach (var pair in dictionary)
                    {
                        var     value  = pair.Key;
                        ref int bucket = ref buckets[value.GetHashCode() & (size - 1)];
                        entries[i] = new Entry(bucket - 1, value, pair.Value);
                        bucket     = i + 1;
                        ++i;
                    }
                }