1 |
|
#include <iostream> |
2 |
< |
#include <cstdlib> |
2 |
> |
#include <stdlib.h> |
3 |
|
|
4 |
– |
|
4 |
|
#include "Exclude.hpp" |
5 |
|
|
6 |
< |
int Exclude::nExcludes; |
8 |
< |
int* Exclude::exPairs; |
6 |
> |
Exclude* Exclude::_instance = 0; |
7 |
|
|
8 |
< |
Exclude::Exclude( int theIndex ){ |
9 |
< |
|
10 |
< |
index = theIndex; |
11 |
< |
exI = index*2; |
12 |
< |
exJ = index*2 + 1; |
8 |
> |
Exclude* Exclude::Instance() { |
9 |
> |
if (_instance == 0) { |
10 |
> |
_instance = new Exclude; |
11 |
> |
} |
12 |
> |
return _instance; |
13 |
|
} |
14 |
|
|
15 |
< |
void Exclude::createArray( int the_nExcludes ){ |
16 |
< |
|
17 |
< |
nExcludes = the_nExcludes; |
20 |
< |
exPairs = new int[nExcludes*2]; |
15 |
> |
Exclude::Exclude(){ |
16 |
> |
exPairs = NULL; |
17 |
> |
newFortranArrayNeeded = 1; |
18 |
|
} |
19 |
|
|
20 |
< |
void Exclude::destroyArray( void ){ |
21 |
< |
delete[] exPairs; |
20 |
> |
Exclude::~Exclude() { |
21 |
> |
if (exPairs != NULL) { |
22 |
> |
delete[] exPairs; |
23 |
> |
} |
24 |
> |
delete _instance; |
25 |
|
} |
26 |
– |
|
27 |
– |
void Exclude::printMe( void ){ |
26 |
|
|
27 |
< |
std::cerr << "exclude[" << index << "] i, j: " << exPairs[exI] << " - " << exPairs[exJ] << "\n"; |
28 |
< |
} |
27 |
> |
int* Exclude::getFortranArray(){ |
28 |
> |
|
29 |
> |
set<pair<int, int> >::iterator i; |
30 |
> |
int j; |
31 |
|
|
32 |
< |
void Exclude::setPair( int i, int j ){ |
33 |
< |
exPairs[exI] = i; |
34 |
< |
exPairs[exJ] = j; |
32 |
> |
if (newFortranArrayNeeded != 0) { |
33 |
> |
delete[] exPairs; |
34 |
> |
exPairs = new int[2*getSize()]; |
35 |
> |
j = 0; |
36 |
> |
for(i = excludeSet.begin(); i != excludeSet.end(); ++i) { |
37 |
> |
exPairs[j] = (*i).first; |
38 |
> |
j++; |
39 |
> |
exPairs[j] = (*i).second; |
40 |
> |
j++; |
41 |
> |
} |
42 |
> |
newFortranArrayNeeded = 0; |
43 |
> |
} |
44 |
> |
|
45 |
> |
return exPairs; |
46 |
|
} |
47 |
|
|
48 |
< |
void Exclude::addExcludePairs(int nAdded, int* AexPairs) { |
49 |
< |
int nNew = nExcludes + nAdded; |
48 |
> |
|
49 |
> |
void Exclude::addPair(int i, int j) { |
50 |
|
|
51 |
< |
int* new_exPairs = new int[nNew*2]; |
52 |
< |
int i, j; |
51 |
> |
if (!hasPair(i, j)) { |
52 |
> |
|
53 |
> |
if (i != j) { |
54 |
> |
|
55 |
> |
if (i < j) |
56 |
> |
excludeSet.insert(make_pair(i, j)); |
57 |
> |
else |
58 |
> |
excludeSet.insert(make_pair(j, i)); |
59 |
> |
} |
60 |
|
|
61 |
< |
for (i = 0; i < 2*nExcludes; i++) { |
44 |
< |
new_exPairs[i] = exPairs[i]; |
61 |
> |
newFortranArrayNeeded = 1; |
62 |
|
} |
63 |
|
|
64 |
< |
for (i=0; i < 2*nAdded; i++) { |
48 |
< |
j = i + 2*nExcludes; |
49 |
< |
new_exPairs[j] = AexPairs[i]; |
50 |
< |
} |
64 |
> |
} |
65 |
|
|
52 |
– |
delete[] exPairs; |
66 |
|
|
67 |
< |
exPairs = new_exPairs; |
67 |
> |
void Exclude::printMe( void ){ |
68 |
|
|
69 |
< |
nExcludes = nNew; |
70 |
< |
} |
69 |
> |
set<pair<int, int> >::iterator i; |
70 |
> |
int index; |
71 |
> |
|
72 |
> |
index = 0; |
73 |
> |
for(i = excludeSet.begin(); i != excludeSet.end(); ++i) { |
74 |
|
|
75 |
< |
void Exclude::deleteExcludePair(int theIndex) { |
76 |
< |
deleteRange(theIndex, theIndex); |
75 |
> |
std::cerr << "exclude[" << index << "] i, j: " << (*i).first << " - " << (*i).second << "\n"; |
76 |
> |
index++; |
77 |
> |
|
78 |
> |
} |
79 |
|
} |
80 |
|
|
81 |
< |
void Exclude::deleteRange(int startIndex, int stopIndex) { |
81 |
> |
int Exclude::hasPair(int i, int j) { |
82 |
|
|
83 |
< |
int nNew = nExcludes - (stopIndex - startIndex + 1); |
66 |
< |
int* new_exPairs = new int[nNew*2]; |
67 |
< |
int i, j; |
83 |
> |
set<pair<int, int> >::iterator position; |
84 |
|
|
85 |
< |
for (i=0; i < 2*startIndex; i++) { |
86 |
< |
new_exPairs[i] = exPairs[i]; |
87 |
< |
} |
88 |
< |
for(i=2*(stopIndex+1); i < 2*nExcludes; i++) { |
89 |
< |
j = i-2*startIndex + 1; |
74 |
< |
new_exPairs[j] = exPairs[i]; |
75 |
< |
} |
85 |
> |
if (i != j) { |
86 |
> |
if (i < j) |
87 |
> |
position = excludeSet.find(make_pair(i, j)); |
88 |
> |
else |
89 |
> |
position = excludeSet.find(make_pair(j, i)); |
90 |
|
|
91 |
< |
delete[] exPairs; |
92 |
< |
|
93 |
< |
exPairs = new_exPairs; |
94 |
< |
nExcludes = nNew; |
91 |
> |
if (position != excludeSet.end()) |
92 |
> |
return 1; |
93 |
> |
else |
94 |
> |
return 0; |
95 |
> |
} else |
96 |
> |
return 0; |
97 |
|
} |
98 |
+ |
|
99 |
+ |
int Exclude::getSize() { |
100 |
+ |
return excludeSet.size(); |
101 |
+ |
} |