Exemplo n.º 1
0
        public static void Free(UnsafeHashMap *set)
        {
            if (set->_collection.Entries.Dynamic == 1)
            {
                UnsafeHashCollection.Free(&set->_collection);
            }

            Native.Free(set);
        }
Exemplo n.º 2
0
        public static void Free(UnsafeHashMap *set)
        {
            if (set->_collection.Entries.Dynamic)
            {
                UnsafeHashCollection.Free(&set->_collection);
            }

            AllocHelper.Free(set);
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 8
0
 public static int Count(UnsafeHashMap *map)
 {
     return(map->_collection.UsedCount - map->_collection.FreeCount);
 }
Exemplo n.º 9
0
 public static int Capacity(UnsafeHashMap *map)
 {
     return(map->_collection.Entries.Length);
 }
Exemplo n.º 10
0
 static void *GetValue(UnsafeHashMap *map, UnsafeHashCollection.Entry *entry)
 {
     return((byte *)entry + map->_valueOffset);
 }
Exemplo n.º 11
0
 public static bool Remove <K>(UnsafeHashMap *map, K key) where K : unmanaged, IEquatable <K>
 {
     return(UnsafeHashCollection.Remove <K>(&map->_collection, key, key.GetHashCode()));
 }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
0
 public static Iterator <K, V> GetIterator <K, V>(UnsafeHashMap *map)
     where K : unmanaged
     where V : unmanaged
 {
     return(new Iterator <K, V>(map));
 }
Exemplo n.º 14
0
 public static void Free(UnsafeHashMap *map)
 {
     AllocHelper.Free(map->_collection.Buckets);
     AllocHelper.Free(map->_collection.FreeHead);
     UnsafeBuffer.Free(&map->_collection.Entries);
 }
Exemplo n.º 15
0
 public Iterator(UnsafeHashMap *map)
 {
     _valueOffset = map->_valueOffset;
     _keyOffset   = map->_collection.KeyOffset;
     _iterator    = new UnsafeHashCollection.Iterator(&map->_collection);
 }
Exemplo n.º 16
0
 public DefaultSnapshotSerializer()
 {
     SystemToChunks   = UnsafeHashMap.Allocate(64, sizeof(uint), UnsafeUtility.SizeOf <SystemChunkData>());
     SystemToGhostIds = UnsafeHashMap.Allocate(64, sizeof(uint), UnsafeUtility.SizeOf <SystemGhostData>());
 }
Exemplo n.º 17
0
 public static void Clear(UnsafeHashMap *set)
 {
     UnsafeHashCollection.Clear(&set->_collection);
 }
Exemplo n.º 18
0
 public void Allocate()
 {
     SystemData = UnsafeHashMap.Allocate <uint, IntPtr>(256);
 }
Exemplo n.º 19
0
 public void Allocate()
 {
     SystemData = UnsafePtrList.Create(256, Allocator.Persistent, NativeArrayOptions.ClearMemory);
 }