/// <summary> /// Expands the set to the next good capacity. /// This will expand to the capacity GetNextLength(set.Capacity). /// See: GetNextLength. /// </summary> public static void Expand <TKey>(SimpleSet <TKey> Set) { var oldCapacity = Set.Capacity; var oldEntries = Set.Entries; var newCapacity = GetNextLength(oldCapacity); var newArrayEntry = new SetEntry <TKey> [newCapacity]; Set.Capacity = newCapacity; Set.Entries = newArrayEntry; Set.Count = 0; for (int i = 0; i < oldCapacity; i++) { var entry = oldEntries[i]; if (entry != null) { Add(Set, entry.Key); while (entry.Next != null) { entry = entry.Next; Add(Set, entry.Key); } } } }
/// <summary> /// Creates a new set entry with the given values. /// </summary> private static SetEntry <TKey> CreateEntry <TKey>(SimpleSet <TKey> Set, TKey key, int hash) { SetEntry <TKey> newEntry; if (Set.EntryPool.Count > 0) { newEntry = Set.EntryPool[Set.EntryPool.Count - 1]; SList.RemoveLast(Set.EntryPool); // remove last for better perfomance } else { newEntry = new SetEntry <TKey>(); } newEntry.Key = key; newEntry.HashCode = hash; return(newEntry); }
private void MoveToNext() { if (CurrentEntry != null) { CurrentEntry = CurrentEntry.Next; if (CurrentEntry == null) { CurrentIndex++; } else { return; } } for (; CurrentIndex < Set.Capacity; CurrentIndex++) { CurrentEntry = Set.Entries[CurrentIndex]; if (CurrentEntry != null) { break; } } }
public void Reset() { CurrentIndex = 0; CurrentEntry = null; }
public void Dispose() { CurrentEntry = null; }