-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBHeapDegreeTable.h
86 lines (67 loc) · 1.9 KB
/
BHeapDegreeTable.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef ADS_BINOMIAL_HEAP_DEGREE_TABLE_H
#define ADS_BINOMIAL_HEAP_DEGREE_TABLE_H
#include "DArray.h"
#include "Node.h"
namespace ADS
{
template <class T>
class DegreeTable
{
public:
DegreeTable (void);
~DegreeTable (void);
/* Returns true if the element at position uiPosition
is not null */
bool used (unsigned int uiPosition);
bool add (unsigned int uiPosition, BNode<T> *pNode);
void remove (unsigned int uiPosition, BNode<T> *&pNode);
/* Returns the length of the array */
unsigned int size (void);
private:
struct DegreeTableEntry
{
BNode<T> *pNode;
};
DArray<DegreeTableEntry*> _table;
};
template<class T>
DegreeTable<T>::DegreeTable()
: _table (1, 0, true)
{
}
template<class T>
DegreeTable<T>::~DegreeTable()
{
}
template<class T>
bool DegreeTable<T>::used (unsigned int uiPosition)
{
return (_table.get (uiPosition) != NULL);
}
template<class T>
bool DegreeTable<T>::add (unsigned int uiPosition, BNode<T> *pNode)
{
DegreeTableEntry *pEntry = _table.get (uiPosition);
bool bRet = false;
if (pEntry == NULL) {
pEntry = new DegreeTableEntry;
DegreeTableEntry *pTmp = _table.add (uiPosition, pEntry);
bRet = (pTmp == NULL);
}
pEntry->pNode = pNode;
return bRet;
}
template<class T>
void DegreeTable<T>::remove (unsigned int uiPosition, BNode<T> *&pNode)
{
DegreeTableEntry *pEntry = _table.remove (uiPosition);
pNode = pEntry->pNode;
delete pEntry;
}
template<class T>
unsigned int DegreeTable<T>::size()
{
return _table.size();
}
}
#endif /* ADS_BINOMIAL_HEAP_DEGREE_TABLE_H */