Upgraded target framework to .NET 10 across all projects to leverage new features and improve performance. Refactored `JobScheduler` to fix method naming inconsistencies and ensure proper resource disposal. Enhanced `AllocationManager` with safer memory operations and better performance handling. Simplified `ReadOnlyUnsafeCollection` enumerator logic for efficiency. Overhauled `UnsafeBitSet` with new properties, improved bitwise operations, and optimized memory management. Updated `UnsafeSlotMap` and `ConcurrentSlotMap` for better validation and naming consistency. Revised `MemoryLeakException` to use `ReadOnlySpan` for improved performance. Simplified `MathematicsBenchmark` logic and integrated `BenchmarkDotNet` for testing. Added AOT compatibility settings for `Debug` and `Release` configurations. Introduced unit tests for `UnsafeBitSet` to validate functionality. Cleaned up unused code, improved readability, and ensured consistent naming conventions. Updated project references and metadata for consistency. Enabled inline methods for `NET10_0_OR_GREATER` in `VectorGenerator`.
112 lines
2.6 KiB
C#
112 lines
2.6 KiB
C#
using Misaki.HighPerformance.LowLevel.Buffer;
|
|
using Misaki.HighPerformance.LowLevel.Collections;
|
|
|
|
namespace Misaki.HighPerformance.Test.UnitTest.Collections;
|
|
|
|
[TestClass]
|
|
public class TestUnsafeSlotMap
|
|
{
|
|
private UnsafeSlotMap<int> _slotMap;
|
|
|
|
[TestInitialize]
|
|
public void Initialize()
|
|
{
|
|
_slotMap = new UnsafeSlotMap<int>(16, Allocator.Persistent);
|
|
}
|
|
|
|
[TestCleanup]
|
|
public void Cleanup()
|
|
{
|
|
_slotMap.Dispose();
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Add()
|
|
{
|
|
var id = _slotMap.Add(10, out var gen);
|
|
Assert.IsTrue(_slotMap.Contains(id, gen));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Remove()
|
|
{
|
|
var id = _slotMap.Add(20, out var gen);
|
|
Assert.IsTrue(_slotMap.Contains(id, gen));
|
|
|
|
_slotMap.Remove(id, gen);
|
|
Assert.IsFalse(_slotMap.Contains(id, gen));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void IndexReuse()
|
|
{
|
|
var id = _slotMap.Add(20, out var gen);
|
|
Assert.IsTrue(_slotMap.Contains(id, gen));
|
|
|
|
_slotMap.Remove(id, gen);
|
|
Assert.IsFalse(_slotMap.Contains(id, gen));
|
|
|
|
var newId = _slotMap.Add(30, out var newGen);
|
|
Assert.AreEqual(id, newId);
|
|
Assert.AreNotEqual(gen, newGen);
|
|
}
|
|
|
|
[TestMethod]
|
|
public unsafe void Resize()
|
|
{
|
|
const int count = 20;
|
|
|
|
var indices = stackalloc int[count];
|
|
var generations = stackalloc int[count];
|
|
|
|
for (var i = 0; i < count; i++)
|
|
{
|
|
indices[i] = _slotMap.Add(i, out generations[i]);
|
|
}
|
|
|
|
Assert.AreEqual(count, _slotMap.Count);
|
|
for (var i = 0; i < count; i++)
|
|
{
|
|
Assert.IsTrue(_slotMap.Contains(indices[i], generations[i]));
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Clear()
|
|
{
|
|
var id1 = _slotMap.Add(10, out var gen1);
|
|
var id2 = _slotMap.Add(20, out var gen2);
|
|
|
|
Assert.AreEqual(2, _slotMap.Count);
|
|
|
|
_slotMap.Clear();
|
|
|
|
Assert.AreEqual(0, _slotMap.Count);
|
|
Assert.IsFalse(_slotMap.Contains(id1, gen1));
|
|
Assert.IsFalse(_slotMap.Contains(id2, gen2));
|
|
}
|
|
|
|
[TestMethod]
|
|
public unsafe void Enumerate()
|
|
{
|
|
const int count = 3;
|
|
|
|
var values = stackalloc int[count] { 10, 20, 30 };
|
|
var ids = stackalloc int[count];
|
|
var gens = stackalloc int[count];
|
|
|
|
for (var i = 0; i < count; i++)
|
|
{
|
|
ids[i] = _slotMap.Add(values[i], out gens[i]);
|
|
}
|
|
|
|
var index = 0;
|
|
foreach (var value in _slotMap)
|
|
{
|
|
Assert.AreEqual(values[index], value);
|
|
index++;
|
|
}
|
|
|
|
Assert.AreEqual(count, index);
|
|
}
|
|
} |