diff --git a/Algorithms.Tests/ModularArithmetic/ExtendedEuclideanAlgorithmTest.cs b/Algorithms.Tests/ModularArithmetic/ExtendedEuclideanAlgorithmTest.cs
index ea3e7792..83ab1caf 100644
--- a/Algorithms.Tests/ModularArithmetic/ExtendedEuclideanAlgorithmTest.cs
+++ b/Algorithms.Tests/ModularArithmetic/ExtendedEuclideanAlgorithmTest.cs
@@ -23,9 +23,9 @@ public static void TestCompute(long a, long b, long expectedGCD, long expectedBe
var eeaResult = ExtendedEuclideanAlgorithm.Compute(a, b);
// Assert
- Assert.That(eeaResult.gcd, Is.EqualTo(expectedGCD));
- Assert.That(eeaResult.bezoutA, Is.EqualTo(expectedBezoutOfA));
- Assert.That(eeaResult.bezoutB, Is.EqualTo(expectedBezoutOfB));
+ Assert.That(eeaResult.Gcd, Is.EqualTo(expectedGCD));
+ Assert.That(eeaResult.BezoutA, Is.EqualTo(expectedBezoutOfA));
+ Assert.That(eeaResult.BezoutB, Is.EqualTo(expectedBezoutOfB));
}
[TestCase(240, 46, 2, -9, 47)]
@@ -45,8 +45,8 @@ public static void TestCompute_BigInteger(long a, long b, long expectedGCD, long
var eeaResult = ExtendedEuclideanAlgorithm.Compute(new BigInteger(a), new BigInteger(b));
// Assert
- Assert.That(eeaResult.gcd, Is.EqualTo(new BigInteger(expectedGCD)));
- Assert.That(eeaResult.bezoutA, Is.EqualTo(new BigInteger(expectedBezoutOfA)));
- Assert.That(eeaResult.bezoutB, Is.EqualTo(new BigInteger(expectedBezoutOfB)));
+ Assert.That(eeaResult.Gcd, Is.EqualTo(new BigInteger(expectedGCD)));
+ Assert.That(eeaResult.BezoutA, Is.EqualTo(new BigInteger(expectedBezoutOfA)));
+ Assert.That(eeaResult.BezoutB, Is.EqualTo(new BigInteger(expectedBezoutOfB)));
}
}
diff --git a/Algorithms/Algorithms.csproj b/Algorithms/Algorithms.csproj
index 84283140..671d3e70 100644
--- a/Algorithms/Algorithms.csproj
+++ b/Algorithms/Algorithms.csproj
@@ -18,7 +18,7 @@
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/Algorithms/DataCompression/BurrowsWheelerTransform.cs b/Algorithms/DataCompression/BurrowsWheelerTransform.cs
index e84aab8d..6ec19387 100644
--- a/Algorithms/DataCompression/BurrowsWheelerTransform.cs
+++ b/Algorithms/DataCompression/BurrowsWheelerTransform.cs
@@ -16,7 +16,7 @@ public class BurrowsWheelerTransform
/// rotation matrix.
///
/// Input string.
- public (string encoded, int index) Encode(string s)
+ public (string Encoded, int Index) Encode(string s)
{
if (s.Length == 0)
{
diff --git a/Algorithms/DataCompression/HuffmanCompressor.cs b/Algorithms/DataCompression/HuffmanCompressor.cs
index a9d3f689..368f0704 100644
--- a/Algorithms/DataCompression/HuffmanCompressor.cs
+++ b/Algorithms/DataCompression/HuffmanCompressor.cs
@@ -27,7 +27,7 @@ public HuffmanCompressor(IComparisonSorter sorter, Translator translat
///
/// Text message to compress.
/// Compressed string and keys to decompress it.
- public (string compressedText, Dictionary decompressionKeys) Compress(string uncompressedText)
+ public (string CompressedText, Dictionary DecompressionKeys) Compress(string uncompressedText)
{
if (string.IsNullOrEmpty(uncompressedText))
{
@@ -70,7 +70,7 @@ private static ListNode[] GetListNodesFromText(string text)
return occurenceCounts.Select(kvp => new ListNode(kvp.Key, 1d * kvp.Value / text.Length)).ToArray();
}
- private (Dictionary compressionKeys, Dictionary decompressionKeys) GetKeys(
+ private (Dictionary CompressionKeys, Dictionary DecompressionKeys) GetKeys(
ListNode tree)
{
var compressionKeys = new Dictionary();
diff --git a/Algorithms/DataCompression/ShannonFanoCompressor.cs b/Algorithms/DataCompression/ShannonFanoCompressor.cs
index 6a48e7b4..3aba6761 100644
--- a/Algorithms/DataCompression/ShannonFanoCompressor.cs
+++ b/Algorithms/DataCompression/ShannonFanoCompressor.cs
@@ -10,11 +10,11 @@ namespace Algorithms.DataCompression;
///
public class ShannonFanoCompressor
{
- private readonly IHeuristicKnapsackSolver<(char symbol, double frequency)> splitter;
+ private readonly IHeuristicKnapsackSolver<(char Symbol, double Frequency)> splitter;
private readonly Translator translator;
public ShannonFanoCompressor(
- IHeuristicKnapsackSolver<(char symbol, double frequency)> splitter,
+ IHeuristicKnapsackSolver<(char Symbol, double Frequency)> splitter,
Translator translator)
{
this.splitter = splitter;
@@ -27,7 +27,7 @@ public ShannonFanoCompressor(
///
/// Text message to compress.
/// Compressed string and keys to decompress it.
- public (string compressedText, Dictionary decompressionKeys) Compress(string uncompressedText)
+ public (string CompressedText, Dictionary DecompressionKeys) Compress(string uncompressedText)
{
if (string.IsNullOrEmpty(uncompressedText))
{
@@ -49,7 +49,7 @@ public ShannonFanoCompressor(
return (translator.Translate(uncompressedText, compressionKeys), decompressionKeys);
}
- private (Dictionary compressionKeys, Dictionary decompressionKeys) GetKeys(
+ private (Dictionary CompressionKeys, Dictionary DecompressionKeys) GetKeys(
ListNode tree)
{
var compressionKeys = new Dictionary();
@@ -57,8 +57,8 @@ public ShannonFanoCompressor(
if (tree.Data.Length == 1)
{
- compressionKeys.Add(tree.Data[0].symbol.ToString(), string.Empty);
- decompressionKeys.Add(string.Empty, tree.Data[0].symbol.ToString());
+ compressionKeys.Add(tree.Data[0].Symbol.ToString(), string.Empty);
+ decompressionKeys.Add(string.Empty, tree.Data[0].Symbol.ToString());
return (compressionKeys, decompressionKeys);
}
@@ -86,7 +86,7 @@ private ListNode GenerateShannonFanoTree(ListNode node)
return node;
}
- var left = splitter.Solve(node.Data, 0.5 * node.Data.Sum(x => x.frequency), x => x.frequency, _ => 1);
+ var left = splitter.Solve(node.Data, 0.5 * node.Data.Sum(x => x.Frequency), x => x.Frequency, _ => 1);
var right = node.Data.Except(left).ToArray();
node.LeftChild = GenerateShannonFanoTree(new ListNode(left));
@@ -122,9 +122,9 @@ private ListNode GetListNodeFromText(string text)
///
public class ListNode
{
- public ListNode((char symbol, double frequency)[] data) => Data = data;
+ public ListNode((char Symbol, double Frequency)[] data) => Data = data;
- public (char symbol, double frequency)[] Data { get; }
+ public (char Symbol, double Frequency)[] Data { get; }
public ListNode? RightChild { get; set; }
diff --git a/Algorithms/Encoders/NysiisEncoder.cs b/Algorithms/Encoders/NysiisEncoder.cs
index a5e98747..10810af3 100644
--- a/Algorithms/Encoders/NysiisEncoder.cs
+++ b/Algorithms/Encoders/NysiisEncoder.cs
@@ -51,13 +51,13 @@ private string RemoveDuplicates(string text)
private string TrimEnd(string text)
{
- var checks = new (string from, string to)?[]
+ var checks = new (string From, string To)?[]
{
("S", string.Empty),
("AY", "Y"),
("A", string.Empty),
};
- var replacement = checks.FirstOrDefault(t => text.EndsWith(t!.Value.from));
+ var replacement = checks.FirstOrDefault(t => text.EndsWith(t!.Value.From));
if (replacement is { })
{
var (from, to) = replacement!.Value;
@@ -69,7 +69,7 @@ private string TrimEnd(string text)
private string ReplaceStep(string text, int i)
{
- (string from, string to)[] replacements =
+ (string From, string To)[] replacements =
{
("EV", "AF"),
("E", "A"),
@@ -134,7 +134,7 @@ private bool TryReplace(string text, int index, (string, string)[] opts, out str
private string StartReplace(string start)
{
- var checks = new (string from, string to)?[]
+ var checks = new (string From, string To)?[]
{
("MAC", "MCC"),
("KN", "NN"),
@@ -143,7 +143,7 @@ private string StartReplace(string start)
("PF", "FF"),
("SCH", "SSS"),
};
- var replacement = checks.FirstOrDefault(t => start.StartsWith(t!.Value.from));
+ var replacement = checks.FirstOrDefault(t => start.StartsWith(t!.Value.From));
if (replacement is { })
{
var (from, to) = replacement!.Value;
@@ -155,7 +155,7 @@ private string StartReplace(string start)
private string EndReplace(string end)
{
- var checks = new (string from, string to)?[]
+ var checks = new (string From, string To)?[]
{
("EE", "Y"),
("IE", "Y"),
@@ -164,7 +164,7 @@ private string EndReplace(string end)
("NT", "D"),
("ND", "D"),
};
- var replacement = checks.FirstOrDefault(t => end.EndsWith(t!.Value.from));
+ var replacement = checks.FirstOrDefault(t => end.EndsWith(t!.Value.From));
if (replacement is { })
{
var (from, to) = replacement!.Value;
@@ -175,5 +175,5 @@ private string EndReplace(string end)
}
private string Replace(string text, int index, int length, string substitute) =>
- text[..index] + substitute + text[(index + length) ..];
+ text[..index] + substitute + text[(index + length)..];
}
diff --git a/Algorithms/Graph/FloydWarshall.cs b/Algorithms/Graph/FloydWarshall.cs
index 7bb9d707..8c7fc466 100644
--- a/Algorithms/Graph/FloydWarshall.cs
+++ b/Algorithms/Graph/FloydWarshall.cs
@@ -49,7 +49,7 @@ public class FloydWarshall
{
for (var j = 0; j < distances.GetLength(0); j++)
{
- var dist = graph.AdjacentDistance(graph.Vertices[i] !, graph.Vertices[j] !);
+ var dist = graph.AdjacentDistance(graph.Vertices[i]!, graph.Vertices[j]!);
distances[i, j] = dist != 0 ? dist : double.PositiveInfinity;
}
}
diff --git a/Algorithms/LinearAlgebra/Eigenvalue/PowerIteration.cs b/Algorithms/LinearAlgebra/Eigenvalue/PowerIteration.cs
index 8e503992..df225723 100644
--- a/Algorithms/LinearAlgebra/Eigenvalue/PowerIteration.cs
+++ b/Algorithms/LinearAlgebra/Eigenvalue/PowerIteration.cs
@@ -27,7 +27,7 @@ public static class PowerIteration
/// Dominant eigenvalue and eigenvector pair.
/// The matrix is not square-shaped.
/// The length of the start vector doesn't equal the size of the source matrix.
- public static (double eigenvalue, double[] eigenvector) Dominant(
+ public static (double Eigenvalue, double[] Eigenvector) Dominant(
double[,] source,
double[] startVector,
double error = 0.00001)
@@ -61,7 +61,7 @@ public static (double eigenvalue, double[] eigenvector) Dominant(
var eigenvalue = source.Multiply(currentEigenVector.ToColumnVector()).ToRowVector().Magnitude();
- return (eigenvalue, eigenvector: currentEigenVector);
+ return (eigenvalue, Eigenvector: currentEigenVector);
}
///
@@ -81,6 +81,6 @@ public static (double eigenvalue, double[] eigenvector) Dominant(
/// Dominant eigenvalue and eigenvector pair.
/// The matrix is not square-shaped.
/// The length of the start vector doesn't equal the size of the source matrix.
- public static (double eigenvalue, double[] eigenvector) Dominant(double[,] source, double error = 0.00001) =>
+ public static (double Eigenvalue, double[] Eigenvector) Dominant(double[,] source, double error = 0.00001) =>
Dominant(source, new Random().NextVector(source.GetLength(1)), error);
}
diff --git a/Algorithms/ModularArithmetic/ChineseRemainderTheorem.cs b/Algorithms/ModularArithmetic/ChineseRemainderTheorem.cs
index 1eeaef76..9f7d88cb 100644
--- a/Algorithms/ModularArithmetic/ChineseRemainderTheorem.cs
+++ b/Algorithms/ModularArithmetic/ChineseRemainderTheorem.cs
@@ -49,7 +49,7 @@ public static long Compute(List listOfAs, List listOfNs)
var n_i = listOfNs[i];
var modulus_i = prodN / n_i;
- var bezout_modulus_i = ExtendedEuclideanAlgorithm.Compute(n_i, modulus_i).bezoutB;
+ var bezout_modulus_i = ExtendedEuclideanAlgorithm.Compute(n_i, modulus_i).BezoutB;
result += a_i * bezout_modulus_i * modulus_i;
}
@@ -102,7 +102,7 @@ public static BigInteger Compute(List listOfAs, List lis
var n_i = listOfNs[i];
var modulus_i = prodN / n_i;
- var bezout_modulus_i = ExtendedEuclideanAlgorithm.Compute(n_i, modulus_i).bezoutB;
+ var bezout_modulus_i = ExtendedEuclideanAlgorithm.Compute(n_i, modulus_i).BezoutB;
result += a_i * bezout_modulus_i * modulus_i;
}
@@ -145,7 +145,7 @@ private static void CheckRequirements(List listOfAs, List listOfNs)
for (var j = i + 1; j < listOfNs.Count; j++)
{
long gcd;
- if ((gcd = ExtendedEuclideanAlgorithm.Compute(listOfNs[i], listOfNs[j]).gcd) != 1L)
+ if ((gcd = ExtendedEuclideanAlgorithm.Compute(listOfNs[i], listOfNs[j]).Gcd) != 1L)
{
throw new ArgumentException($"The GCD of n_{i} = {listOfNs[i]} and n_{j} = {listOfNs[j]} equals {gcd} and thus these values aren't coprime.");
}
@@ -182,7 +182,7 @@ private static void CheckRequirements(List listOfAs, List
- /// Computes the greatest common divisor (gcd) of integers a and b, also the coefficients of Bézout's identity,
- /// which are integers x and y such that a*bezoutCoefficientOfA + b*bezoutCoefficientOfB = gcd(a, b).
+ /// Computes the greatest common divisor (Gcd) of integers a and b, also the coefficients of Bézout's identity,
+ /// which are integers x and y such that a*bezoutCoefficientOfA + b*bezoutCoefficientOfB = Gcd(a, b).
///
/// Input number.
/// Second input number.
- /// A record of ExtendedEuclideanAlgorithmResult containing the bezout coefficients of a and b as well as the gcd(a,b).
+ /// A record of ExtendedEuclideanAlgorithmResult containing the bezout coefficients of a and b as well as the Gcd(a,b).
public static ExtendedEuclideanAlgorithmResult Compute(long a, long b)
{
long quotient;
@@ -46,12 +46,12 @@ public static ExtendedEuclideanAlgorithmResult Compute(long a, long b)
}
///
- /// Computes the greatest common divisor (gcd) of integers a and b, also the coefficients of Bézout's identity,
- /// which are integers x and y such that a*bezoutCoefficientOfA + b*bezoutCoefficientOfB = gcd(a, b).
+ /// Computes the greatest common divisor (Gcd) of integers a and b, also the coefficients of Bézout's identity,
+ /// which are integers x and y such that a*bezoutCoefficientOfA + b*bezoutCoefficientOfB = Gcd(a, b).
///
/// Input number.
/// Second input number.
- /// A record of ExtendedEuclideanAlgorithmResult containing the bezout coefficients of a and b as well as the gcd(a,b).
+ /// A record of ExtendedEuclideanAlgorithmResult containing the bezout coefficients of a and b as well as the Gcd(a,b).
public static ExtendedEuclideanAlgorithmResult Compute(BigInteger a, BigInteger b)
{
BigInteger quotient;
@@ -87,8 +87,8 @@ public static ExtendedEuclideanAlgorithmResult Compute(BigInteger a,
/// The result type for the computation of the Extended Euclidean Algorithm.
///
/// The data type of the computation (i.e. long or BigInteger).
- /// The bezout coefficient of the parameter a to the computation.
- /// The bezout coefficient of the parameter b to the computation.
- /// The greatest common divisor of the parameters a and b to the computation.
- public record ExtendedEuclideanAlgorithmResult(T bezoutA, T bezoutB, T gcd);
+ /// The bezout coefficient of the parameter a to the computation.
+ /// The bezout coefficient of the parameter b to the computation.
+ /// The greatest common divisor of the parameters a and b to the computation.
+ public record ExtendedEuclideanAlgorithmResult(T BezoutA, T BezoutB, T Gcd);
}
diff --git a/Algorithms/ModularArithmetic/ModularMultiplicativeInverse.cs b/Algorithms/ModularArithmetic/ModularMultiplicativeInverse.cs
index 0e42cd68..9a3c5ce0 100644
--- a/Algorithms/ModularArithmetic/ModularMultiplicativeInverse.cs
+++ b/Algorithms/ModularArithmetic/ModularMultiplicativeInverse.cs
@@ -20,13 +20,13 @@ public static long Compute(long a, long n)
var eeaResult = ExtendedEuclideanAlgorithm.Compute(a, n);
// Check if there is an inverse:
- if (eeaResult.gcd != 1)
+ if (eeaResult.Gcd != 1)
{
throw new ArithmeticException($"{a} is not invertible in Z/{n}Z.");
}
// Make sure, inverseOfA (i.e. the bezout coefficient of a) is in the interval [0, n).
- var inverseOfA = eeaResult.bezoutA;
+ var inverseOfA = eeaResult.BezoutA;
if (inverseOfA < 0)
{
inverseOfA += n;
@@ -47,13 +47,13 @@ public static BigInteger Compute(BigInteger a, BigInteger n)
var eeaResult = ExtendedEuclideanAlgorithm.Compute(a, n);
// Check if there is an inverse:
- if (eeaResult.gcd != 1)
+ if (eeaResult.Gcd != 1)
{
throw new ArithmeticException($"{a} is not invertible in Z/{n}Z.");
}
// Make sure, inverseOfA (i.e. the bezout coefficient of a) is in the interval [0, n).
- var inverseOfA = eeaResult.bezoutA;
+ var inverseOfA = eeaResult.BezoutA;
if (inverseOfA < 0)
{
inverseOfA += n;
diff --git a/Algorithms/Other/FloodFill.cs b/Algorithms/Other/FloodFill.cs
index 22cc94e1..ac881d5f 100644
--- a/Algorithms/Other/FloodFill.cs
+++ b/Algorithms/Other/FloodFill.cs
@@ -14,7 +14,7 @@ namespace Algorithms.Other;
///
public static class FloodFill
{
- private static readonly List<(int xOffset, int yOffset)> Neighbors = new() { (-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1) };
+ private static readonly List<(int XOffset, int YOffset)> Neighbors = new() { (-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1) };
///
/// Implements the flood fill algorithm through a breadth-first approach using a queue.
@@ -23,14 +23,14 @@ public static class FloodFill
/// The start location on the bitmap.
/// The old color to be replaced.
/// The new color to replace the old one.
- public static void BreadthFirstSearch(SKBitmap bitmap, (int x, int y) location, SKColor targetColor, SKColor replacementColor)
+ public static void BreadthFirstSearch(SKBitmap bitmap, (int X, int Y) location, SKColor targetColor, SKColor replacementColor)
{
- if (location.x < 0 || location.x >= bitmap.Width || location.y < 0 || location.y >= bitmap.Height)
+ if (location.X < 0 || location.X >= bitmap.Width || location.Y < 0 || location.Y >= bitmap.Height)
{
throw new ArgumentOutOfRangeException(nameof(location), $"{nameof(location)} should point to a pixel within the bitmap");
}
- var queue = new List<(int x, int y)>();
+ var queue = new List<(int X, int Y)>();
queue.Add(location);
while (queue.Count > 0)
@@ -46,9 +46,9 @@ public static void BreadthFirstSearch(SKBitmap bitmap, (int x, int y) location,
/// The start location on the bitmap.
/// The old color to be replaced.
/// The new color to replace the old one.
- public static void DepthFirstSearch(SKBitmap bitmap, (int x, int y) location, SKColor targetColor, SKColor replacementColor)
+ public static void DepthFirstSearch(SKBitmap bitmap, (int X, int Y) location, SKColor targetColor, SKColor replacementColor)
{
- if (location.x < 0 || location.x >= bitmap.Width || location.y < 0 || location.y >= bitmap.Height)
+ if (location.X < 0 || location.X >= bitmap.Width || location.Y < 0 || location.Y >= bitmap.Height)
{
throw new ArgumentOutOfRangeException(nameof(location), $"{nameof(location)} should point to a pixel within the bitmap");
}
@@ -56,19 +56,19 @@ public static void DepthFirstSearch(SKBitmap bitmap, (int x, int y) location, SK
DepthFirstFill(bitmap, location, targetColor, replacementColor);
}
- private static void BreadthFirstFill(SKBitmap bitmap, (int x, int y) location, SKColor targetColor, SKColor replacementColor, List<(int x, int y)> queue)
+ private static void BreadthFirstFill(SKBitmap bitmap, (int X, int Y) location, SKColor targetColor, SKColor replacementColor, List<(int X, int Y)> queue)
{
- (int x, int y) currentLocation = queue[0];
+ (int X, int Y) currentLocation = queue[0];
queue.RemoveAt(0);
- if (bitmap.GetPixel(currentLocation.x, currentLocation.y) == targetColor)
+ if (bitmap.GetPixel(currentLocation.X, currentLocation.Y) == targetColor)
{
- bitmap.SetPixel(currentLocation.x, currentLocation.y, replacementColor);
+ bitmap.SetPixel(currentLocation.X, currentLocation.Y, replacementColor);
for (int i = 0; i < Neighbors.Count; i++)
{
- int x = currentLocation.x + Neighbors[i].xOffset;
- int y = currentLocation.y + Neighbors[i].yOffset;
+ int x = currentLocation.X + Neighbors[i].XOffset;
+ int y = currentLocation.Y + Neighbors[i].YOffset;
if (x >= 0 && x < bitmap.Width && y >= 0 && y < bitmap.Height)
{
queue.Add((x, y));
@@ -77,16 +77,16 @@ private static void BreadthFirstFill(SKBitmap bitmap, (int x, int y) location, S
}
}
- private static void DepthFirstFill(SKBitmap bitmap, (int x, int y) location, SKColor targetColor, SKColor replacementColor)
+ private static void DepthFirstFill(SKBitmap bitmap, (int X, int Y) location, SKColor targetColor, SKColor replacementColor)
{
- if (bitmap.GetPixel(location.x, location.y) == targetColor)
+ if (bitmap.GetPixel(location.X, location.Y) == targetColor)
{
- bitmap.SetPixel(location.x, location.y, replacementColor);
+ bitmap.SetPixel(location.X, location.Y, replacementColor);
for (int i = 0; i < Neighbors.Count; i++)
{
- int x = location.x + Neighbors[i].xOffset;
- int y = location.y + Neighbors[i].yOffset;
+ int x = location.X + Neighbors[i].XOffset;
+ int y = location.Y + Neighbors[i].YOffset;
if (x >= 0 && x < bitmap.Width && y >= 0 && y < bitmap.Height)
{
DepthFirstFill(bitmap, (x, y), targetColor, replacementColor);
diff --git a/Algorithms/Other/GaussOptimization.cs b/Algorithms/Other/GaussOptimization.cs
index 3387a1e1..a8c50fdb 100644
--- a/Algorithms/Other/GaussOptimization.cs
+++ b/Algorithms/Other/GaussOptimization.cs
@@ -24,7 +24,7 @@ public class GaussOptimization
/// The first function parameter.
/// The second function parameter.
/// A tuple of coordinates of function extremum.
- public (double, double) Optimize(
+ public (double X1, double X2) Optimize(
Func func,
double n,
double step,
diff --git a/Algorithms/Other/RGBHSVConversion.cs b/Algorithms/Other/RGBHSVConversion.cs
index ecad76d3..9e1f2f97 100644
--- a/Algorithms/Other/RGBHSVConversion.cs
+++ b/Algorithms/Other/RGBHSVConversion.cs
@@ -22,7 +22,7 @@ public static class RgbHsvConversion
/// Saturation of the color.
/// Brightness-value of the color.
/// The tuple of RGB-components.
- public static (byte red, byte green, byte blue) HsvToRgb(
+ public static (byte Red, byte Green, byte Blue) HsvToRgb(
double hue,
double saturation,
double value)
@@ -59,7 +59,7 @@ public static (byte red, byte green, byte blue) HsvToRgb(
/// Green-component of the color.
/// Blue-component of the color.
/// The tuple of HSV-components.
- public static (double hue, double saturation, double value) RgbToHsv(
+ public static (double Hue, double Saturation, double Value) RgbToHsv(
byte red,
byte green,
byte blue)
@@ -94,7 +94,7 @@ public static (double hue, double saturation, double value) RgbToHsv(
return (hue, saturation, value);
}
- private static (byte red, byte green, byte blue) GetRgbBySection(
+ private static (byte Red, byte Green, byte Blue) GetRgbBySection(
double hueSection,
double chroma,
double matchValue,
diff --git a/Algorithms/Search/FastSearcher.cs b/Algorithms/Search/FastSearcher.cs
index b11989df..42b2cf3a 100644
--- a/Algorithms/Search/FastSearcher.cs
+++ b/Algorithms/Search/FastSearcher.cs
@@ -44,7 +44,7 @@ public int FindIndex(Span array, int item)
return from + FindIndex(array.Slice(from, to - from + 1), item);
}
- private (int left, int right) ComputeIndices(Span array, int item)
+ private (int Left, int Right) ComputeIndices(Span array, int item)
{
var indexBinary = array.Length / 2;
@@ -62,7 +62,7 @@ public int FindIndex(Span array, int item)
: (indexInterpolation, indexBinary);
}
- private (int from, int to) SelectSegment(Span array, int left, int right, int item)
+ private (int From, int To) SelectSegment(Span array, int left, int right, int item)
{
if (item < array[left])
{
diff --git a/Algorithms/Sorters/Comparison/MergeSorter.cs b/Algorithms/Sorters/Comparison/MergeSorter.cs
index b86af4b6..13a888ad 100644
--- a/Algorithms/Sorters/Comparison/MergeSorter.cs
+++ b/Algorithms/Sorters/Comparison/MergeSorter.cs
@@ -57,7 +57,7 @@ private static void Merge(T[] array, T[] left, T[] right, IComparer comparer)
}
}
- private static (T[] left, T[] right) Split(T[] array)
+ private static (T[] Left, T[] Right) Split(T[] array)
{
var mid = array.Length / 2;
return (array.Take(mid).ToArray(), array.Skip(mid).ToArray());
diff --git a/Algorithms/Sorters/Comparison/TimSorter.cs b/Algorithms/Sorters/Comparison/TimSorter.cs
index 0115e560..d098d340 100755
--- a/Algorithms/Sorters/Comparison/TimSorter.cs
+++ b/Algorithms/Sorters/Comparison/TimSorter.cs
@@ -9,18 +9,18 @@ namespace Algorithms.Sorters.Comparison;
/// It was originally implemented by Tim Peters in 2002 for use in the Python programming language.
///
/// This class is based on a Java interpretation of Tim Peter's original work.
-/// Java class is viewable here:
+/// Java class is viewable here:
/// http://cr.openjdk.java.net/~martin/webrevs/openjdk7/timsort/raw_files/new/src/share/classes/java/util/TimSort.java
///
-/// Tim Peters's list sort for Python, is described in detail here:
-/// http://svn.python.org/projects/python/trunk/Objects/listsort.txt
+/// Tim Peters's list sort for Python, is described in detail here:
+/// http://svn.python.org/projects/python/trunk/Objects/listsort.txt
///
/// Tim's C code may be found here: http://svn.python.org/projects/python/trunk/Objects/listobject.c
///
-/// The underlying techniques are described in this paper (and may have even earlier origins):
-/// "Optimistic Sorting and Information Theoretic Complexity"
-/// Peter McIlroy
-/// SODA (Fourth Annual ACM-SIAM Symposium on Discrete Algorithms),
+/// The underlying techniques are described in this paper (and may have even earlier origins):
+/// "Optimistic Sorting and Information Theoretic Complexity"
+/// Peter McIlroy
+/// SODA (Fourth Annual ACM-SIAM Symposium on Discrete Algorithms),
/// pp 467-474, Austin, Texas, 25-27 January 1993.
///
/// Type of array element.
@@ -34,31 +34,31 @@ public class TimSorter : IComparisonSorter
private readonly int[] runBase;
private readonly int[] runLengths;
-
+
private int minGallop;
private int stackSize;
private IComparer comparer = default!;
- ///
- /// Private class for handling gallop merges, allows for tracking array indexes and wins.
- ///
- /// Type of array element.
- private class TimChunk
- {
- public Tc[] Array { get; set; } = default!;
-
- public int Index { get; set; }
-
- public int Remaining { get; set; }
-
- public int Wins { get; set; }
+ ///
+ /// Private class for handling gallop merges, allows for tracking array indexes and wins.
+ ///
+ /// Type of array element.
+ private class TimChunk
+ {
+ public Tc[] Array { get; set; } = default!;
+
+ public int Index { get; set; }
+
+ public int Remaining { get; set; }
+
+ public int Wins { get; set; }
}
public TimSorter(TimSorterSettings settings, IComparer comparer)
{
initMinGallop = minGallop;
- runBase = new int[85];
+ runBase = new int[85];
runLengths = new int[85];
stackSize = 0;
@@ -149,21 +149,21 @@ private static int MinRunLength(int total, int minRun)
return total + r;
}
- ///
- /// Reverse the specified range of the specified array.
- ///
- /// the array in which a range is to be reversed.
- /// the index of the first element in the range to be reversed.
- /// the index after the last element in the range to be reversed.
- private static void ReverseRange(T[] array, int start, int end)
- {
- end--;
- while (start < end)
- {
- var t = array[start];
- array[start++] = array[end];
- array[end--] = t;
- }
+ ///
+ /// Reverse the specified range of the specified array.
+ ///
+ /// the array in which a range is to be reversed.
+ /// the index of the first element in the range to be reversed.
+ /// the index after the last element in the range to be reversed.
+ private static void ReverseRange(T[] array, int start, int end)
+ {
+ end--;
+ while (start < end)
+ {
+ var t = array[start];
+ array[start++] = array[end];
+ array[end--] = t;
+ }
}
///
@@ -175,18 +175,18 @@ private static void ReverseRange(T[] array, int start, int end)
/// If a merge is required.
private static bool NeedsMerge(TimChunk left, TimChunk right, ref int dest)
{
- right.Array[dest++] = right.Array[right.Index++];
+ right.Array[dest++] = right.Array[right.Index++];
if (--right.Remaining == 0)
- {
- Array.Copy(left.Array, left.Index, right.Array, dest, left.Remaining);
- return false;
+ {
+ Array.Copy(left.Array, left.Index, right.Array, dest, left.Remaining);
+ return false;
}
-
+
if (left.Remaining == 1)
- {
- Array.Copy(right.Array, right.Index, right.Array, dest, right.Remaining);
- right.Array[dest + right.Remaining] = left.Array[left.Index];
- return false;
+ {
+ Array.Copy(right.Array, right.Index, right.Array, dest, right.Remaining);
+ right.Array[dest + right.Remaining] = left.Array[left.Index];
+ return false;
}
return true;
@@ -201,71 +201,71 @@ private static bool NeedsMerge(TimChunk left, TimChunk right, ref int dest
private static void FinalizeMerge(TimChunk left, TimChunk right, int dest)
{
if (left.Remaining == 1)
- {
- Array.Copy(right.Array, right.Index, right.Array, dest, right.Remaining);
- right.Array[dest + right.Remaining] = left.Array[left.Index];
+ {
+ Array.Copy(right.Array, right.Index, right.Array, dest, right.Remaining);
+ right.Array[dest + right.Remaining] = left.Array[left.Index];
}
else if (left.Remaining == 0)
- {
- throw new ArgumentException("Comparison method violates its general contract!");
+ {
+ throw new ArgumentException("Comparison method violates its general contract!");
}
else
- {
- Array.Copy(left.Array, left.Index, right.Array, dest, left.Remaining);
+ {
+ Array.Copy(left.Array, left.Index, right.Array, dest, left.Remaining);
}
}
- ///
- /// Returns the length of the run beginning at the specified position in
- /// the specified array and reverses the run if it is descending (ensuring
- /// that the run will always be ascending when the method returns).
+ ///
+ /// Returns the length of the run beginning at the specified position in
+ /// the specified array and reverses the run if it is descending (ensuring
+ /// that the run will always be ascending when the method returns).
///
- /// A run is the longest ascending sequence with:
+ /// A run is the longest ascending sequence with:
///
- ///
+ ///
///
- /// or the longest descending sequence with:
+ /// or the longest descending sequence with:
///
- /// a[lo + 1] > a[lo + 2] > ...]]>
+ /// a[lo + 1] > a[lo + 2] > ...]]>
///
- /// For its intended use in a stable mergesort, the strictness of the
- /// definition of "descending" is needed so that the call can safely
- /// reverse a descending sequence without violating stability.
- ///
- /// the array in which a run is to be counted and possibly reversed.
- /// index of the first element in the run.
- /// the length of the run beginning at the specified position in the specified array.
+ /// For its intended use in a stable mergesort, the strictness of the
+ /// definition of "descending" is needed so that the call can safely
+ /// reverse a descending sequence without violating stability.
+ ///
+ /// the array in which a run is to be counted and possibly reversed.
+ /// index of the first element in the run.
+ /// the length of the run beginning at the specified position in the specified array.
private int CountRunAndMakeAscending(T[] array, int start)
- {
- var runHi = start + 1;
+ {
+ var runHi = start + 1;
if (runHi == array.Length)
- {
+ {
return 1;
- }
-
- // Find end of run, and reverse range if descending
+ }
+
+ // Find end of run, and reverse range if descending
if (comparer.Compare(array[runHi++], array[start]) < 0)
- { // Descending
+ { // Descending
while (runHi < array.Length && comparer.Compare(array[runHi], array[runHi - 1]) < 0)
- {
+ {
runHi++;
}
-
+
ReverseRange(array, start, runHi);
}
else
- { // Ascending
+ { // Ascending
while (runHi < array.Length && comparer.Compare(array[runHi], array[runHi - 1]) >= 0)
- {
+ {
runHi++;
- }
- }
-
- return runHi - start;
+ }
+ }
+
+ return runHi - start;
}
///
- /// Sorts the specified portion of the specified array using a binary
+ /// Sorts the specified portion of the specified array using a binary
/// insertion sort. It requires O(n log n) compares, but O(n^2) data movement.
///
/// Array to sort.
@@ -334,25 +334,25 @@ private void MergeCollapse(T[] array)
}
}
- private void MergeForceCollapse(T[] array)
- {
- while (stackSize > 1)
- {
- var n = stackSize - 2;
+ private void MergeForceCollapse(T[] array)
+ {
+ while (stackSize > 1)
+ {
+ var n = stackSize - 2;
if (n > 0 && runLengths[n - 1] < runLengths[n + 1])
{
n--;
}
-
- MergeAt(array, n);
- }
+
+ MergeAt(array, n);
+ }
}
private void MergeAt(T[] array, int index)
{
- var baseA = runBase[index];
- var lenA = runLengths[index];
- var baseB = runBase[index + 1];
+ var baseA = runBase[index];
+ var lenA = runLengths[index];
+ var baseB = runBase[index + 1];
var lenB = runLengths[index + 1];
runLengths[index] = lenA + lenB;
@@ -386,45 +386,45 @@ private void MergeAt(T[] array, int index)
}
private void Merge(T[] array, int baseA, int lenA, int baseB, int lenB)
- {
- var endA = baseA + lenA;
+ {
+ var endA = baseA + lenA;
var dest = baseA;
- TimChunk left = new()
- {
- Array = array[baseA..endA],
- Remaining = lenA,
- };
-
- TimChunk right = new()
- {
- Array = array,
- Index = baseB,
- Remaining = lenB,
- };
-
- // Move first element of the right chunk and deal with degenerate cases.
+ TimChunk left = new()
+ {
+ Array = array[baseA..endA],
+ Remaining = lenA,
+ };
+
+ TimChunk right = new()
+ {
+ Array = array,
+ Index = baseB,
+ Remaining = lenB,
+ };
+
+ // Move first element of the right chunk and deal with degenerate cases.
if (!TimSorter.NeedsMerge(left, right, ref dest))
{
// One of the chunks had 0-1 items in it, so no need to merge anything.
return;
}
-
+
var gallop = minGallop;
-
+
while (RunMerge(left, right, ref dest, ref gallop))
{
// Penalize for leaving gallop mode
gallop = gallop > 0
? gallop + 2
- : 2;
+ : 2;
}
minGallop = gallop >= 1
? gallop
- : 1;
-
- FinalizeMerge(left, right, dest);
+ : 1;
+
+ FinalizeMerge(left, right, dest);
}
private bool RunMerge(TimChunk left, TimChunk right, ref int dest, ref int gallop)
@@ -531,16 +531,3 @@ private bool GallopMerge(TimChunk left, TimChunk right, ref int dest)
return false;
}
}
-
-public class TimSorterSettings
-{
- public int MinMerge { get; }
-
- public int MinGallop { get; }
-
- public TimSorterSettings(int minMerge = 32, int minGallop = 7)
- {
- MinMerge = minMerge;
- MinGallop = minGallop;
- }
-}
diff --git a/Algorithms/Sorters/Comparison/TimSorterSettings.cs b/Algorithms/Sorters/Comparison/TimSorterSettings.cs
new file mode 100644
index 00000000..0f804fbd
--- /dev/null
+++ b/Algorithms/Sorters/Comparison/TimSorterSettings.cs
@@ -0,0 +1,14 @@
+namespace Algorithms.Sorters.Comparison;
+
+public class TimSorterSettings
+{
+ public int MinMerge { get; }
+
+ public int MinGallop { get; }
+
+ public TimSorterSettings(int minMerge = 32, int minGallop = 7)
+ {
+ MinMerge = minMerge;
+ MinGallop = minGallop;
+ }
+}
diff --git a/Algorithms/Sorters/Utils/GallopingStrategy.cs b/Algorithms/Sorters/Utils/GallopingStrategy.cs
index 2226064b..4c4ddc02 100644
--- a/Algorithms/Sorters/Utils/GallopingStrategy.cs
+++ b/Algorithms/Sorters/Utils/GallopingStrategy.cs
@@ -40,7 +40,7 @@ public static int BoundLeftShift(int shiftable) => (shiftable << 1) < 0
? (shiftable << 1) + 1
: int.MaxValue;
- private static (int offset, int lastOfs) LeftRun(T[] array, T key, int baseIndex, int hint, IComparer comparer)
+ private static (int Offset, int LastOfs) LeftRun(T[] array, T key, int baseIndex, int hint, IComparer comparer)
{
var maxOfs = hint + 1;
var (offset, tmp) = (1, 0);
@@ -62,7 +62,7 @@ private static (int offset, int lastOfs) LeftRun(T[] array, T key, int baseIndex
return (offset, lastOfs);
}
- private static (int offset, int lastOfs) RightRun(T[] array, T key, int baseIndex, int len, int hint, IComparer comparer)
+ private static (int Offset, int LastOfs) RightRun(T[] array, T key, int baseIndex, int len, int hint, IComparer comparer)
{
var (offset, lastOfs) = (1, 0);
var maxOfs = len - hint;
diff --git a/Algorithms/Strings/Similarity/CosineSimilarity.cs b/Algorithms/Strings/Similarity/CosineSimilarity.cs
index d05ee8c9..2975f793 100644
--- a/Algorithms/Strings/Similarity/CosineSimilarity.cs
+++ b/Algorithms/Strings/Similarity/CosineSimilarity.cs
@@ -21,8 +21,8 @@ public static double Calculate(string left, string right)
// Step 1: Get the vectors for the two strings
// Each vector represents the frequency of each character in the string.
var vectors = GetVectors(left.ToLowerInvariant(), right.ToLowerInvariant());
- var leftVector = vectors.leftVector;
- var rightVector = vectors.rightVector;
+ var leftVector = vectors.LeftVector;
+ var rightVector = vectors.RightVector;
// Step 2: Calculate the intersection of the two vectors
// The intersection is the set of characters that appear in both strings.
@@ -64,7 +64,7 @@ public static double Calculate(string left, string right)
/// The first string.
/// The second string.
/// A tuple containing the vectors for the two strings.
- private static (Dictionary leftVector, Dictionary rightVector) GetVectors(string left, string right)
+ private static (Dictionary LeftVector, Dictionary RightVector) GetVectors(string left, string right)
{
var leftVector = new Dictionary();
var rightVector = new Dictionary();
diff --git a/Algorithms/Strings/Similarity/DamerauLevenshteinDistance.cs b/Algorithms/Strings/Similarity/DamerauLevenshteinDistance.cs
index a00bdae6..4d699658 100644
--- a/Algorithms/Strings/Similarity/DamerauLevenshteinDistance.cs
+++ b/Algorithms/Strings/Similarity/DamerauLevenshteinDistance.cs
@@ -36,7 +36,7 @@ public static int Calculate(string left, string right)
// Calculate the minimum distance by considering three possible operations:
// deletion, insertion, and substitution.
distances[i, j] = Math.Min(
- Math.Min( // deletion
+ Math.Min(// deletion
distances[i - 1, j] + 1, // delete the character from the left string
distances[i, j - 1] + 1), // insert the character into the right string
distances[i - 1, j - 1] + cost); // substitute the character in the left string with the character in the right string
diff --git a/DataStructures/AATree/AATree.cs b/DataStructures/AATree/AATree.cs
index f4322cbf..c2f2eeae 100644
--- a/DataStructures/AATree/AATree.cs
+++ b/DataStructures/AATree/AATree.cs
@@ -216,7 +216,7 @@ private AaTreeNode Add(TKey key, AaTreeNode? node)
throw new ArgumentException($"Key \"{key}\" already in tree!", nameof(key));
}
- return Split(Skew(node)) !;
+ return Split(Skew(node))!;
}
///
diff --git a/DataStructures/DataStructures.csproj b/DataStructures/DataStructures.csproj
index 06f645a3..445adbf9 100644
--- a/DataStructures/DataStructures.csproj
+++ b/DataStructures/DataStructures.csproj
@@ -16,7 +16,7 @@
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/DataStructures/Graph/DirectedWeightedGraph.cs b/DataStructures/Graph/DirectedWeightedGraph.cs
index 15e0a336..666b9e48 100644
--- a/DataStructures/Graph/DirectedWeightedGraph.cs
+++ b/DataStructures/Graph/DirectedWeightedGraph.cs
@@ -94,7 +94,7 @@ public void RemoveVertex(Vertex vertex)
for (int i = indexToRemove; i < Count - 1; i++)
{
Vertices[i] = Vertices[i + 1];
- Vertices[i] !.Index = i;
+ Vertices[i]!.Index = i;
}
Vertices[Count - 1] = null;
diff --git a/DataStructures/Hashing/HashTable.cs b/DataStructures/Hashing/HashTable.cs
index 05dde26a..8f6aac78 100644
--- a/DataStructures/Hashing/HashTable.cs
+++ b/DataStructures/Hashing/HashTable.cs
@@ -150,7 +150,7 @@ public void Add(TKey? key, TValue? value)
var index = GetIndex(key);
if (
entries[index] != null &&
- EqualityComparer.Default.Equals(entries[index] !.Key!, key))
+ EqualityComparer.Default.Equals(entries[index]!.Key!, key))
{
throw new ArgumentException("Key already exists");
}
diff --git a/DataStructures/RedBlackTree/RedBlackTreeNode.cs b/DataStructures/RedBlackTree/RedBlackTreeNode.cs
index 5c888b38..91f42df0 100644
--- a/DataStructures/RedBlackTree/RedBlackTreeNode.cs
+++ b/DataStructures/RedBlackTree/RedBlackTreeNode.cs
@@ -6,12 +6,12 @@ namespace DataStructures.RedBlackTree;
public enum NodeColor : byte
{
///
- /// Represents red node
+ /// Represents red node.
///
Red,
///
- /// Represents black node
+ /// Represents black node.
///
Black,
}
diff --git a/DataStructures/ScapegoatTree/ScapegoatTree.cs b/DataStructures/ScapegoatTree/ScapegoatTree.cs
index a5262152..8f0a1b55 100644
--- a/DataStructures/ScapegoatTree/ScapegoatTree.cs
+++ b/DataStructures/ScapegoatTree/ScapegoatTree.cs
@@ -247,7 +247,7 @@ public void Tune(double value)
/// Scapegoat node with its parent node. Parent can be null if scapegoat node is root node.
/// Thrown if path stack is empty.
/// Thrown if scapegoat wasn't found.
- public (Node? parent, Node scapegoat) FindScapegoatInPath(Stack> path)
+ public (Node? Parent, Node Scapegoat) FindScapegoatInPath(Stack> path)
{
if (path.Count == 0)
{
diff --git a/Utilities/Extensions/DictionaryExtensions.cs b/Utilities/Extensions/DictionaryExtensions.cs
index 03638290..3d040554 100644
--- a/Utilities/Extensions/DictionaryExtensions.cs
+++ b/Utilities/Extensions/DictionaryExtensions.cs
@@ -17,7 +17,7 @@ public static class DictionaryExtensions
///
public static void AddMany(
this Dictionary keys,
- IEnumerable<(TKey, TValue)> enumerable) where TKey : notnull
+ IEnumerable<(TKey Key, TValue Value)> enumerable) where TKey : notnull
{
foreach (var (key, value) in enumerable)
{
diff --git a/Utilities/Utilities.csproj b/Utilities/Utilities.csproj
index 8c289a07..01944c82 100644
--- a/Utilities/Utilities.csproj
+++ b/Utilities/Utilities.csproj
@@ -16,7 +16,7 @@
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive