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:
@@ -2,15 +2,43 @@ using Misaki.HighPerformance.LowLevel.Buffer;
|
||||
using Misaki.HighPerformance.LowLevel.Collections.Contracts;
|
||||
using Misaki.HighPerformance.LowLevel.Utilities;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Misaki.HighPerformance.LowLevel.Collections;
|
||||
|
||||
internal class UnsafeStackDebugView<T>
|
||||
where T : unmanaged
|
||||
{
|
||||
private readonly UnsafeStack<T> _stack;
|
||||
public UnsafeStackDebugView(UnsafeStack<T> stack)
|
||||
{
|
||||
_stack = stack;
|
||||
}
|
||||
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
|
||||
public unsafe T[] Items
|
||||
{
|
||||
get
|
||||
{
|
||||
var items = new T[_stack.Count];
|
||||
var pItems = (T*)_stack.GetUnsafePtr();
|
||||
for (int i = 0; i < _stack.Count; i++)
|
||||
{
|
||||
items[i] = pItems[i];
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides a high-performance, unsafe stack data structure for unmanaged types, supporting manual memory management
|
||||
/// and allocation control.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of elements stored in the stack. Must be an unmanaged type.</typeparam>
|
||||
[DebuggerTypeProxy(typeof(UnsafeStackDebugView<>))]
|
||||
public unsafe struct UnsafeStack<T> : IUnsafeCollection<T>
|
||||
where T : unmanaged
|
||||
{
|
||||
@@ -96,7 +124,7 @@ public unsafe struct UnsafeStack<T> : IUnsafeCollection<T>
|
||||
{
|
||||
if (_count >= Capacity)
|
||||
{
|
||||
Resize((int)(Capacity * 1.5f));
|
||||
Resize(Math.Max(1, Capacity * 2));
|
||||
}
|
||||
|
||||
UnsafeUtility.WriteArrayElement(_array.GetUnsafePtr(), _count, value);
|
||||
|
||||
Reference in New Issue
Block a user