Merge solver code with static interface

- Breaks backwards compat solver code with last version. Concurrent broke backwards compat because of race conditions with rng, but single is now broken too, despite it being 2x faster (!!!!)
- Literally twice as fast as Rust now in single thread
- Concurrent doesn't work yet, deadlocks somewhere..?
This commit is contained in:
Asriel Camora
2023-07-07 09:58:47 +02:00
parent 2894867195
commit d5a8288439
9 changed files with 332 additions and 145 deletions
+24 -3
View File
@@ -20,17 +20,17 @@ public sealed class ArenaNode<T> where T : struct
private static int BatchCount = MaxSize / BatchSize;
public ArenaNode<T>[][] Data;
private int index;
private int index; // Unused in single threaded workload
private int count;
public readonly int Count => count;
public void Add(ArenaNode<T> node)
public void AddConcurrent(ArenaNode<T> node)
{
if (Data == null)
Interlocked.CompareExchange(ref Data, new ArenaNode<T>[BatchCount][], null);
var idx = Interlocked.Increment(ref this.index) - 1;
var idx = Interlocked.Increment(ref index) - 1;
var (arrayIdx, subIdx) = GetArrayIndex(idx);
@@ -42,6 +42,19 @@ public sealed class ArenaNode<T> where T : struct
Interlocked.Increment(ref count);
}
public void Add(ArenaNode<T> node)
{
Data ??= new ArenaNode<T>[BatchCount][];
var idx = count++;
var (arrayIdx, subIdx) = GetArrayIndex(idx);
Data[arrayIdx] ??= new ArenaNode<T>[BatchSize];
Data[arrayIdx][subIdx] = node;
}
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static (int arrayIdx, int subIdx) GetArrayIndex(int idx) =>
@@ -59,6 +72,14 @@ public sealed class ArenaNode<T> where T : struct
Parent = parent;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ArenaNode<T> AddConcurrent(T state)
{
var node = new ArenaNode<T>(state, this);
Children.AddConcurrent(node);
return node;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ArenaNode<T> Add(T state)
{