This repository has been archived by the owner on Jan 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HashTableWithRedBlackTree.cs
66 lines (55 loc) · 1.69 KB
/
HashTableWithRedBlackTree.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Text;
using System.Collections;
namespace SolucionAlumno
{
class HashTableWithRedBlackTree : IOrderSerchStruct<Node>
{
private Hashtable internalTable = new Hashtable();
private RedBlackTree<Node> internalRedBlackTree = new RedBlackTree<Node>();
#region Miembros de IOrderSerchStruct<Node>
public int Size
{
get { return internalTable.Count; }
}
public void Add(Node item)
{
RedBlackNode<Node> node = new RedBlackNode<Node>(item);
internalRedBlackTree.Add(node);
internalTable.Add(item.GetHashCode(), node);
}
public void Clear()
{
internalTable.Clear();
internalRedBlackTree.Clear();
}
public bool Contains(Node item)
{
return internalTable.ContainsKey(item.GetHashCode());
}
public Node FindInStruct(Node item)
{
return (internalTable[item.GetHashCode()] as RedBlackNode<Node>).Value;
}
public bool Remove(Node item)
{
if (internalRedBlackTree.Remove(item))
{
internalTable.Remove(item.GetHashCode());
return true;
}
return false;
}
public Node getMinValue()
{
return internalRedBlackTree.getMinValue();
}
public Node getMinimoAndRemove()
{
Node min = internalRedBlackTree.getMinimoAndRemove();
internalTable.Remove(min.GetHashCode());
return min;
}
#endregion
}
}