Skip to content

Commit

Permalink
🤢 Replace ImmutableList with ImmutableArray
Browse files Browse the repository at this point in the history
  • Loading branch information
tomrijnbeek committed Mar 11, 2024
1 parent 39ac86a commit 0cdca05
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions Bearded.Utilities/Algorithms/CoffmanGraham.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static class CoffmanGraham
{
public interface ISolver
{
ImmutableList<ImmutableHashSet<T>> Solve<T>(IDirectedAcyclicGraph<T> graph)
ImmutableArray<ImmutableHashSet<T>> Solve<T>(IDirectedAcyclicGraph<T> graph)
where T : IEquatable<T>;
}

Expand All @@ -50,7 +50,7 @@ internal ArbitraryGraphSolver(int maxLayerSize)
internalSolver = new ReducedGraphSolver(maxLayerSize);
}

public ImmutableList<ImmutableHashSet<T>> Solve<T>(IDirectedAcyclicGraph<T> graph)
public ImmutableArray<ImmutableHashSet<T>> Solve<T>(IDirectedAcyclicGraph<T> graph)
where T : IEquatable<T>
{
var reducedGraph = DirectedAcyclicGraphTransitiveReducer<T>.ReduceGraph(graph);
Expand All @@ -67,10 +67,10 @@ internal ReducedGraphSolver(int maxLayerSize)
this.maxLayerSize = maxLayerSize;
}

public ImmutableList<ImmutableHashSet<T>> Solve<T>(IDirectedAcyclicGraph<T> graph)
public ImmutableArray<ImmutableHashSet<T>> Solve<T>(IDirectedAcyclicGraph<T> graph)
where T : IEquatable<T>
{
if (graph.Count == 0) return ImmutableList<ImmutableHashSet<T>>.Empty;
if (graph.Count == 0) return ImmutableArray<ImmutableHashSet<T>>.Empty;

var ordering = createTopologicalOrdering(graph);
return createLayers(graph, ordering, maxLayerSize);
Expand Down Expand Up @@ -125,7 +125,7 @@ DecreasingNumberSequence createDecreasingNumberSequenceOfPredecessorIndices(T e)
}
}

private static ImmutableList<ImmutableHashSet<T>> createLayers<T>(
private static ImmutableArray<ImmutableHashSet<T>> createLayers<T>(
// ReSharper disable once SuggestBaseTypeForParameter
IDirectedAcyclicGraph<T> graph, IList<T> ordering, int maxLayerSize)
where T : IEquatable<T>
Expand Down Expand Up @@ -169,7 +169,7 @@ private static ImmutableList<ImmutableHashSet<T>> createLayers<T>(
elementToLayer.Add(ordering[i], candidateLayer);
}

return ImmutableList.CreateRange(layersReversed.Select(b => b.ToImmutable()).Reverse());
return ImmutableArray.CreateRange(layersReversed.Select(b => b.ToImmutable()).Reverse());
}
}

Expand Down
6 changes: 3 additions & 3 deletions Bearded.Utilities/Graphs/AdjacencyListDirectedAcyclicGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ sealed class AdjacencyListDirectedAcyclicGraph<T> : AdjacencyListDirectedGraph<T
where T : IEquatable<T>
{
internal AdjacencyListDirectedAcyclicGraph(
ImmutableList<T> elements,
ImmutableDictionary<T, ImmutableList<T>> directSuccessors,
ImmutableDictionary<T, ImmutableList<T>> directPredecessors)
ImmutableArray<T> elements,
ImmutableDictionary<T, ImmutableArray<T>> directSuccessors,
ImmutableDictionary<T, ImmutableArray<T>> directPredecessors)
: base(
elements,
directSuccessors,
Expand Down
14 changes: 7 additions & 7 deletions Bearded.Utilities/Graphs/AdjacencyListDirectedGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ namespace Bearded.Utilities.Graphs;

class AdjacencyListDirectedGraph<T> : IDirectedGraph<T> where T : IEquatable<T>
{
private readonly ImmutableList<T> elements;
private readonly ImmutableDictionary<T, ImmutableList<T>> directSuccessors;
private readonly ImmutableDictionary<T, ImmutableList<T>> directPredecessors;
private readonly ImmutableArray<T> elements;
private readonly ImmutableDictionary<T, ImmutableArray<T>> directSuccessors;
private readonly ImmutableDictionary<T, ImmutableArray<T>> directPredecessors;

public IEnumerable<T> Elements => elements;
public int Count => elements.Count;
public int Count => elements.Length;

internal AdjacencyListDirectedGraph(
ImmutableList<T> elements,
ImmutableDictionary<T, ImmutableList<T>> directSuccessors,
ImmutableDictionary<T, ImmutableList<T>> directPredecessors)
ImmutableArray<T> elements,
ImmutableDictionary<T, ImmutableArray<T>> directSuccessors,
ImmutableDictionary<T, ImmutableArray<T>> directPredecessors)
{
this.elements = elements;
this.directSuccessors = directSuccessors;
Expand Down
6 changes: 3 additions & 3 deletions Bearded.Utilities/Graphs/DirectedGraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ public DirectedGraphBuilder<T> AddArrow(T from, T to)
public IDirectedGraph<T> CreateGraph()
{
return new AdjacencyListDirectedGraph<T>(
ImmutableList.CreateRange(elements),
ImmutableArray.CreateRange(elements),
directSuccessors.ToImmutableDictionary(
pair => pair.Key,
pair => ImmutableList.CreateRange(pair.Value)),
pair => ImmutableArray.CreateRange(pair.Value)),
directPredecessors.ToImmutableDictionary(
pair => pair.Key,
pair => ImmutableList.CreateRange(pair.Value)));
pair => ImmutableArray.CreateRange(pair.Value)));
}

/// <summary>
Expand Down

0 comments on commit 0cdca05

Please sign in to comment.