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 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 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 void Xor <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) { var key = *(T *)((byte *)entry + other->_collection.KeyOffset); var keyHash = key.GetHashCode(); // if we don't find it in our collection, add it if (UnsafeHashCollection.Find <T>(&set->_collection, key, keyHash) == null) { UnsafeHashCollection.Insert <T>(&set->_collection, key, keyHash); } // if we do, remove it else { UnsafeHashCollection.Remove <T>(&set->_collection, key, keyHash); } } } }