Skip to content

Commit 6a62fc3

Browse files
committed
more cleanup via resharper
1 parent c11a861 commit 6a62fc3

34 files changed

+441
-553
lines changed

Advanced.Algorithms.Tests/DataStructures/Heap/Min/D-aryMinHeap_Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class AsD_aryMinTree_Tests
1414
/// A tree test
1515
/// </summary>
1616
[TestMethod]
17-
public void AsD_aryHeap_Test()
17+
public void D_aryHeap_Test()
1818
{
1919
var rnd = new Random();
2020
var initial = Enumerable.Range(0, 51).OrderBy(x => rnd.Next()).ToList();

Advanced.Algorithms.Tests/DataStructures/Tree/AVLTree_Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Advanced.Algorithms.Tests.DataStructures
88
{
99
[TestClass]
10-
public class AVLTree_Tests
10+
public class AvlTreeTests
1111
{
1212
/// <summary>
1313
/// Smoke test

Advanced.Algorithms.Tests/DataStructures/Tree/B+Tree_Tests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class BPTree_Tests
1515
public void BPTree_Smoke_Test()
1616
{
1717
//insert test
18-
var tree = new BPTree<int>(3);
18+
var tree = new BpTree<int>(3);
1919

2020
tree.Insert(5);
2121
tree.Insert(3);
@@ -89,7 +89,7 @@ public void BPTree_AccuracyTest()
8989
.ToList();
9090

9191
var order = 5;
92-
var tree = new BPTree<int>(order);
92+
var tree = new BpTree<int>(order);
9393

9494
for (int i = 0; i < nodeCount; i++)
9595
{
@@ -165,7 +165,7 @@ public void BPTree_StressTest()
165165
.OrderBy(x => rnd.Next())
166166
.ToList();
167167

168-
var tree = new BPTree<int>(12);
168+
var tree = new BpTree<int>(12);
169169

170170
for (int i = 0; i < nodeCount; i++)
171171
{

Advanced.Algorithms.Tests/DataStructures/Tree/FenwickTree_Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class AsFenwickTreeTests
1111
/// Smoke test
1212
/// </summary>
1313
[TestMethod]
14-
public void AsFenwickTree_Sum_Smoke_Test()
14+
public void FenwickTree_Sum_Smoke_Test()
1515
{
1616
var testArray = new int[] { 1, 3, 5, 7, 9, 11 };
1717

Advanced.Algorithms.Tests/DataStructures/Tree/RangeTreeTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class RangeTreeTests
1010
/// Smoke test
1111
/// </summary>
1212
[TestMethod]
13-
public void AsRangeTree1D_Smoke_Test()
13+
public void RangeTree1D_Smoke_Test()
1414
{
1515
var tree = new DRangeTree<int>(1);
1616

@@ -46,7 +46,7 @@ public void AsRangeTree1D_Smoke_Test()
4646
}
4747

4848
[TestMethod]
49-
public void AsRangeTree2D_Smoke_Test()
49+
public void RangeTree2D_Smoke_Test()
5050
{
5151
var tree = new DRangeTree<int>(2);
5252

Advanced.Algorithms.Tests/DataStructures/Tree/SegmentTree_Tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
namespace Advanced.Algorithms.Tests.DataStructures.Tree
66
{
77
[TestClass]
8-
public class AsSegmentTreeTests
8+
public class SegmentTreeTests
99
{
1010
/// <summary>
1111
/// Smoke test
1212
/// </summary>
1313
[TestMethod]
14-
public void AsSegmentTree_Sum_Smoke_Test()
14+
public void SegmentTree_Sum_Smoke_Test()
1515
{
1616
var testArray = new int[] { 1, 3, 5, 7, 9, 11 };
1717

Advanced.Algorithms/DataStructures/Heap/BinomialHeapNode.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
63

74
namespace Advanced.Algorithms.DataStructures.Heap
85
{
@@ -23,7 +20,7 @@ public BinomialHeapNode(T value)
2320

2421
public int CompareTo(object obj)
2522
{
26-
return this.Value.CompareTo((obj as BinomialHeapNode<T>).Value);
23+
return Value.CompareTo(((BinomialHeapNode<T>) obj).Value);
2724
}
2825
}
2926

Advanced.Algorithms/DataStructures/Heap/FibornacciHeapNode.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
62

73
namespace Advanced.Algorithms.DataStructures.Heap
84
{
@@ -21,12 +17,12 @@ public class FibornacciHeapNode<T> : IComparable where T : IComparable
2117

2218
public FibornacciHeapNode(T value)
2319
{
24-
this.Value = value;
20+
Value = value;
2521
}
2622

2723
public int CompareTo(object obj)
2824
{
29-
return this.Value.CompareTo((obj as FibornacciHeapNode<T>).Value);
25+
return Value.CompareTo(((FibornacciHeapNode<T>) obj).Value);
3026
}
3127
}
3228

Advanced.Algorithms/DataStructures/Heap/Max/BMaxHeap.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ public BMaxHeap(IEnumerable<T> initial = null)
1919
{
2020
if (initial != null)
2121
{
22-
var initArray = new T[initial.Count()];
22+
var items = initial as T[] ?? initial.ToArray();
23+
var initArray = new T[items.Count()];
2324

2425
int i = 0;
25-
foreach (var item in initial)
26+
foreach (var item in items)
2627
{
2728
initArray[i] = item;
2829
i++;
@@ -48,7 +49,7 @@ private void BulkInit(T[] initial)
4849

4950
while (i >= 0)
5051
{
51-
BulkInitRecursive(i, initial);
52+
bulkInitRecursive(i, initial);
5253
i--;
5354
}
5455

@@ -59,31 +60,35 @@ private void BulkInit(T[] initial)
5960
/// Recursively
6061
/// </summary>
6162
/// <param name="i"></param>
62-
private void BulkInitRecursive(int i, T[] initial)
63+
/// <param name="initial"></param>
64+
private void bulkInitRecursive(int i, T[] initial)
6365
{
64-
var parent = i;
66+
while (true)
67+
{
68+
var parent = i;
6569

66-
var left = 2 * i + 1;
67-
var right = 2 * i + 2;
70+
var left = 2 * i + 1;
71+
var right = 2 * i + 2;
6872

69-
var max = left < initial.Length && right < initial.Length ?
70-
initial[left].CompareTo(initial[right]) > 0 ? left : right
71-
: left < initial.Length ?
72-
left : right < initial.Length ?
73-
right : -1;
73+
var max = left < initial.Length && right < initial.Length ? initial[left].CompareTo(initial[right]) > 0 ? left : right
74+
: left < initial.Length ? left
75+
: right < initial.Length ? right : -1;
7476

75-
if (max != -1
76-
&& initial[max].CompareTo(initial[parent]) > 0)
77-
{
78-
var temp = initial[max];
79-
initial[max] = initial[parent];
80-
initial[parent] = temp;
77+
if (max != -1 && initial[max].CompareTo(initial[parent]) > 0)
78+
{
79+
var temp = initial[max];
80+
initial[max] = initial[parent];
81+
initial[parent] = temp;
8182

82-
//if min is child then drill down child
83-
BulkInitRecursive(max, initial);
84-
}
83+
//if min is child then drill down child
84+
i = max;
85+
continue;
86+
}
8587

88+
break;
89+
}
8690
}
91+
8792
//o(log(n))
8893
public void Insert(T newItem)
8994
{
@@ -117,12 +122,12 @@ public T ExtractMax()
117122
{
118123
throw new Exception("Empty heap");
119124
}
120-
var Max = heapArray[0];
125+
var max = heapArray[0];
121126

122127
heapArray[0] = heapArray[Count - 1];
123128
Count--;
124129

125-
int parentIndex = 0;
130+
var parentIndex = 0;
126131

127132
//percolate down
128133
while (true)
@@ -137,12 +142,7 @@ public T ExtractMax()
137142
var leftChild = heapArray[leftIndex];
138143
var rightChild = heapArray[rightIndex];
139144

140-
var leftIsMax = false;
141-
142-
if (leftChild.CompareTo(rightChild) > 0)
143-
{
144-
leftIsMax = true;
145-
}
145+
bool leftIsMax = leftChild.CompareTo(rightChild) > 0;
146146

147147
var maxChildIndex = leftIsMax ? leftIndex : rightIndex;
148148

@@ -209,7 +209,7 @@ public T ExtractMax()
209209
halfArray();
210210
}
211211

212-
return Max;
212+
return max;
213213
}
214214

215215
//o(1)
@@ -227,7 +227,7 @@ private void halfArray()
227227
{
228228
var smallerArray = new T[heapArray.Length / 2];
229229

230-
for (int i = 0; i < Count; i++)
230+
for (var i = 0; i < Count; i++)
231231
{
232232
smallerArray[i] = heapArray[i];
233233
}
@@ -239,7 +239,7 @@ private void doubleArray()
239239
{
240240
var biggerArray = new T[heapArray.Length * 2];
241241

242-
for (int i = 0; i < Count; i++)
242+
for (var i = 0; i < Count; i++)
243243
{
244244
biggerArray[i] = heapArray[i];
245245
}

0 commit comments

Comments
 (0)