From 4c6e0ed045200b1b750ed988301297b6ce896baf Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sat, 16 Mar 2024 13:54:50 +0800 Subject: [PATCH] refactoring --- src/EcsArc.cs | 10 +- src/EcsWorldConfig.cs | 7 - src/EcsWorldGraph.cs | 4 +- src/{Utils => Internal}/ArrayUtility.cs | 2 +- src/{Utils => Internal}/BitsUtility.cs | 4 +- src/{Utils => Internal}/RelEntityInfo.cs | 4 +- src/{Utils => Internal}/SparseArray.cs | 4 +- src/{Utils => Internal}/SparseMatrix.cs | 85 +------- src/{Utils => Internal}/UnsafeArray.cs | 2 +- src/Utils/ArrayUtility.cs.meta | 11 - src/Utils/Exceptions.cs | 32 ++- src/Utils/IdsBasket.cs.meta | 11 - src/Utils/RelationTargets.cs.meta | 11 - src/Utils/SparseArray.cs.meta | 11 - src/Utils/SparseArray64.cs | 265 ----------------------- src/Utils/SparseArray64.cs.meta | 11 - 16 files changed, 51 insertions(+), 423 deletions(-) delete mode 100644 src/EcsWorldConfig.cs rename src/{Utils => Internal}/ArrayUtility.cs (99%) rename src/{Utils => Internal}/BitsUtility.cs (99%) rename src/{Utils => Internal}/RelEntityInfo.cs (94%) rename src/{Utils => Internal}/SparseArray.cs (98%) rename src/{Utils => Internal}/SparseMatrix.cs (78%) rename src/{Utils => Internal}/UnsafeArray.cs (99%) delete mode 100644 src/Utils/ArrayUtility.cs.meta delete mode 100644 src/Utils/IdsBasket.cs.meta delete mode 100644 src/Utils/RelationTargets.cs.meta delete mode 100644 src/Utils/SparseArray.cs.meta delete mode 100644 src/Utils/SparseArray64.cs delete mode 100644 src/Utils/SparseArray64.cs.meta diff --git a/src/EcsArc.cs b/src/EcsArc.cs index 48db565..0d5e70d 100644 --- a/src/EcsArc.cs +++ b/src/EcsArc.cs @@ -1,4 +1,4 @@ -using DCFApixels.DragonECS.Relations.Internal; +using DCFApixels.DragonECS.Graphs.Internal; using System; using System.Runtime.CompilerServices; @@ -223,8 +223,6 @@ namespace DCFApixels.DragonECS { foreach (var relEntityID in relEntityBuffer) { - //var (startEntityID, endEntityID) = _arc._relEntityInfos[relEntityID]; - //_arc.ClearRelation_Internal(startEntityID, endEntityID); _arc.ClearRelation_Internal(relEntityID); } } @@ -242,7 +240,7 @@ namespace DCFApixels.DragonECS { _arc = arc; _arc.StartWorld.AddListener(this); - OnWorldResize(_arc.StartWorld.Capacity); + //OnWorldResize(_arc.StartWorld.Capacity); } public void Destroy() { @@ -264,7 +262,7 @@ namespace DCFApixels.DragonECS { _arc = arc; _arc.EndWorld.AddListener(this); - OnWorldResize(_arc.EndWorld.Capacity); + //OnWorldResize(_arc.EndWorld.Capacity); } public void Destroy() { @@ -286,7 +284,7 @@ namespace DCFApixels.DragonECS { _arc = arc; _arc.StartWorld.AddListener(this); - OnWorldResize(_arc.StartWorld.Capacity); + //OnWorldResize(_arc.StartWorld.Capacity); } public void Destroy() { diff --git a/src/EcsWorldConfig.cs b/src/EcsWorldConfig.cs deleted file mode 100644 index d77b0e0..0000000 --- a/src/EcsWorldConfig.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace DCFApixels.DragonECS -{ - public static class EcsWorldConfigRelationsExtensions - { - - } -} diff --git a/src/EcsWorldGraph.cs b/src/EcsWorldGraph.cs index 5c26166..e75ba09 100644 --- a/src/EcsWorldGraph.cs +++ b/src/EcsWorldGraph.cs @@ -1,5 +1,5 @@ -using DCFApixels.DragonECS.Relations.Internal; -using DCFApixels.DragonECS.Relations.Utils; +using DCFApixels.DragonECS.Graphs.Internal; +using DCFApixels.DragonECS.Graphs.Utils; using System; namespace DCFApixels.DragonECS diff --git a/src/Utils/ArrayUtility.cs b/src/Internal/ArrayUtility.cs similarity index 99% rename from src/Utils/ArrayUtility.cs rename to src/Internal/ArrayUtility.cs index fee8b84..cf3771c 100644 --- a/src/Utils/ArrayUtility.cs +++ b/src/Internal/ArrayUtility.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace DCFApixels.DragonECS.Relations.Internal +namespace DCFApixels.DragonECS.Graphs.Internal { internal static class ArrayUtility { diff --git a/src/Utils/BitsUtility.cs b/src/Internal/BitsUtility.cs similarity index 99% rename from src/Utils/BitsUtility.cs rename to src/Internal/BitsUtility.cs index 2bf2725..29dcf08 100644 --- a/src/Utils/BitsUtility.cs +++ b/src/Internal/BitsUtility.cs @@ -3,9 +3,9 @@ using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; -using static DCFApixels.DragonECS.Relations.Internal.BitsUtility; +using static DCFApixels.DragonECS.Graphs.Internal.BitsUtility; -namespace DCFApixels.DragonECS.Relations.Internal +namespace DCFApixels.DragonECS.Graphs.Internal { internal unsafe static class BitsUtility { diff --git a/src/Utils/RelEntityInfo.cs b/src/Internal/RelEntityInfo.cs similarity index 94% rename from src/Utils/RelEntityInfo.cs rename to src/Internal/RelEntityInfo.cs index 8cc3e68..d8ed03d 100644 --- a/src/Utils/RelEntityInfo.cs +++ b/src/Internal/RelEntityInfo.cs @@ -2,11 +2,11 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace DCFApixels.DragonECS +namespace DCFApixels.DragonECS.Graphs.Internal { [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 8)] [Serializable] - public readonly struct RelEntityInfo : IEquatable + internal readonly struct RelEntityInfo : IEquatable { public static readonly RelEntityInfo Empty = new RelEntityInfo(); diff --git a/src/Utils/SparseArray.cs b/src/Internal/SparseArray.cs similarity index 98% rename from src/Utils/SparseArray.cs rename to src/Internal/SparseArray.cs index 8ceaff8..b50bd74 100644 --- a/src/Utils/SparseArray.cs +++ b/src/Internal/SparseArray.cs @@ -6,9 +6,9 @@ using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace DCFApixels.DragonECS.Relations.Utils +namespace DCFApixels.DragonECS.Graphs.Internal { - public class SparseArray + internal class SparseArray { public const int MIN_CAPACITY_BITS_OFFSET = 4; public const int MIN_CAPACITY = 1 << MIN_CAPACITY_BITS_OFFSET; diff --git a/src/Utils/SparseMatrix.cs b/src/Internal/SparseMatrix.cs similarity index 78% rename from src/Utils/SparseMatrix.cs rename to src/Internal/SparseMatrix.cs index 6901347..647c656 100644 --- a/src/Utils/SparseMatrix.cs +++ b/src/Internal/SparseMatrix.cs @@ -3,7 +3,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using TValue = System.Int32; -namespace DCFApixels.DragonECS.Relations.Internal +namespace DCFApixels.DragonECS.Graphs.Internal { internal sealed unsafe class SparseMatrix { @@ -33,7 +33,6 @@ namespace DCFApixels.DragonECS.Relations.Internal public int Capacity { [MethodImpl(MethodImplOptions.AggressiveInlining)] - //get { return _buckets.Length; } get { return _capacity; } } #endregion @@ -43,15 +42,11 @@ namespace DCFApixels.DragonECS.Relations.Internal public SparseMatrix(int minCapacity = MIN_CAPACITY) { minCapacity = NormalizeCapacity(minCapacity); - //_buckets = new Basket[minCapacity]; - //_buckets = new UnsafeArray(minCapacity); _buckets = UnmanagedArrayUtility.New(minCapacity); for (int i = 0; i < minCapacity; i++) { _buckets[i] = Basket.Empty; } - //_entries = new Entry[minCapacity]; - //_entries = new UnsafeArray(minCapacity, true); _entries = UnmanagedArrayUtility.NewAndInit(minCapacity); _modBitMask = (minCapacity - 1) & 0x7FFFFFFF; @@ -59,13 +54,10 @@ namespace DCFApixels.DragonECS.Relations.Internal _freeList = 0; _freeCount = 0; - // _capacity = minCapacity; } #endregion - - #region Add/TryAdd/Set [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(int x, int y, TValue value) @@ -74,7 +66,7 @@ namespace DCFApixels.DragonECS.Relations.Internal #if DEBUG if (FindEntry(key) >= 0) { - throw new ArgumentException("Has(x, y) is true"); + Throw.ArgumentException("Has(x, y) is true"); } #endif int targetBucket = key.yHash & _modBitMask; @@ -114,7 +106,6 @@ namespace DCFApixels.DragonECS.Relations.Internal int index; if (_freeCount == 0) { - //if (_count == _entries.Length) if (_count == _capacity) { Resize(); @@ -124,26 +115,23 @@ namespace DCFApixels.DragonECS.Relations.Internal } else { - //_freeCount > 0 index = _freeList; _freeList = _entries[index].next; _freeCount--; } #if DEBUG - if(_freeCount < 0) { throw new Exception(); } + if(_freeCount < 0) { Throw.UndefinedException(); } #endif ref Basket basket = ref _buckets[targetBucket]; ref Entry entry = ref _entries[index]; - entry.next = basket.index; entry.key = key; entry.value = value; basket.count++; basket.index = index; - //Console.WriteLine($"{targetBucket} {basket.count}"); if (basket.count >= MAX_CHAIN_LENGTH && Count / Capacity >= 0.7f) { @@ -191,10 +179,7 @@ namespace DCFApixels.DragonECS.Relations.Internal { int index = FindEntry(x, y); #if DEBUG - if(index < 0) - { - throw new KeyNotFoundException(); - } + if(index < 0) { Throw.KeyNotFound(); } #endif return _entries[index].value; } @@ -246,21 +231,15 @@ namespace DCFApixels.DragonECS.Relations.Internal } #endregion - - - #region Clear public void Clear() { if (_count > 0) { - //for (int i = 0; i < _buckets.Length; i++) for (int i = 0; i < _capacity; i++) { _buckets[i] = Basket.Empty; } - //Array.Clear(_entries, 0, _count); - //UnsafeArray.Clear(ref _entries); for (int i = 0; i < _capacity; i++) { _entries[i] = default; @@ -274,26 +253,16 @@ namespace DCFApixels.DragonECS.Relations.Internal [MethodImpl(MethodImplOptions.NoInlining)] private void Resize() { - //int newSize = _buckets.Length << 1; int newSize = _capacity << 1; _modBitMask = (newSize - 1) & 0x7FFFFFFF; - //Contract.Assert(newSize >= _entries.Length); - - //Basket[] newBuckets = new Basket[newSize]; - //UnsafeArray newBuckets = new UnsafeArray(newSize); Basket* newBuckets = UnmanagedArrayUtility.New(newSize); - //for (int i = 0; i < newBuckets.Length; i++) for (int i = 0; i < _capacity; i++) { newBuckets[i] = Basket.Empty; } - //Entry[] newEntries = new Entry[newSize]; - //Array.Copy(_entries, 0, newEntries, 0, _count); - //UnsafeArray newEntries = UnsafeArray.Resize(_entries, newSize); Entry* newEntries = UnmanagedArrayUtility.ResizeAndInit(_entries, _capacity, newSize); - for (int i = 0; i < _count; i++) { if (newEntries[i].key.yHash >= 0) @@ -309,8 +278,6 @@ namespace DCFApixels.DragonECS.Relations.Internal _entries = newEntries; _capacity = newSize; - - Console.WriteLine($"----- {Capacity} {Count}"); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -329,18 +296,13 @@ namespace DCFApixels.DragonECS.Relations.Internal public int next; // Index of next entry, -1 if last public Key key; public TValue value; - - public override string ToString() - { - return key.x == 0 ? "NULL" : value.ToString(); - } + public override string ToString() { return key.x == 0 ? "NULL" : value.ToString(); } } [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 8)] public struct Basket { public static readonly Basket Empty = new Basket(-1, 0); - public int index; public int count; [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -349,10 +311,7 @@ namespace DCFApixels.DragonECS.Relations.Internal this.index = index; this.count = length; } - public override string ToString() - { - return index < 0 ? "NULL" : $"{index} {count}"; - } + public override string ToString() { return index < 0 ? "NULL" : $"{index} {count}"; } } [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 8)] @@ -368,32 +327,12 @@ namespace DCFApixels.DragonECS.Relations.Internal this.yHash = yHash; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Key FromXY(int x, int y) - { - //return new Key(x, BitsUtility.NextXorShiftState(y)); - //return new Key(x, (~x) ^ y ^ 1_431_655_765); - return new Key(x, x ^ y ^ BitsUtility.NextXorShiftState(y)); - } - public static bool operator ==(Key a, Key b) - { - return a.x == b.x && a.yHash == b.yHash; - } - public static bool operator !=(Key a, Key b) - { - return a.x != b.x || a.yHash != b.yHash; - } - public override int GetHashCode() - { - return yHash; - } - public bool Equals(Key other) - { - return this == other; - } - public override bool Equals(object obj) - { - return obj is Key && Equals((Key)obj); - } + public static Key FromXY(int x, int y) { return new Key(x, x ^ y ^ BitsUtility.NextXorShiftState(y)); } + public static bool operator ==(Key a, Key b) { return a.x == b.x && a.yHash == b.yHash; } + public static bool operator !=(Key a, Key b) { return a.x != b.x || a.yHash != b.yHash; } + public override int GetHashCode() { return yHash; } + public bool Equals(Key other) { return this == other; } + public override bool Equals(object obj) { return obj is Key && Equals((Key)obj); } } #endregion } diff --git a/src/Utils/UnsafeArray.cs b/src/Internal/UnsafeArray.cs similarity index 99% rename from src/Utils/UnsafeArray.cs rename to src/Internal/UnsafeArray.cs index 9c6a91e..a57800d 100644 --- a/src/Utils/UnsafeArray.cs +++ b/src/Internal/UnsafeArray.cs @@ -5,7 +5,7 @@ using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; -namespace DCFApixels.DragonECS.Relations.Internal +namespace DCFApixels.DragonECS.Graphs.Internal { internal unsafe static class UnsafeArray { diff --git a/src/Utils/ArrayUtility.cs.meta b/src/Utils/ArrayUtility.cs.meta deleted file mode 100644 index 22f3a7a..0000000 --- a/src/Utils/ArrayUtility.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 57bb7865029f870429c7b698334b116f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/Utils/Exceptions.cs b/src/Utils/Exceptions.cs index 989aa5b..a5cd18b 100644 --- a/src/Utils/Exceptions.cs +++ b/src/Utils/Exceptions.cs @@ -1,34 +1,52 @@ using System; +using System.Collections.Generic; using System.Runtime.CompilerServices; -namespace DCFApixels.DragonECS.Relations.Internal +namespace DCFApixels.DragonECS.Graphs.Internal { internal static class Throw { + [MethodImpl(MethodImplOptions.NoInlining)] + internal static void RelationAlreadyExists() + { + throw new EcsRelationException("This relation already exists."); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + internal static void UndefinedRelationException() + { + throw new EcsRelationException(); + } + [MethodImpl(MethodImplOptions.NoInlining)] internal static void ArgumentNull() { throw new ArgumentNullException(); } [MethodImpl(MethodImplOptions.NoInlining)] + internal static void ArgumentOutOfRange() + { + throw new ArgumentOutOfRangeException($"index is less than 0 or is equal to or greater than Count."); + } + [MethodImpl(MethodImplOptions.NoInlining)] internal static void UndefinedException() { throw new Exception(); } [MethodImpl(MethodImplOptions.NoInlining)] - internal static void ArgumentOutOfRange() + internal static void Exception(string message) { - throw new ArgumentOutOfRangeException(); + throw new Exception(message); } [MethodImpl(MethodImplOptions.NoInlining)] - internal static void UndefinedRelationException() + internal static void ArgumentException(string message) { - throw new EcsRelationException(); + throw new ArgumentException(message); } [MethodImpl(MethodImplOptions.NoInlining)] - internal static void RelationAlreadyExists() + internal static void KeyNotFound() { - throw new EcsRelationException("This relation already exists."); + throw new KeyNotFoundException(); } } } diff --git a/src/Utils/IdsBasket.cs.meta b/src/Utils/IdsBasket.cs.meta deleted file mode 100644 index da6adbf..0000000 --- a/src/Utils/IdsBasket.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e369fe57852b216439940cad19bbb5f2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/Utils/RelationTargets.cs.meta b/src/Utils/RelationTargets.cs.meta deleted file mode 100644 index ac97a1a..0000000 --- a/src/Utils/RelationTargets.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5c8028c38ac28f84eac2ee5238fc3c2a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/Utils/SparseArray.cs.meta b/src/Utils/SparseArray.cs.meta deleted file mode 100644 index d92b074..0000000 --- a/src/Utils/SparseArray.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: cdd3589bd2d514845b172b2952fccc81 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/Utils/SparseArray64.cs b/src/Utils/SparseArray64.cs deleted file mode 100644 index d4c76e3..0000000 --- a/src/Utils/SparseArray64.cs +++ /dev/null @@ -1,265 +0,0 @@ -//SparseArray64. Analogous to Dictionary, but faster. -//Benchmark result of indexer.get speed test with 300 elements: -//[Dictinary: 6.705us] [SparseArray64: 2.512us]. -using DCFApixels.DragonECS.Relations.Internal; -using System; -using System.Diagnostics; -using System.Diagnostics.Contracts; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace DCFApixels.DragonECS.Relations.Utils -{ - internal unsafe class SparseArray64 - where TValue : unmanaged - { - public const int MIN_CAPACITY_BITS_OFFSET = 4; - public const int MIN_CAPACITY = 1 << MIN_CAPACITY_BITS_OFFSET; - private const int EMPTY = -1; - - private UnsafeArray _buckets; - private UnsafeArray _entries; - - private int _count; - - private int _freeList; - private int _freeCount; - - private int _modBitMask; - - #region Properties - public TValue this[long keyX, long keyY] - { - get - { - //TODO Проверить необходимость проверки на Null - return _entries.ptr[FindEntry(keyX + (keyY << 32))].value; - } - set - { - Insert(keyX + (keyY << 32), value); - } - } - public TValue this[long key] - { - get - { - //TODO Проверить необходимость проверки на Null - return _entries.ptr[FindEntry(key)].value; - } - set - { - Insert(key, value); - } - } - - public int Count - { - get { return _count; } - } - #endregion - - #region Constructors - public SparseArray64(int minCapacity = MIN_CAPACITY) - { - minCapacity = NormalizeCapacity(minCapacity); - _buckets = new UnsafeArray(minCapacity); - for (int i = 0; i < minCapacity; i++) - { - _buckets[i] = EMPTY; - } - _entries = new UnsafeArray(minCapacity); - _modBitMask = (minCapacity - 1) & 0x7FFFFFFF; - } - #endregion - - #region Add - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Add(long keyX, long keyY, TValue value) => Add(keyX + (keyY << 32), value); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Add(long key, TValue value) - { -#if DEBUG - if (Contains(key)) - throw new ArgumentException("Contains(hashKey) is true"); -#endif - Insert(key, value); - } - #endregion - - #region Find/Insert/Remove - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private int FindEntry(long key) - { - for (int i = _buckets[unchecked((int)key & _modBitMask)]; i >= 0; i = _entries[i].next) - if (_entries[i].hashKey == key) return i; - return -1; - } - private void Insert(long key, TValue value) - { - int targetBucket = unchecked((int)key & _modBitMask); - - for (int i = _buckets[targetBucket]; i >= 0; i = _entries[i].next) - { - if (_entries[i].hashKey == key) - { - _entries[i].value = value; - return; - } - } - - int index; - if (_freeCount > 0) - { - index = _freeList; - _freeList = _entries[index].next; - _freeCount--; - } - else - { - if (_count == _entries.Length) - { - Resize(); - targetBucket = unchecked((int)key & _modBitMask); - } - index = _count++; - } - - _entries[index].next = _buckets[targetBucket]; - _entries[index].hashKey = key; - _entries[index].value = value; - _buckets[targetBucket] = index; - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Remove(long keyX, long keyY) => Remove(keyX + (keyY << 32)); - public bool Remove(long key) - { - int bucket = unchecked((int)key & _modBitMask); - int last = -1; - for (int i = _buckets[bucket]; i >= 0; last = i, i = _entries[i].next) - { - if (_entries[i].hashKey == key) - { - if (last < 0) - { - _buckets[bucket] = _entries[i].next; - } - else - { - _entries[last].next = _entries[i].next; - } - _entries[i].next = _freeList; - _entries[i].hashKey = -1; - _entries[i].value = default; - _freeList = i; - _freeCount++; - return true; - } - } - return false; - } - #endregion - - #region TryGetValue - public bool TryGetValue(long key, out TValue value) - { - int index = FindEntry(key); - if (index < 0) - { - value = default; - return false; - } - value = _entries.ptr[index].value; - return true; - } - public bool TryGetValue(long keyX, long keyY, out TValue value) - { - int index = FindEntry(keyX + (keyY << 32)); - if (index < 0) - { - value = default; - return false; - } - value = _entries.ptr[index].value; - return true; - } - #endregion - - #region Contains - public bool Contains(long keyX, long keyY) - { - return FindEntry(keyX + (keyY << 32)) >= 0; - } - public bool Contains(long key) - { - return FindEntry(key) >= 0; - } - #endregion - - #region Clear - public void Clear() - { - if (_count > 0) - { - for (int i = 0; i < _buckets.Length; i++) - { - _buckets[i] = -1; - } - for (int i = 0; i < _count; i++) - { - _entries[i] = default; - } - _count = 0; - } - } - #endregion - - #region Resize - private void Resize() - { - int newSize = _buckets.Length << 1; - _modBitMask = (newSize - 1) & 0x7FFFFFFF; - - Contract.Assert(newSize >= _entries.Length); - UnsafeArray newBuckets = new UnsafeArray(newSize); - for (int i = 0; i < newBuckets.Length; i++) - newBuckets[i] = EMPTY; - - UnsafeArray newEntries = UnsafeArray.Resize(_entries, newSize); - //UnsafeArray newEntries = new UnsafeArray(newSize); - //Array.Copy(_entries, 0, newEntries, 0, _count); - - - for (int i = 0; i < _count; i++) - { - if (newEntries[i].hashKey >= 0) - { - int bucket = unchecked((int)newEntries[i].hashKey & _modBitMask); - newEntries[i].next = newBuckets[bucket]; - newBuckets[bucket] = i; - } - } - _buckets = newBuckets; - _entries = newEntries; - } - - private int NormalizeCapacity(int capacity) - { - int result = MIN_CAPACITY; - while (result < capacity) result <<= 1; - return result; - } - #endregion - - #region Utils - [StructLayout(LayoutKind.Sequential, Pack = 4)] - [DebuggerDisplay("next{next} hashKey{hashKey} value{value}")] - private struct Entry - { - public int next; // Index of next entry, -1 if last - public long hashKey; - public TValue value; - } - #endregion - } -} \ No newline at end of file diff --git a/src/Utils/SparseArray64.cs.meta b/src/Utils/SparseArray64.cs.meta deleted file mode 100644 index fa70e8a..0000000 --- a/src/Utils/SparseArray64.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a5614297928ccbc479e9a0b7bd42df4b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: