forked from eullah01/gEFM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PathwayPool.h
67 lines (53 loc) · 1.41 KB
/
PathwayPool.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
#ifndef PATHWAYPOOL_H
#define PATHWAYPOOL_H
#include <cassert>
#include "Pathway.h"
#define MAX_PATHWAY_POOL_SIZE 2000000
template <class BitVector>
class PathwayPool {
public:
PathwayPool() {
pathways = (Pathway<BitVector>*) malloc(MAX_PATHWAY_POOL_SIZE * sizeof (Pathway<BitVector>));
assert(pathways != NULL);
nCount = 0;
}
~PathwayPool() {
if (pathways) {
free(pathways);
pathways = NULL;
}
}
unsigned int size() {
return nCount;
}
Pathway<BitVector>& operator[] (const unsigned int nIndex) {
assert(nIndex >= 0 && nIndex < nCount);
return pathways[nIndex];
}
void operator<<(Pathway<BitVector>& pathway) {
assert((nCount + 1) < MAX_PATHWAY_POOL_SIZE);
pathways[nCount] = pathway;
nCount++;
}
Pathway<BitVector>* operator ++() {
assert((nCount + 1) < MAX_PATHWAY_POOL_SIZE);
return &pathways[nCount++];
}
void operator --() {
assert(nCount > 0);
nCount--;
}
void remove(const unsigned int nIndex) {
assert(nCount > 0);
nCount--;
pathways[nIndex] = pathways[nCount];
}
void swap(int i, int j) {
Pathway<BitVector> p = pathways[i];
pathways[i] = pathways[j];
pathways[j] = p;
}
Pathway<BitVector>* pathways;
unsigned int nCount;
};
#endif /* PATHWAYPOOL_H */