public static void CopyTo <T>(UnsafeHashSet *set, void *destination, int destinationIndex) where T : unmanaged { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } if (destinationIndex < 0) { throw new ArgumentOutOfRangeException(ThrowHelper.ArgumentOutOfRange_Index); } UDebug.Assert(set != null); UDebug.Assert(typeof(T).TypeHandle.Value == set->_typeHandle); var enumerator = GetEnumerator <T>(set); var dest = (T *)destination; int i = 0; while (enumerator.MoveNext()) { dest[destinationIndex + i] = enumerator.Current; i++; } }
/// <summary> /// Removes all elements in the specified hashset from the current hashset. /// </summary> public static void ExceptWith <T>(UnsafeHashSet *set, UnsafeHashSet *other) where T : unmanaged, IEquatable <T> { UDebug.Assert(set != null); UDebug.Assert(typeof(T).TypeHandle.Value == set->_typeHandle); UDebug.Assert(other != null); UDebug.Assert(typeof(T).TypeHandle.Value == other->_typeHandle); // When this set has no elements, return if (GetCount(set) == 0) { return; } // A set except itself is an empty set. if (other == set) { Clear(set); return; } for (int i = other->_collection.UsedCount - 1; i >= 0; --i) { var entry = UnsafeHashCollection.GetEntry(&other->_collection, i); if (entry->State == UnsafeHashCollection.EntryState.Used) { var key = *(T *)((byte *)entry + other->_collection.KeyOffset); var keyHash = key.GetHashCode(); UnsafeHashCollection.Remove(&set->_collection, key, keyHash); } } }
public static bool Contains <T>(UnsafeHashSet *set, T key) where T : unmanaged, IEquatable <T> { UDebug.Assert(set != null); UDebug.Assert(typeof(T).TypeHandle.Value == set->_typeHandle); return(UnsafeHashCollection.Find(&set->_collection, key, key.GetHashCode()) != null); }
public static Enumerator <T> GetEnumerator <T>(UnsafeHashSet *set) where T : unmanaged { UDebug.Assert(set != null); UDebug.Assert(typeof(T).TypeHandle.Value == set->_typeHandle); return(new Enumerator <T>(set)); }
public static void Free(UnsafeHashSet *set) { if (set->_collection.Entries.Dynamic == 1) { UnsafeHashCollection.Free(&set->_collection); } Native.Free(set); }
public static void Free(UnsafeHashSet *set) { if (set->_collection.Entries.Dynamic) { UnsafeHashCollection.Free(&set->_collection); } AllocHelper.Free(set); }
public static void Or <T>(UnsafeHashSet *set, UnsafeHashSet *other) where T : unmanaged, IEquatable <T> { for (int i = other->_collection.UsedCount - 1; i >= 0; --i) { var entry = UnsafeHashCollection.GetEntry(&other->_collection, i); if (entry->State == UnsafeHashCollection.EntryState.Used) { // always add to this collection Add <T>(set, *(T *)((byte *)entry + other->_collection.KeyOffset)); } } }
public static bool Add <T>(UnsafeHashSet *set, T key) where T : unmanaged, IEquatable <T> { var hash = key.GetHashCode(); var entry = UnsafeHashCollection.Find <T>(&set->_collection, key, hash); if (entry == null) { UnsafeHashCollection.Insert <T>(&set->_collection, key, hash); return(true); } return(false); }
public static void Free(UnsafeHashSet *set) { if (set == null) { return; } if (set->_collection.Entries.Dynamic == 1) { UnsafeHashCollection.Free(&set->_collection); } *set = default; Memory.Free(set); }
public static bool Add <T>(UnsafeHashSet *set, T key) where T : unmanaged, IEquatable <T> { UDebug.Assert(set != null); UDebug.Assert(typeof(T).TypeHandle.Value == set->_typeHandle); var hash = key.GetHashCode(); var entry = UnsafeHashCollection.Find <T>(&set->_collection, key, hash); if (entry == null) { UnsafeHashCollection.Insert <T>(&set->_collection, key, hash); return(true); } return(false); }
/// <summary> /// Modifies the current hashset to contain all elements that are present in itself, the specified hashset, or both. /// </summary> public static void UnionWith <T>(UnsafeHashSet *set, UnsafeHashSet *other) where T : unmanaged, IEquatable <T> { UDebug.Assert(set != null); UDebug.Assert(typeof(T).TypeHandle.Value == set->_typeHandle); UDebug.Assert(other != null); UDebug.Assert(typeof(T).TypeHandle.Value == other->_typeHandle); for (int i = other->_collection.UsedCount - 1; i >= 0; --i) { var entry = UnsafeHashCollection.GetEntry(&other->_collection, i); if (entry->State == UnsafeHashCollection.EntryState.Used) { // always add to this collection Add <T>(set, *(T *)((byte *)entry + other->_collection.KeyOffset)); } } }
public static void And <T>(UnsafeHashSet *set, UnsafeHashSet *other) where T : unmanaged, IEquatable <T> { for (int i = set->_collection.UsedCount - 1; i >= 0; --i) { var entry = UnsafeHashCollection.GetEntry(&set->_collection, i); if (entry->State == UnsafeHashCollection.EntryState.Used) { var key = *(T *)((byte *)entry + set->_collection.KeyOffset); var keyHash = key.GetHashCode(); // if we don't find this in other collection, remove it (And) if (UnsafeHashCollection.Find <T>(&other->_collection, key, keyHash) == null) { UnsafeHashCollection.Remove <T>(&set->_collection, key, keyHash); } } } }
/// <summary> /// Modifies the current hashset to contain only elements that are present in that hashset and in the specified hashset. /// </summary> public static void IntersectsWith <T>(UnsafeHashSet *set, UnsafeHashSet *other) where T : unmanaged, IEquatable <T> { UDebug.Assert(set != null); UDebug.Assert(typeof(T).TypeHandle.Value == set->_typeHandle); UDebug.Assert(other != null); UDebug.Assert(typeof(T).TypeHandle.Value == other->_typeHandle); // When this set has no elements, there is nothing to intersect. // When this set equals other, it is already intersecting. if (GetCount(set) == 0 || set == other) { return; } // When the other set has no elements, clear this one completely if (GetCount(other) == 0) { Clear(set); return; } for (int i = set->_collection.UsedCount - 1; i >= 0; --i) { var entry = UnsafeHashCollection.GetEntry(&set->_collection, i); if (entry->State == UnsafeHashCollection.EntryState.Used) { var key = *(T *)((byte *)entry + set->_collection.KeyOffset); var keyHash = key.GetHashCode(); // if we don't find this in other collection, remove it (And) if (UnsafeHashCollection.Find <T>(&other->_collection, key, keyHash) == null) { UnsafeHashCollection.Remove <T>(&set->_collection, key, keyHash); } } } }
public static int Capacity(UnsafeHashSet *set) { return(set->_collection.Entries.Length); }
public static int Count(UnsafeHashSet *set) { return(set->_collection.UsedCount - set->_collection.FreeCount); }
public static void Clear(UnsafeHashSet *set) { UnsafeHashCollection.Clear(&set->_collection); }
public static bool IsFixedSize(UnsafeHashSet *set) { UDebug.Assert(set != null); return(set->_collection.Entries.Dynamic == 0); }
public static int GetCapacity(UnsafeHashSet *set) { UDebug.Assert(set != null); return(set->_collection.Entries.Length); }
public static int GetCount(UnsafeHashSet *set) { UDebug.Assert(set != null); return(set->_collection.UsedCount - set->_collection.FreeCount); }
public NativeHashSet(int capacity) { m_inner = UnsafeHashSet.Allocate <T>(capacity, false); }
public static bool Remove <T>(UnsafeHashSet *set, T key) where T : unmanaged, IEquatable <T> { return(UnsafeHashCollection.Remove <T>(&set->_collection, key, key.GetHashCode())); }
public static bool Contains <T>(UnsafeHashSet *set, T key) where T : unmanaged, IEquatable <T> { return(UnsafeHashCollection.Find <T>(&set->_collection, key, key.GetHashCode()) != null); }
public NativeHashSet(int capacity, bool fixedSize) { m_inner = UnsafeHashSet.Allocate <T>(capacity, fixedSize); }
public static void Clear(UnsafeHashSet *set) { UDebug.Assert(set != null); UnsafeHashCollection.Clear(&set->_collection); }
public Iterator(UnsafeHashSet *set) { _keyOffset = set->_collection.KeyOffset; _iterator = new UnsafeHashCollection.Iterator(&set->_collection); }
public static Iterator <T> GetIterator <T>(UnsafeHashSet *set) where T : unmanaged { return(new Iterator <T>(set)); }