-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncoding.h
102 lines (86 loc) · 1.92 KB
/
Encoding.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef ENCODING
#define ENCODING
#include <cstdlib>
/*********************************************************************************
*
* Node lists
*
*********************************************************************************/
class node;
class variable_node;
class check_node;
class NodeListWithoutID {
public:
int CurrentLength;
int MaxLength;
node **Nodes;
public:
NodeListWithoutID() :
CurrentLength(0), MaxLength(0), Nodes(NULL) {
}
void Allocate(int p_MaxLength) {
if (Nodes != NULL)
delete Nodes;
Nodes = new node *[p_MaxLength];
MaxLength = p_MaxLength;
CurrentLength = 0;
}
void Add(node &Node) {
if (CurrentLength >= MaxLength) {
cout << "NodeList:Add: Attempt to exceed list size\n";
exit(1);
}
Nodes[CurrentLength++] = &Node;
}
// Extract the last node from the list
node &ExtractAnyNode() {
if (CurrentLength <= 0) {
cout
<< "NodeList:ExtractAnyNode: Attempt to extract from an empty list\n";
exit(1);
}
return *Nodes[--CurrentLength];
}
~NodeListWithoutID() {
if (MaxLength > 0) {
delete Nodes;
MaxLength = 0;
CurrentLength = 0;
}
}
int GetLength() {
return CurrentLength;
}
node &operator[](int i) {
return *Nodes[i];
}
};
class NodeListWithID: public NodeListWithoutID {
public:
int Systematic;
int Gap;
public:
void SwitchNodes(int i1, int i2);
void Reverse()
// Reverse the lists
{
for (int i1 = 0, i2 = GetLength() - 1; i1 < i2; i1++, i2--)
SwitchNodes(i1, i2);
}
};
class VariableNodeList: public NodeListWithID {
public:
void Init(variable_node VariableNodeArray[], int p_Length);
variable_node &operator[](int i) {
return *(variable_node *) Nodes[i];
}
};
class CheckNodeList: public NodeListWithID {
public:
void Init(check_node CheckNodeArray[], int p_Length);
check_node &operator[](int i) {
return *(check_node *) Nodes[i];
}
};
void UrbankeAlgorithmAH(NodeListWithID &Columns, NodeListWithID &Rows);
#endif