Reserve index 0 in SlotMap, improve unsafe collections
- Reserve index 0 as always invalid in SlotMap, ConcurrentSlotMap, UnsafeSlotMap, and UnsafeSparseSet; update all index checks and slot operations accordingly - Refactor SlotMap to use parallel arrays and BitArray for occupancy - Double capacity on resize for all major unsafe collections - Add debugger display support for unsafe collections - Improve NuGet publishing workflow to skip existing versions - Increment package versions (LowLevel: 1.3.1, main: 1.0.2) - Add comprehensive unit tests for SlotMap and ConcurrentSlotMap - Update main program and documentation for new slot map behavior
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using Misaki.HighPerformance.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Misaki.HighPerformance.Test.UnitTest.Collections;
|
||||
|
||||
[TestClass]
|
||||
public class TestSlotMap
|
||||
{
|
||||
private SlotMap<int> _slotMap = null!;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_slotMap = new SlotMap<int>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestDefaultIndex()
|
||||
{
|
||||
Assert.IsFalse(_slotMap.Contains(0, 0));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestAddAndContains()
|
||||
{
|
||||
var slotIndex = _slotMap.Add(42, out var generation);
|
||||
Assert.IsTrue(_slotMap.Contains(slotIndex, generation));
|
||||
Assert.AreEqual(42, _slotMap.GetElementAt(slotIndex, generation));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestRemove()
|
||||
{
|
||||
var slotIndex = _slotMap.Add(100, out var generation);
|
||||
Assert.IsTrue(_slotMap.Contains(slotIndex, generation));
|
||||
var removed = _slotMap.Remove(slotIndex, generation);
|
||||
Assert.IsTrue(removed);
|
||||
Assert.IsFalse(_slotMap.Contains(slotIndex, generation));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestRemoveInvalid()
|
||||
{
|
||||
var slotIndex = _slotMap.Add(200, out var generation);
|
||||
Assert.IsTrue(_slotMap.Contains(slotIndex, generation));
|
||||
var removed = _slotMap.Remove(slotIndex, generation + 1); // Wrong generation
|
||||
Assert.IsFalse(removed);
|
||||
Assert.IsTrue(_slotMap.Contains(slotIndex, generation));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestIndexReuse()
|
||||
{
|
||||
var slotIndex1 = _slotMap.Add(300, out var generation1);
|
||||
_slotMap.Remove(slotIndex1, generation1);
|
||||
var slotIndex2 = _slotMap.Add(400, out var generation2);
|
||||
Assert.AreEqual(slotIndex1, slotIndex2);
|
||||
Assert.AreNotEqual(generation1, generation2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user