Skip to content

Commit

Permalink
Merge pull request #23 from naminodarie/feature/optimize
Browse files Browse the repository at this point in the history
Use SimpleList
  • Loading branch information
kzrnm authored Jan 10, 2021
2 parents 6d7c29e + 70645e9 commit 948a245
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Source/AtCoderLibrary/Graph/Internal/CSR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CSR<TEdge>
/// </summary>
public readonly TEdge[] EList;

public CSR(int n, List<(int from, TEdge e)> edges)
public CSR(int n, ICollection<(int from, TEdge e)> edges)
{
// 本家 C++ 版 ACL を参考に実装。通常の隣接リストと比較して高速か否かは未検証。
Start = new int[n + 1];
Expand Down
4 changes: 2 additions & 2 deletions Source/AtCoderLibrary/Graph/MaxFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public MFGraph(int n)
{
_g[i] = new SimpleList<EdgeInternal>();
}
_pos = new List<(int first, int second)>();
_pos = new SimpleList<(int first, int second)>();
}

/// <summary>
Expand Down Expand Up @@ -375,7 +375,7 @@ public EdgeInternal(int to, int rev, TValue cap)
};

internal readonly int _n;
internal readonly List<(int first, int second)> _pos;
internal readonly SimpleList<(int first, int second)> _pos;
internal readonly SimpleList<EdgeInternal>[] _g;
}
}
16 changes: 8 additions & 8 deletions Source/AtCoderLibrary/Graph/MinCostFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public Edge GetEdge(int i)
{
var degree = new int[_n];
var redgeIdx = new int[m];
var elist = new List<(int from, EdgeInternal edge)>(2 * m);
var elist = new SimpleList<(int from, EdgeInternal edge)>(2 * m);

for (int i = 0; i < m; i++)
{
Expand Down Expand Up @@ -382,7 +382,7 @@ bool DualRef()
for (int v = t; v != s; v = g.EList[prevE[v]].To)
{
var e = g.EList[prevE[v]];
e.Cap = capOp.Add(e.Cap, c);
g.EList[prevE[v]].Cap = capOp.Add(e.Cap, c);
g.EList[e.Rev].Cap = capOp.Subtract(g.EList[e.Rev].Cap, c);
}
var d = costOp.Minus(dual[s]);
Expand Down Expand Up @@ -434,12 +434,12 @@ public bool Equals(Edge other) => From == other.From &&

};

private class EdgeInternal
private struct EdgeInternal
{
public int To { get; set; }
public int Rev { get; set; }
public TCap Cap { get; set; }
public TCost Cost { get; set; }
public int To;
public int Rev;
public TCap Cap;
public TCost Cost;
public EdgeInternal(int to, int rev, TCap cap, TCost cost)
{
To = to;
Expand All @@ -450,7 +450,7 @@ public EdgeInternal(int to, int rev, TCap cap, TCost cost)
};

private readonly int _n;
private readonly List<Edge> _edges = new List<Edge>();
private readonly SimpleList<Edge> _edges = new SimpleList<Edge>();

private class PriorityQueueForMcf
{
Expand Down
4 changes: 2 additions & 2 deletions Source/AtCoderLibrary/Graph/SCCGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace Internal
public class SCCGraph
{
private readonly int _n;
private readonly List<(int from, Edge e)> edges;
private readonly SimpleList<(int from, Edge e)> edges;

public int VerticesNumbers => _n;

Expand All @@ -76,7 +76,7 @@ public class SCCGraph
public SCCGraph(int n)
{
_n = n;
edges = new List<(int from, Edge e)>();
edges = new SimpleList<(int from, Edge e)>();
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Source/AtCoderLibrary/String/StringLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public static int[] SAIS(ReadOnlyMemory<int> sm, int upper, int thresholdNaive,
}
}

var lms = new List<int>(m);
var lms = new SimpleList<int>(m);
for (int i = 1; i < ls.Length; i++)
{
if (!ls[i - 1] && ls[i])
Expand All @@ -377,7 +377,7 @@ public static int[] SAIS(ReadOnlyMemory<int> sm, int upper, int thresholdNaive,
// LMSを再帰的にソート
if (m > 0)
{
var sortedLms = new List<int>(m);
var sortedLms = new SimpleList<int>(m);
foreach (var v in sa)
{
if (lmsMap[v] != -1)
Expand Down Expand Up @@ -441,7 +441,7 @@ public static int[] SAIS(ReadOnlyMemory<int> sm, int upper, int thresholdNaive,

return sa;

void Induce(List<int> lms)
void Induce(SimpleList<int> lms)
{
var s = sm.Span;
sa.AsSpan().Fill(-1);
Expand Down

0 comments on commit 948a245

Please sign in to comment.