Skip to content

Commit

Permalink
⬇️ Downgrade System.Collections.Immutable (#382)
Browse files Browse the repository at this point in the history
* 🤢 Replace ImmutableList with ImmutableArray

* ⬇️ Downgrade System.Collections.Immutable

* 💩 Missed two references
  • Loading branch information
tomrijnbeek authored Mar 11, 2024
1 parent 39ac86a commit ed80950
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Bearded.Utilities.Tests/Algorithms/CoffmanGrahamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void Solve_PutsChildrenInSeparateLayers()

var solution = solver.Solve(graph);

for (var i = 0; i < solution.Count; i++)
for (var i = 0; i < solution.Length; i++)
{
solution[i].Should().ContainSingle().Which.Should().Be(i);
}
Expand Down
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
2 changes: 1 addition & 1 deletion Bearded.Utilities/Bearded.Utilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageReference Include="OpenTK.Mathematics" Version="4.8.2" />
<PackageReference Include="OpenTK.Windowing.Desktop" Version="4.8.2" />
<PackageReference Include="OpenTK.Windowing.GraphicsLibraryFramework" Version="4.8.2" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
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
20 changes: 10 additions & 10 deletions Bearded.Utilities/Graphs/DirectedGraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Bearded.Utilities.Graphs;

public sealed class DirectedGraphBuilder<T> where T : IEquatable<T>
{
private readonly HashSet<T> elements = new HashSet<T>();
private readonly HashSet<T> sources = new HashSet<T>();
private readonly Dictionary<T, HashSet<T>> directSuccessors = new Dictionary<T, HashSet<T>>();
private readonly Dictionary<T, HashSet<T>> directPredecessors = new Dictionary<T, HashSet<T>>();
private readonly HashSet<T> elements = new();
private readonly HashSet<T> sources = new();
private readonly Dictionary<T, HashSet<T>> directSuccessors = new();
private readonly Dictionary<T, HashSet<T>> directPredecessors = new();

public static DirectedGraphBuilder<T> NewBuilder()
{
Expand Down 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 Expand Up @@ -139,12 +139,12 @@ bool leadsBackToCurrentPath(T element)
public IDirectedAcyclicGraph<T> CreateAcyclicGraphUnsafe()
{
return new AdjacencyListDirectedAcyclicGraph<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)));
}
}

0 comments on commit ed80950

Please sign in to comment.