示例#1
0
        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));
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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;
        }
示例#6
0
        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);
                    }
                }
            }
        }
示例#7
0
        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();
            }
        }
示例#8
0
 public static bool ContainsKey <K>(UnsafeHashMap *map, K key) where K : unmanaged, IEquatable <K>
 {
     return(UnsafeHashCollection.Find <K>(&map->_collection, key, key.GetHashCode()) != null);
 }
示例#9
0
 public static bool Contains <T>(UnsafeHashSet *set, T key) where T : unmanaged, IEquatable <T>
 {
     return(UnsafeHashCollection.Find <T>(&set->_collection, key, key.GetHashCode()) != null);
 }