public static void *GetPtr <K>(UnsafeHashMap *map, K key) where K : unmanaged, IEquatable <K> { var entry = UnsafeHashCollection.Find(&map->_collection, key, key.GetHashCode()); if (entry == null) { throw new KeyNotFoundException(key.ToString()); } return(GetValue(map, entry)); }
public static void Set <K>(UnsafeHashMap *map, K key, void *value, int size) where K : unmanaged, IEquatable <K> { var hash = key.GetHashCode(); var entry = UnsafeHashCollection.Find(&map->_collection, key, hash); if (entry == null) // insert new entry for key { entry = UnsafeHashCollection.Insert(&map->_collection, key, hash); } // assign value to entry UnsafeUtility.MemCpy(GetValue(map, entry), value, size); }
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 bool TryGetValuePtr <K, V>(UnsafeHashMap *map, K key, out V *val) where K : unmanaged, IEquatable <K> where V : unmanaged { var entry = UnsafeHashCollection.Find <K>(&map->_collection, key, key.GetHashCode()); if (entry != null) { val = (V *)GetValue(map, entry); return(true); } val = null; return(false); }
public static void Set <K, V>(UnsafeHashMap *map, K key, V value) where K : unmanaged, IEquatable <K> where V : unmanaged { var hash = key.GetHashCode(); var entry = UnsafeHashCollection.Find(&map->_collection, key, hash); if (entry == null) // insert new entry for key { entry = UnsafeHashCollection.Insert(&map->_collection, key, hash); } // assign value to entry *(V *)GetValue(map, entry) = value; }
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); } } } }
public static void Add <K, V>(UnsafeHashMap *map, K key, V value) where K : unmanaged, IEquatable <K> where V : unmanaged { var hash = key.GetHashCode(); var entry = UnsafeHashCollection.Find <K>(&map->_collection, key, hash); if (entry == null) { // insert new entry for key entry = UnsafeHashCollection.Insert <K>(&map->_collection, key, hash); // assign value to entry *(V *)GetValue(map, entry) = value; } else { throw new InvalidOperationException(); } }
public static bool ContainsKey <K>(UnsafeHashMap *map, K key) where K : unmanaged, IEquatable <K> { return(UnsafeHashCollection.Find <K>(&map->_collection, key, key.GetHashCode()) != null); }
public static bool Contains <T>(UnsafeHashSet *set, T key) where T : unmanaged, IEquatable <T> { return(UnsafeHashCollection.Find <T>(&set->_collection, key, key.GetHashCode()) != null); }