public void Clear() { if (count > 0) { _buckets.SetAllValues(-1); _entries.ClearAllChunks(); freeList = -1; count = 0; freeCount = 0; version++; } }
private void Initialize(int capacity) { _size = HashHelpers.GetPrime(capacity); _buckets = new NoLohData <int>(); _entries = new NoLohData <Entry>(); _buckets.EnsureSize(_size); _buckets.SetAllValues(-1); _entries.EnsureSize(_size); freeList = -1; }
private void Resize(int newSize, bool forceNewHashCodes) { Contract.Assert(newSize >= _size); _buckets = _buckets ?? new NoLohData <int>(); _buckets.EnsureSize(newSize); _buckets.SetAllValues(-1); _entries = _entries ?? new NoLohData <Entry>(); _entries.EnsureSize(newSize); int temp = 0; if (forceNewHashCodes) { for (int i = 0; temp < count && i < _entries.VirtualArrayCount; i++) { var chunkData = _entries.Values[i]; for (int j = 0; temp < count && j < chunkData.Length; j++) { if (chunkData[j].hashCode != -1) { chunkData[j].hashCode = (comparer.GetHashCode(chunkData[j].key) & 0x7FFFFFFF); temp++; } } } } temp = 0; for (int i = 0; temp < count && i < _entries.VirtualArrayCount; i++) { var chunkData = _entries.Values[i]; for (int j = 0; temp < count && j < chunkData.Length; j++) { if (chunkData[j].hashCode >= 0) { int bucketChunk = -1, bucketIndexInChunk = -1; int bucket = ExtractChunkAndIndexInChunk(chunkData[j].hashCode % newSize, _maxBucketChunkElementCount, ref bucketChunk, ref bucketIndexInChunk); chunkData[j].next = _buckets.Values[bucketChunk][bucketIndexInChunk]; _buckets.Values[bucketChunk][bucketIndexInChunk] = MergeChunkAndIndexInChunk(_maxEntryChunkElementCount, i, j); temp++; } } } _size = newSize; }