Skip to content

Commit 06cfd5e

Browse files
committed
Cleanup of indentation. Visual Studio Document Formatting.
1 parent 10cad49 commit 06cfd5e

29 files changed

+641
-628
lines changed

Algorithms/Common/Comparers.cs

+36-36
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Algorithms.Common
44
{
5-
public static class Comparers
6-
{
5+
public static class Comparers
6+
{
77
/// <summary>
88
/// Determines if a specific value is a number.
99
/// </summary>
@@ -27,44 +27,44 @@ public static bool IsNumber<T>(this T value)
2727
}
2828

2929

30-
/// <summary>
31-
/// Determines if firstValue is equals to the specified secondValue.
32-
/// </summary>
33-
/// <returns><c>true</c> if firstValue is equals to the specified secondValue; otherwise, <c>false</c>.</returns>
34-
/// <param name="firstValue">The first value.</param>
35-
/// <param name="secondValue">The second value.</param>
36-
/// <typeparam name="T">The Type of values.</typeparam>
37-
public static bool IsEqualTo<T>(this T firstValue, T secondValue) where T : IComparable<T>
38-
{
39-
return firstValue.Equals (secondValue);
40-
}
30+
/// <summary>
31+
/// Determines if firstValue is equals to the specified secondValue.
32+
/// </summary>
33+
/// <returns><c>true</c> if firstValue is equals to the specified secondValue; otherwise, <c>false</c>.</returns>
34+
/// <param name="firstValue">The first value.</param>
35+
/// <param name="secondValue">The second value.</param>
36+
/// <typeparam name="T">The Type of values.</typeparam>
37+
public static bool IsEqualTo<T>(this T firstValue, T secondValue) where T : IComparable<T>
38+
{
39+
return firstValue.Equals(secondValue);
40+
}
4141

4242

43-
/// <summary>
44-
/// Determines if thisValue is greater than the specified otherValue.
45-
/// </summary>
46-
/// <returns><c>true</c> if thisValue is greater than the specified otherValue; otherwise, <c>false</c>.</returns>
47-
/// <param name="firstValue">The first value.</param>
48-
/// <param name="secondValue">The second value.</param>
49-
/// <typeparam name="T">The Type of values.</typeparam>
50-
public static bool IsGreaterThan<T>(this T firstValue, T secondValue) where T : IComparable<T>
51-
{
52-
return firstValue.CompareTo (secondValue) > 0;
53-
}
43+
/// <summary>
44+
/// Determines if thisValue is greater than the specified otherValue.
45+
/// </summary>
46+
/// <returns><c>true</c> if thisValue is greater than the specified otherValue; otherwise, <c>false</c>.</returns>
47+
/// <param name="firstValue">The first value.</param>
48+
/// <param name="secondValue">The second value.</param>
49+
/// <typeparam name="T">The Type of values.</typeparam>
50+
public static bool IsGreaterThan<T>(this T firstValue, T secondValue) where T : IComparable<T>
51+
{
52+
return firstValue.CompareTo(secondValue) > 0;
53+
}
5454

5555

56-
/// <summary>
57-
/// Determines if thisValue is less than the specified otherValue.
58-
/// </summary>
59-
/// <returns><c>true</c> if thisValue is less than the specified otherValue; otherwise, <c>false</c>.</returns>
60-
/// <param name="firstValue">The first value.</param>
61-
/// <param name="secondValue">The second value.</param>
62-
/// <typeparam name="T">The Type of values.</typeparam>
63-
public static bool IsLessThan<T>(this T firstValue, T secondValue) where T : IComparable<T>
64-
{
65-
return firstValue.CompareTo (secondValue) < 0;
66-
}
56+
/// <summary>
57+
/// Determines if thisValue is less than the specified otherValue.
58+
/// </summary>
59+
/// <returns><c>true</c> if thisValue is less than the specified otherValue; otherwise, <c>false</c>.</returns>
60+
/// <param name="firstValue">The first value.</param>
61+
/// <param name="secondValue">The second value.</param>
62+
/// <typeparam name="T">The Type of values.</typeparam>
63+
public static bool IsLessThan<T>(this T firstValue, T secondValue) where T : IComparable<T>
64+
{
65+
return firstValue.CompareTo(secondValue) < 0;
66+
}
6767

68-
}
68+
}
6969

7070
}

Algorithms/Common/Helpers.cs

+21-21
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@
55

66
namespace Algorithms.Common
77
{
8-
public static class Helpers
9-
{
10-
/// <summary>
8+
public static class Helpers
9+
{
10+
/// <summary>
1111
/// Swaps two values in an IList<T> collection given their indexes.
12-
/// </summary>
13-
public static void Swap<T>(this IList<T> list, int firstIndex, int secondIndex)
14-
{
15-
if (list.Count < 2 || firstIndex == secondIndex) //This check is not required but Partition function may make many calls so its for perf reason
16-
return;
12+
/// </summary>
13+
public static void Swap<T>(this IList<T> list, int firstIndex, int secondIndex)
14+
{
15+
if (list.Count < 2 || firstIndex == secondIndex) //This check is not required but Partition function may make many calls so its for perf reason
16+
return;
1717

18-
var temp = list[firstIndex];
19-
list[firstIndex] = list[secondIndex];
20-
list[secondIndex] = temp;
21-
}
18+
var temp = list[firstIndex];
19+
list[firstIndex] = list[secondIndex];
20+
list[secondIndex] = temp;
21+
}
2222

2323
/// <summary>
2424
/// Swaps two values in an ArrayList<T> collection given their indexes.
2525
/// </summary>
26-
public static void Swap<T>(this ArrayList<T> list, int firstIndex, int secondIndex)
27-
{
28-
if (list.Count < 2 || firstIndex == secondIndex) //This check is not required but Partition function may make many calls so its for perf reason
29-
return;
26+
public static void Swap<T>(this ArrayList<T> list, int firstIndex, int secondIndex)
27+
{
28+
if (list.Count < 2 || firstIndex == secondIndex) //This check is not required but Partition function may make many calls so its for perf reason
29+
return;
3030

31-
var temp = list[firstIndex];
32-
list[firstIndex] = list[secondIndex];
33-
list[secondIndex] = temp;
34-
}
31+
var temp = list[firstIndex];
32+
list[firstIndex] = list[secondIndex];
33+
list[secondIndex] = temp;
34+
}
3535

3636
/// <summary>
3737
/// Populates a collection with a specific value.
@@ -46,6 +46,6 @@ public static void Populate<T>(this IList<T> collection, T value)
4646
collection[i] = value;
4747
}
4848
}
49-
}
49+
}
5050
}
5151

Algorithms/Graphs/CyclesDetector.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static class CyclesDetector
2929
/// <returns>True if there is a cycle; otherwise, false.</returns>
3030
private static bool _isUndirectedCyclic<T>(IGraph<T> graph, T source, object parent, ref HashSet<T> visited) where T : IComparable<T>
3131
{
32-
if(!visited.Contains(source))
32+
if (!visited.Contains(source))
3333
{
3434
// Mark the current node as visited
3535
visited.Add(source);
@@ -46,7 +46,7 @@ private static bool _isUndirectedCyclic<T>(IGraph<T> graph, T source, object par
4646
return true;
4747
}
4848
}
49-
49+
5050
return false;
5151
}
5252

@@ -90,18 +90,18 @@ private static bool _isDirectedCyclic<T>(IGraph<T> graph, T source, ref HashSet<
9090
/// <summary>
9191
/// Returns true if Graph has cycle.
9292
/// </summary>
93-
public static bool IsCyclic<T> (IGraph<T> Graph) where T : IComparable<T>
93+
public static bool IsCyclic<T>(IGraph<T> Graph) where T : IComparable<T>
9494
{
9595
if (Graph == null)
9696
throw new ArgumentNullException();
9797

9898
var visited = new HashSet<T>();
9999
var recursionStack = new HashSet<T>();
100-
101-
if(Graph.IsDirected)
100+
101+
if (Graph.IsDirected)
102102
{
103-
foreach(var vertex in Graph.Vertices)
104-
if(_isDirectedCyclic<T>(Graph, vertex, ref visited, ref recursionStack))
103+
foreach (var vertex in Graph.Vertices)
104+
if (_isDirectedCyclic<T>(Graph, vertex, ref visited, ref recursionStack))
105105
return true;
106106
}
107107
else

Algorithms/Graphs/DijkstraAllPairsShortestPaths.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ public DijkstraAllPairsShortestPaths(TGraph Graph)
3434

3535
// Initialize the all pairs dictionary
3636
_allPairsDjkstra = new Dictionary<TVertex, DijkstraShortestPaths<TGraph, TVertex>>();
37-
37+
3838
var vertices = Graph.Vertices;
3939

40-
foreach(var vertex in vertices) {
40+
foreach (var vertex in vertices)
41+
{
4142
var dijkstra = new DijkstraShortestPaths<TGraph, TVertex>(Graph, vertex);
4243
_allPairsDjkstra.Add(vertex, dijkstra);
4344
}

Algorithms/Graphs/DijkstraShortestPaths.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private void _dijkstra(TGraph graph, TVertex source)
8686
foreach (var edge in edges)
8787
{
8888
var adjacentIndex = _nodesToIndices[edge.Destination];
89-
89+
9090
// calculate a new possible weighted path if the edge weight is less than infinity
9191
var delta = Infinity;
9292
if (edge.Weight < Infinity && (Infinity - edge.Weight) > _distances[currentIndex]) // Handles overflow

Algorithms/Graphs/TopologicalSorter.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private static void _topoSortHelper<T>(IGraph<T> graph, T source, ref DataStruct
2525
foreach (var adjacent in graph.Neighbours(source))
2626
if (!visited.Contains(adjacent))
2727
_topoSortHelper<T>(graph, adjacent, ref topoSortStack, ref visited);
28-
28+
2929
topoSortStack.Push(source);
3030
}
3131

@@ -44,8 +44,8 @@ public static IEnumerable<T> Sort<T>(IGraph<T> Graph) where T : IComparable<T>
4444
var visited = new HashSet<T>();
4545
var topoSortStack = new DataStructures.Lists.Stack<T>();
4646

47-
foreach(var vertex in Graph.Vertices)
48-
if(!visited.Contains(vertex))
47+
foreach (var vertex in Graph.Vertices)
48+
if (!visited.Contains(vertex))
4949
_topoSortHelper<T>(Graph, vertex, ref topoSortStack, ref visited);
5050

5151
return topoSortStack;

Algorithms/Numeric/BinomialCoefficients.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ public static class BinomialCoefficients
1111
public static ulong Calculate(uint n, uint k)
1212
{
1313
ulong result = 1;
14-
14+
1515
// Since C(n, k) = C(n, n-k)
1616
if (k > n - k)
1717
k = n - k;
18-
18+
1919
// Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1]
2020
for (int i = 0; i < k; ++i)
2121
{
2222
result *= Convert.ToUInt64(n - i);
2323
result /= Convert.ToUInt64(i + 1);
2424
}
25-
25+
2626
return result;
2727
}
2828

Algorithms/Numeric/CatalanNumbers.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static class CatalanNumbers
1616
/// Internal cache.
1717
/// By default contains the first two catalan numbers for the ranks: 0, and 1.
1818
/// </summary>
19-
private static Dictionary<uint, ulong> _catalanNumbers = new Dictionary<uint, ulong>() { {0, 1}, {1, 1} };
19+
private static Dictionary<uint, ulong> _catalanNumbers = new Dictionary<uint, ulong>() { { 0, 1 }, { 1, 1 } };
2020

2121
/// <summary>
2222
/// Helper function.
@@ -34,15 +34,15 @@ private static ulong _recursiveHelper(uint rank)
3434
ulong firstPart = _recursiveHelper(i);
3535
ulong secondPart = _recursiveHelper(lastRank - i);
3636

37-
if(!_catalanNumbers.ContainsKey(i)) _catalanNumbers.Add(i, firstPart);
37+
if (!_catalanNumbers.ContainsKey(i)) _catalanNumbers.Add(i, firstPart);
3838
if (!_catalanNumbers.ContainsKey(lastRank - i)) _catalanNumbers.Add(lastRank - i, secondPart);
39-
39+
4040
number = number + (firstPart * secondPart);
4141
}
4242

4343
return number;
4444
}
45-
45+
4646
/// <summary>
4747
/// Public API
4848
/// </summary>

Algorithms/Sorting/BinarySearchTreeSorter.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ public static class BinarySearchTreeSorter
1414
/// <param name="collection"></param>
1515
public static void UnbalancedBSTSort<T>(this List<T> collection) where T : IComparable<T>
1616
{
17-
if(collection.Count == 0)
17+
if (collection.Count == 0)
1818
return;
1919

2020
Node<T> treeRoot = new Node<T>() { Value = collection[0] };
2121

2222
// Get a handle on root.
23-
for(int i = 1; i < collection.Count; ++i)
23+
for (int i = 1; i < collection.Count; ++i)
2424
{
2525
var currentNode = treeRoot;
2626
var newNode = new Node<T>() { Value = collection[i] };
2727

28-
while(true)
28+
while (true)
2929
{
3030
// Go left
31-
if(newNode.Value.IsLessThan<T>(currentNode.Value))
31+
if (newNode.Value.IsLessThan<T>(currentNode.Value))
3232
{
3333
if (currentNode.Left == null)
3434
{

Algorithms/Sorting/CountingSorter.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ public static void CountingSort(this int[] array)
3939
index = 0;
4040

4141
// Sort the elements
42-
for(int j = 0; j < keys.Length; ++j)
42+
for (int j = 0; j < keys.Length; ++j)
4343
{
4444
var val = keys[j];
4545

46-
if(val > 0)
46+
if (val > 0)
4747
{
48-
while(val-- > 0)
48+
while (val-- > 0)
4949
{
5050
array[index] = j;
5151
index++;

Algorithms/Sorting/HeapSorter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static void HeapSortDescending<T>(this IList<T> collection, Comparer<T> c
5656
}
5757
}
5858

59-
59+
6060
/****************************************************************************/
6161

6262

0 commit comments

Comments
 (0)