Minor optimizations

This commit is contained in:
Asriel Camora
2023-06-21 05:58:08 -07:00
parent b7393b5c65
commit fc0ffc11f3
5 changed files with 7 additions and 68 deletions
+4 -5
View File
@@ -6,24 +6,23 @@ public class Arena<T> where T : struct
{
public readonly record struct Node
{
public int? Parent { get; init; }
public int Index { get; init; }
public List<int> Children { get; init; }
public T State { get; init; }
public List<int> Children { get; init; }
public int Parent { get; init; }
}
private readonly List<Node> nodes = new();
public Arena(T initialState = default)
{
nodes.Add(new() { Parent = null, Index = 0, Children = new(), State = initialState });
nodes.Add(new() { Parent = -1, Children = new(), State = initialState });
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int Insert(int parentIndex, T state)
{
var index = nodes.Count;
nodes.Add(new() { Parent = parentIndex, Index = index, Children = new(), State = state });
nodes.Add(new() { Parent = parentIndex, Children = new(), State = state });
nodes[parentIndex].Children.Add(index);
return index;
}