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:
@@ -36,18 +36,18 @@ public unsafe struct UnsafeBitSet : IDisposable, IEquatable<UnsafeBitSet>
|
|||||||
{
|
{
|
||||||
public ref struct Iterator
|
public ref struct Iterator
|
||||||
{
|
{
|
||||||
private UnsafeBitSet _bitSet;
|
private readonly UnsafeBitSet* _bitSet;
|
||||||
private int _currentBit;
|
private int _currentBit;
|
||||||
|
|
||||||
public Iterator(UnsafeBitSet bitSet)
|
public Iterator(UnsafeBitSet* bitSet, int start)
|
||||||
{
|
{
|
||||||
_bitSet = bitSet;
|
_bitSet = bitSet;
|
||||||
_currentBit = -1;
|
_currentBit = start - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Next(out int bitIndex)
|
public bool Next(out int bitIndex)
|
||||||
{
|
{
|
||||||
_currentBit = _bitSet.NextSetBit(_currentBit + 1);
|
_currentBit = _bitSet->NextSetBit(_currentBit + 1);
|
||||||
bitIndex = _currentBit;
|
bitIndex = _currentBit;
|
||||||
return _currentBit != -1;
|
return _currentBit != -1;
|
||||||
}
|
}
|
||||||
@@ -143,9 +143,9 @@ public unsafe struct UnsafeBitSet : IDisposable, IEquatable<UnsafeBitSet>
|
|||||||
return (id >> _INDEX_SIZE) + int.Sign(id & _BIT_SIZE);
|
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>
|
/// <summary>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Authors>Misaki</Authors>
|
<Authors>Misaki</Authors>
|
||||||
<AssemblyVersion>1.6.10</AssemblyVersion>
|
<AssemblyVersion>1.6.11</AssemblyVersion>
|
||||||
<Version>$(AssemblyVersion)</Version>
|
<Version>$(AssemblyVersion)</Version>
|
||||||
<PackageProjectUrl>https://git.personalnas.com/Misaki/Misaki.HighPerformance.git</PackageProjectUrl>
|
<PackageProjectUrl>https://git.personalnas.com/Misaki/Misaki.HighPerformance.git</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://git.personalnas.com/Misaki/Misaki.HighPerformance.git</RepositoryUrl>
|
<RepositoryUrl>https://git.personalnas.com/Misaki/Misaki.HighPerformance.git</RepositoryUrl>
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
using BenchmarkDotNet.Running;
|
using Misaki.HighPerformance.LowLevel.Buffer;
|
||||||
using Misaki.HighPerformance.Mathematics;
|
using Misaki.HighPerformance.LowLevel.Collections;
|
||||||
using Misaki.HighPerformance.Test.Benchmark;
|
|
||||||
|
|
||||||
//BenchmarkRunner.Run<SPMDBenchmark>();
|
//BenchmarkRunner.Run<SPMDBenchmark>();
|
||||||
|
|
||||||
var faceDirection = math.normalize(float3.zero - new float3(0.0f, 0.0f, 5.0f));
|
AllocationManager.Initialize(AllocationManagerInitOpts.Default);
|
||||||
var test = quaternion.LookRotation(faceDirection, math.up());
|
var set = new UnsafeBitSet(100, Allocator.Persistent, AllocationOption.Clear);
|
||||||
var test2 = quaternion.LookRotationSafe(faceDirection, math.up());
|
set.SetBit(0);
|
||||||
var rotation = quaternion.EulerXYZ(new float3(0, math.radians(180.0f), 0));
|
Console.WriteLine(set.NextSetBit(0));
|
||||||
|
|
||||||
Console.WriteLine(test);
|
set.Dispose();
|
||||||
Console.WriteLine(test2);
|
AllocationManager.Dispose();
|
||||||
Console.WriteLine(rotation);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user