Skip to content

Commit ed80950

Browse files
authored
⬇️ Downgrade System.Collections.Immutable (#382)
* 🤢 Replace ImmutableList with ImmutableArray * ⬇️ Downgrade System.Collections.Immutable * 💩 Missed two references
1 parent 39ac86a commit ed80950

6 files changed

Lines changed: 28 additions & 28 deletions

File tree

Bearded.Utilities.Tests/Algorithms/CoffmanGrahamTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void Solve_PutsChildrenInSeparateLayers()
133133

134134
var solution = solver.Solve(graph);
135135

136-
for (var i = 0; i < solution.Count; i++)
136+
for (var i = 0; i < solution.Length; i++)
137137
{
138138
solution[i].Should().ContainSingle().Which.Should().Be(i);
139139
}

Bearded.Utilities/Algorithms/CoffmanGraham.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static class CoffmanGraham
3737
{
3838
public interface ISolver
3939
{
40-
ImmutableList<ImmutableHashSet<T>> Solve<T>(IDirectedAcyclicGraph<T> graph)
40+
ImmutableArray<ImmutableHashSet<T>> Solve<T>(IDirectedAcyclicGraph<T> graph)
4141
where T : IEquatable<T>;
4242
}
4343

@@ -50,7 +50,7 @@ internal ArbitraryGraphSolver(int maxLayerSize)
5050
internalSolver = new ReducedGraphSolver(maxLayerSize);
5151
}
5252

53-
public ImmutableList<ImmutableHashSet<T>> Solve<T>(IDirectedAcyclicGraph<T> graph)
53+
public ImmutableArray<ImmutableHashSet<T>> Solve<T>(IDirectedAcyclicGraph<T> graph)
5454
where T : IEquatable<T>
5555
{
5656
var reducedGraph = DirectedAcyclicGraphTransitiveReducer<T>.ReduceGraph(graph);
@@ -67,10 +67,10 @@ internal ReducedGraphSolver(int maxLayerSize)
6767
this.maxLayerSize = maxLayerSize;
6868
}
6969

70-
public ImmutableList<ImmutableHashSet<T>> Solve<T>(IDirectedAcyclicGraph<T> graph)
70+
public ImmutableArray<ImmutableHashSet<T>> Solve<T>(IDirectedAcyclicGraph<T> graph)
7171
where T : IEquatable<T>
7272
{
73-
if (graph.Count == 0) return ImmutableList<ImmutableHashSet<T>>.Empty;
73+
if (graph.Count == 0) return ImmutableArray<ImmutableHashSet<T>>.Empty;
7474

7575
var ordering = createTopologicalOrdering(graph);
7676
return createLayers(graph, ordering, maxLayerSize);
@@ -125,7 +125,7 @@ DecreasingNumberSequence createDecreasingNumberSequenceOfPredecessorIndices(T e)
125125
}
126126
}
127127

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

172-
return ImmutableList.CreateRange(layersReversed.Select(b => b.ToImmutable()).Reverse());
172+
return ImmutableArray.CreateRange(layersReversed.Select(b => b.ToImmutable()).Reverse());
173173
}
174174
}
175175

Bearded.Utilities/Bearded.Utilities.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageReference Include="OpenTK.Mathematics" Version="4.8.2" />
1616
<PackageReference Include="OpenTK.Windowing.Desktop" Version="4.8.2" />
1717
<PackageReference Include="OpenTK.Windowing.GraphicsLibraryFramework" Version="4.8.2" />
18-
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
18+
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
1919
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
2020
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
2121
</ItemGroup>

Bearded.Utilities/Graphs/AdjacencyListDirectedAcyclicGraph.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ sealed class AdjacencyListDirectedAcyclicGraph<T> : AdjacencyListDirectedGraph<T
77
where T : IEquatable<T>
88
{
99
internal AdjacencyListDirectedAcyclicGraph(
10-
ImmutableList<T> elements,
11-
ImmutableDictionary<T, ImmutableList<T>> directSuccessors,
12-
ImmutableDictionary<T, ImmutableList<T>> directPredecessors)
10+
ImmutableArray<T> elements,
11+
ImmutableDictionary<T, ImmutableArray<T>> directSuccessors,
12+
ImmutableDictionary<T, ImmutableArray<T>> directPredecessors)
1313
: base(
1414
elements,
1515
directSuccessors,

Bearded.Utilities/Graphs/AdjacencyListDirectedGraph.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ namespace Bearded.Utilities.Graphs;
66

77
class AdjacencyListDirectedGraph<T> : IDirectedGraph<T> where T : IEquatable<T>
88
{
9-
private readonly ImmutableList<T> elements;
10-
private readonly ImmutableDictionary<T, ImmutableList<T>> directSuccessors;
11-
private readonly ImmutableDictionary<T, ImmutableList<T>> directPredecessors;
9+
private readonly ImmutableArray<T> elements;
10+
private readonly ImmutableDictionary<T, ImmutableArray<T>> directSuccessors;
11+
private readonly ImmutableDictionary<T, ImmutableArray<T>> directPredecessors;
1212

1313
public IEnumerable<T> Elements => elements;
14-
public int Count => elements.Count;
14+
public int Count => elements.Length;
1515

1616
internal AdjacencyListDirectedGraph(
17-
ImmutableList<T> elements,
18-
ImmutableDictionary<T, ImmutableList<T>> directSuccessors,
19-
ImmutableDictionary<T, ImmutableList<T>> directPredecessors)
17+
ImmutableArray<T> elements,
18+
ImmutableDictionary<T, ImmutableArray<T>> directSuccessors,
19+
ImmutableDictionary<T, ImmutableArray<T>> directPredecessors)
2020
{
2121
this.elements = elements;
2222
this.directSuccessors = directSuccessors;

Bearded.Utilities/Graphs/DirectedGraphBuilder.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace Bearded.Utilities.Graphs;
77

88
public sealed class DirectedGraphBuilder<T> where T : IEquatable<T>
99
{
10-
private readonly HashSet<T> elements = new HashSet<T>();
11-
private readonly HashSet<T> sources = new HashSet<T>();
12-
private readonly Dictionary<T, HashSet<T>> directSuccessors = new Dictionary<T, HashSet<T>>();
13-
private readonly Dictionary<T, HashSet<T>> directPredecessors = new Dictionary<T, HashSet<T>>();
10+
private readonly HashSet<T> elements = new();
11+
private readonly HashSet<T> sources = new();
12+
private readonly Dictionary<T, HashSet<T>> directSuccessors = new();
13+
private readonly Dictionary<T, HashSet<T>> directPredecessors = new();
1414

1515
public static DirectedGraphBuilder<T> NewBuilder()
1616
{
@@ -81,13 +81,13 @@ public DirectedGraphBuilder<T> AddArrow(T from, T to)
8181
public IDirectedGraph<T> CreateGraph()
8282
{
8383
return new AdjacencyListDirectedGraph<T>(
84-
ImmutableList.CreateRange(elements),
84+
ImmutableArray.CreateRange(elements),
8585
directSuccessors.ToImmutableDictionary(
8686
pair => pair.Key,
87-
pair => ImmutableList.CreateRange(pair.Value)),
87+
pair => ImmutableArray.CreateRange(pair.Value)),
8888
directPredecessors.ToImmutableDictionary(
8989
pair => pair.Key,
90-
pair => ImmutableList.CreateRange(pair.Value)));
90+
pair => ImmutableArray.CreateRange(pair.Value)));
9191
}
9292

9393
/// <summary>
@@ -139,12 +139,12 @@ bool leadsBackToCurrentPath(T element)
139139
public IDirectedAcyclicGraph<T> CreateAcyclicGraphUnsafe()
140140
{
141141
return new AdjacencyListDirectedAcyclicGraph<T>(
142-
ImmutableList.CreateRange(elements),
142+
ImmutableArray.CreateRange(elements),
143143
directSuccessors.ToImmutableDictionary(
144144
pair => pair.Key,
145-
pair => ImmutableList.CreateRange(pair.Value)),
145+
pair => ImmutableArray.CreateRange(pair.Value)),
146146
directPredecessors.ToImmutableDictionary(
147147
pair => pair.Key,
148-
pair => ImmutableList.CreateRange(pair.Value)));
148+
pair => ImmutableArray.CreateRange(pair.Value)));
149149
}
150150
}

0 commit comments

Comments
 (0)