From a108f39cbeadb8f6b2c538e68996b26266d90592 Mon Sep 17 00:00:00 2001 From: Misaki Date: Wed, 8 Apr 2026 21:01:21 +0900 Subject: [PATCH] feat(UnsafeBitSet): refactor iterator to use pointer Refactored UnsafeBitSet.Iterator to store a pointer to the bitset and accept a start index in its constructor. Updated GetIterator to support an optional start parameter and return an iterator using a pointer to the current instance. Revised Program.cs to demonstrate new usage and removed unrelated code. Bumped assembly version to 1.6.11. --- .../Collections/UnsafeBitSet.cs | 12 ++++++------ .../Misaki.HighPerformance.LowLevel.csproj | 2 +- Misaki.HighPerformance.Test/Program.cs | 18 ++++++++---------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Misaki.HighPerformance.LowLevel/Collections/UnsafeBitSet.cs b/Misaki.HighPerformance.LowLevel/Collections/UnsafeBitSet.cs index 7757e6d..2c8a63b 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/UnsafeBitSet.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/UnsafeBitSet.cs @@ -36,18 +36,18 @@ public unsafe struct UnsafeBitSet : IDisposable, IEquatable { public ref struct Iterator { - private UnsafeBitSet _bitSet; + private readonly UnsafeBitSet* _bitSet; private int _currentBit; - public Iterator(UnsafeBitSet bitSet) + public Iterator(UnsafeBitSet* bitSet, int start) { _bitSet = bitSet; - _currentBit = -1; + _currentBit = start - 1; } public bool Next(out int bitIndex) { - _currentBit = _bitSet.NextSetBit(_currentBit + 1); + _currentBit = _bitSet->NextSetBit(_currentBit + 1); bitIndex = _currentBit; return _currentBit != -1; } @@ -143,9 +143,9 @@ public unsafe struct UnsafeBitSet : IDisposable, IEquatable return (id >> _INDEX_SIZE) + int.Sign(id & _BIT_SIZE); } - public readonly Iterator GetIterator() + public readonly Iterator GetIterator(int start = 0) { - return new Iterator(this); + return new Iterator((UnsafeBitSet*)Unsafe.AsPointer(in this), start); } /// diff --git a/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj b/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj index b71d5ac..d10e4b7 100644 --- a/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj +++ b/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj @@ -7,7 +7,7 @@ true true Misaki - 1.6.10 + 1.6.11 $(AssemblyVersion) https://git.personalnas.com/Misaki/Misaki.HighPerformance.git https://git.personalnas.com/Misaki/Misaki.HighPerformance.git diff --git a/Misaki.HighPerformance.Test/Program.cs b/Misaki.HighPerformance.Test/Program.cs index 94d2b3b..8b481a9 100644 --- a/Misaki.HighPerformance.Test/Program.cs +++ b/Misaki.HighPerformance.Test/Program.cs @@ -1,14 +1,12 @@ -using BenchmarkDotNet.Running; -using Misaki.HighPerformance.Mathematics; -using Misaki.HighPerformance.Test.Benchmark; +using Misaki.HighPerformance.LowLevel.Buffer; +using Misaki.HighPerformance.LowLevel.Collections; //BenchmarkRunner.Run(); -var faceDirection = math.normalize(float3.zero - new float3(0.0f, 0.0f, 5.0f)); -var test = quaternion.LookRotation(faceDirection, math.up()); -var test2 = quaternion.LookRotationSafe(faceDirection, math.up()); -var rotation = quaternion.EulerXYZ(new float3(0, math.radians(180.0f), 0)); +AllocationManager.Initialize(AllocationManagerInitOpts.Default); +var set = new UnsafeBitSet(100, Allocator.Persistent, AllocationOption.Clear); +set.SetBit(0); +Console.WriteLine(set.NextSetBit(0)); -Console.WriteLine(test); -Console.WriteLine(test2); -Console.WriteLine(rotation); \ No newline at end of file +set.Dispose(); +AllocationManager.Dispose();