protected FastDictionaryBase(int initialBucketCount, TComparer comparer) { Contract.Requires(comparer != null); Contract.Ensures(_capacity >= initialBucketCount); this._comparer = comparer; // Calculate the next power of 2. int newCapacity = initialBucketCount >= DictionaryHelper.KMinBuckets ? initialBucketCount : DictionaryHelper.KMinBuckets; newCapacity = Bits.NextPowerOf2(newCapacity); this._initialCapacity = newCapacity; // Initialization this._entries = new Entry[newCapacity]; BlockCopyMemoryHelper.Memset(this._entries, new Entry(KUnusedHash, default(TKey), default(TValue))); _usedEntries = new int[newCapacity]; _usedEntriesIndex = 0; this._capacity = newCapacity; this._capacityMask = this._capacity - 1; this._numberOfUsed = 0; this._numberOfDeleted = 0; this._size = 0; this._nextGrowthThreshold = _capacity * 4 / KLoadFactor; }
public FastDictionary(int initialBucketCount) { Contract.Ensures(this.Capacity >= initialBucketCount); Contract.EndContractBlock(); // Calculate the next power of 2. var newCapacity = initialBucketCount >= DictionaryHelper.MinBuckets ? initialBucketCount : DictionaryHelper.MinBuckets; newCapacity = DictionaryHelper.NextPowerOf2(newCapacity); this.initialCapacity = newCapacity; // Initialization this.entries = new Entry[newCapacity]; BlockCopyMemoryHelper.Memset(this.entries, new Entry(UnusedHash, default(TKey), default(TValue))); this.Capacity = newCapacity; this.numberOfUsed = 0; this.numberOfDeleted = 0; this.Count = 0; this.nextGrowthThreshold = this.Capacity * 4 / LoadFactor; }
public FastDictionary(int initialBucketCount, IEqualityComparer <TKey> comparer) { Contract.Ensures(_capacity >= initialBucketCount); this.comparer = comparer ?? EqualityComparer <TKey> .Default; // Calculate the next power of 2. int newCapacity = initialBucketCount >= DictionaryHelper.kMinBuckets ? initialBucketCount : DictionaryHelper.kMinBuckets; newCapacity = DictionaryHelper.NextPowerOf2(newCapacity); this._initialCapacity = newCapacity; // Initialization this._entries = new Entry[newCapacity]; BlockCopyMemoryHelper.Memset(this._entries, new Entry(kUnusedHash, default(TKey), default(TValue))); this._capacity = newCapacity; this._capacityM1 = this._capacity - 1; this._numberOfUsed = 0; this._numberOfDeleted = 0; this._size = 0; this._nextGrowthThreshold = _capacity * 4 / tLoadFactor; }
public void Clear() { this.entries = new Entry[this.Capacity]; BlockCopyMemoryHelper.Memset(this.entries, new Entry(UnusedHash, default(TKey), default(TValue))); this.numberOfUsed = 0; this.numberOfDeleted = 0; this.Count = 0; }
public void Clear() { this._entries = new Entry[_capacity]; BlockCopyMemoryHelper.Memset(this._entries, new Entry(kUnusedHash, default(TKey), default(TValue))); this._numberOfUsed = 0; this._numberOfDeleted = 0; this._size = 0; }
private void Grow(int newCapacity) { Contract.Requires(newCapacity >= _capacity); Contract.Ensures((_capacity & (_capacity - 1)) == 0); var entries = new Entry[newCapacity]; BlockCopyMemoryHelper.Memset(entries, new Entry(kUnusedHash, default(TKey), default(TValue))); Rehash(entries); }
private void Grow(int newCapacity) { Contract.Requires(newCapacity >= this.Capacity); Contract.Ensures((this.Capacity & (this.Capacity - 1)) == 0); Contract.EndContractBlock(); var e = new Entry[newCapacity]; BlockCopyMemoryHelper.Memset(e, new Entry(UnusedHash, default(TKey), default(TValue))); this.Rehash(e); }
private void Shrink(int newCapacity) { Contract.Requires(newCapacity > _size); Contract.Ensures(this._numberOfUsed < this._capacity); // Calculate the next power of 2. newCapacity = Math.Max(DictionaryHelper.NextPowerOf2(newCapacity), _initialCapacity); var entries = new Entry[newCapacity]; BlockCopyMemoryHelper.Memset(entries, new Entry(kUnusedHash, default(TKey), default(TValue))); Rehash(entries); }
private void Shrink(int newCapacity) { Contract.Requires(newCapacity > _size); Contract.Ensures(_numberOfUsed < _capacity); // Calculate the next power of 2. newCapacity = Math.Max(Bits.NextPowerOf2(newCapacity), _initialCapacity); var entries = new Entry[newCapacity]; BlockCopyMemoryHelper.Memset(entries, new Entry(kUnused, kUnused, default(Internal))); Rehash(entries); }
private void Shrink(int newCapacity) { Contract.Requires(newCapacity > this.Count); Contract.Ensures(this.numberOfUsed < this.Capacity); Contract.EndContractBlock(); // Calculate the next power of 2. newCapacity = Math.Max(DictionaryHelper.NextPowerOf2(newCapacity), this.initialCapacity); var e = new Entry[newCapacity]; BlockCopyMemoryHelper.Memset(e, new Entry(UnusedHash, default(TKey), default(TValue))); this.Rehash(e); }
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); } }
public ZFastNodesTable(int initialBucketCount, ZFastTrieSortedSet <TKey, TValue> owner) { this.owner = owner; // Calculate the next power of 2. int newCapacity = initialBucketCount >= kMinCapacity ? initialBucketCount : kMinCapacity; newCapacity = Bits.NextPowerOf2(newCapacity); _initialCapacity = newCapacity; // Initialization _entries = new Entry[newCapacity]; BlockCopyMemoryHelper.Memset(_entries, new Entry(kUnused, kUnused, default(Internal))); _capacity = newCapacity; _numberOfUsed = 0; _numberOfDeleted = 0; _size = 0; _nextGrowthThreshold = _capacity * 4 / tLoadFactor; }
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); } }
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._capacityM1 = this._capacity - 1; 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); } }