Skip to content

Commit ab0119e

Browse files
committed
enable node lookup
1 parent 1c9ecde commit ab0119e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

Lines changed: 14 additions & 3 deletions
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>>();
23+
binarySearchTree = new RedBlackTree<OrderedKeyValuePair<K, V>>(true);
2424
}
2525

2626
/// <summary>
@@ -215,6 +215,11 @@ internal OrderedKeyValuePair(K key, V value)
215215
this.Value = value;
216216
}
217217

218+
public KeyValuePair<K, V> ToKeyValuePair()
219+
{
220+
return new KeyValuePair<K, V>(Key, Value);
221+
}
222+
218223
public int CompareTo(object obj)
219224
{
220225
if (obj is OrderedKeyValuePair<K, V> itemToComare)
@@ -225,10 +230,16 @@ public int CompareTo(object obj)
225230
throw new ArgumentException("Compare object is nu");
226231
}
227232

228-
public KeyValuePair<K, V> ToKeyValuePair()
233+
public override bool Equals(object obj)
229234
{
230-
return new KeyValuePair<K, V>(Key, Value);
235+
return Key.Equals(((OrderedKeyValuePair<K, V>)obj).Key);
231236
}
237+
238+
public override int GetHashCode()
239+
{
240+
return Key.GetHashCode();
241+
}
242+
232243
}
233244

234245
internal class SortedDictionaryEnumerator<K, V> : IEnumerator<KeyValuePair<K, V>> where K : IComparable

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>();
21+
binarySearchTree = new RedBlackTree<T>(true);
2222
}
2323

2424
/// <summary>

0 commit comments

Comments
 (0)