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.
This commit is contained in:
2026-04-08 21:01:21 +09:00
parent b08662b77d
commit a108f39cbe
3 changed files with 15 additions and 17 deletions

View File

@@ -36,18 +36,18 @@ public unsafe struct UnsafeBitSet : IDisposable, IEquatable<UnsafeBitSet>
{
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<UnsafeBitSet>
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);
}
/// <summary>

View File

@@ -7,7 +7,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Misaki</Authors>
<AssemblyVersion>1.6.10</AssemblyVersion>
<AssemblyVersion>1.6.11</AssemblyVersion>
<Version>$(AssemblyVersion)</Version>
<PackageProjectUrl>https://git.personalnas.com/Misaki/Misaki.HighPerformance.git</PackageProjectUrl>
<RepositoryUrl>https://git.personalnas.com/Misaki/Misaki.HighPerformance.git</RepositoryUrl>

View File

@@ -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<SPMDBenchmark>();
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);
set.Dispose();
AllocationManager.Dispose();