Skip to content

Commit 34dce58

Browse files
committed
Merge branch 'master' into beta
2 parents 257bcc9 + 427c661 commit 34dce58

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

src/Advanced.Algorithms/DataStructures/Dictionary/OrderedDictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class OrderedDictionary<K, V> : IEnumerable<KeyValuePair<K, V>> where K :
2020

2121
public OrderedDictionary()
2222
{
23-
binarySearchTree = new RedBlackTree<OrderedKeyValuePair<K, V>>(true);
23+
binarySearchTree = new RedBlackTree<OrderedKeyValuePair<K, V>>();
2424
}
2525

2626
/// <summary>

src/Advanced.Algorithms/DataStructures/HashSet/OrderedHashSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class OrderedHashSet<T> : IEnumerable<T> where T : IComparable
1818

1919
public OrderedHashSet()
2020
{
21-
binarySearchTree = new RedBlackTree<T>(true);
21+
binarySearchTree = new RedBlackTree<T>();
2222
}
2323

2424
/// <summary>

src/Advanced.Algorithms/DataStructures/Tree/RedBlackTree.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,40 @@ namespace Advanced.Algorithms.DataStructures
1010
/// </summary>
1111
public class RedBlackTree<T> : BSTBase<T>, IEnumerable<T> where T : IComparable
1212
{
13+
//only used internally by Bentley-Ottmann sweepline algorithm for faster line swap operation.
1314
private readonly Dictionary<T, BSTNodeBase<T>> nodeLookUp;
15+
1416
internal RedBlackTreeNode<T> Root { get; set; }
15-
public int Count => Root == null ? 0 : Root.Count;
1617

17-
/// <param name="enableNodeLookUp">Enabling lookup will fasten deletion/insertion/exists operations
18-
/// at the cost of additional space.</param>
19-
/// <param name="equalityComparer">Provide custom IEquality comparer for node lookup dictionary when enabled.</param>
20-
public RedBlackTree(bool enableNodeLookUp = false, IEqualityComparer<T> equalityComparer = null)
21-
{
22-
if (enableNodeLookUp)
23-
{
24-
nodeLookUp = new Dictionary<T, BSTNodeBase<T>>(equalityComparer);
25-
}
26-
}
18+
public int Count => Root == null ? 0 : Root.Count;
2719

2820
/// <summary>
29-
/// Initialize the BST with given sorted keys.
21+
/// Initialize the BST with given sorted keys optionally.
3022
/// Time complexity: O(n).
3123
/// </summary>
3224
/// <param name="collection">The sorted keys.</param>
3325
/// <param name="enableNodeLookUp">Enabling lookup will fasten deletion/insertion/exists operations
3426
/// at the cost of additional space.</param>
3527
/// <param name="equalityComparer">Provide custom IEquality comparer for node lookup dictionary when enabled.</param>
36-
public RedBlackTree(IEnumerable<T> sortedKeys, bool enableNodeLookUp = false, IEqualityComparer<T> equalityComparer = null)
37-
: this(enableNodeLookUp, equalityComparer)
28+
public RedBlackTree(IEnumerable<T> sortedKeys = null)
3829
{
39-
ValidateCollection(sortedKeys);
40-
var nodes = sortedKeys.Select(x => new RedBlackTreeNode<T>(null, x)).ToArray();
41-
Root = (RedBlackTreeNode<T>)ToBST(nodes);
42-
assignColors(Root);
43-
assignCount(Root);
30+
if (sortedKeys != null)
31+
{
32+
ValidateCollection(sortedKeys);
33+
var nodes = sortedKeys.Select(x => new RedBlackTreeNode<T>(null, x)).ToArray();
34+
Root = (RedBlackTreeNode<T>)ToBST(nodes);
35+
assignColors(Root);
36+
assignCount(Root);
37+
}
4438
}
4539

40+
///Special (internal only) constructor for Bentley-Ottmann sweep line algorithm for fast line swap.
41+
/// <param name="equalityComparer">Provide custom IEquality comparer for node lookup dictionary.</param>
42+
internal RedBlackTree(IEqualityComparer<T> equalityComparer)
43+
: this()
44+
{
45+
nodeLookUp = new Dictionary<T, BSTNodeBase<T>>(equalityComparer);
46+
}
4647

4748
/// <summary>
4849
/// Time complexity: O(log(n))
@@ -200,7 +201,7 @@ public int Insert(T value)
200201
return (node, insertionPosition);
201202
}
202203

203-
currentNode = currentNode.Right;
204+
currentNode = currentNode.Right;
204205
}
205206
//current node is greater than new node
206207
else if (compareResult > 0)

src/Advanced.Algorithms/Geometry/BentleyOttmann.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private void initialize(IEnumerable<Line> lineSegments)
4040
{
4141
SweepLine = new Line(new Point(0, 0), new Point(0, int.MaxValue), Tolerance);
4242

43-
currentlyTrackedLines = new RedBlackTree<Event>(true, pointComparer);
43+
currentlyTrackedLines = new RedBlackTree<Event>(pointComparer);
4444
intersectionEvents = new Dictionary<Point, HashSet<Tuple<Event, Event>>>(pointComparer);
4545

4646
verticalHorizontalLines = new HashSet<Event>();

0 commit comments

Comments
 (0)