-
Notifications
You must be signed in to change notification settings - Fork 0
/
orbit.cc
131 lines (99 loc) · 2.71 KB
/
orbit.cc
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <stdlib.h>
#include <assert.h>
#include "defs.hh"
#include "orbit.hh"
/*
Copyright (c) 2003-2015 Tommi Junttila
Released under the GNU Lesser General Public License version 3.
This file is part of bliss.
bliss is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, version 3 of the License.
bliss is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with bliss. If not, see <http://www.gnu.org/licenses/>.
*/
namespace bliss_digraphs {
Orbit::Orbit()
{
nof_elements = 0;
}
Orbit::~Orbit()
{
}
void Orbit::init(const unsigned int n)
{
assert(n > 0);
orbits_vec.resize(n);
orbits = orbits_vec.begin();
in_orbit_vec.resize(n);
in_orbit = in_orbit_vec.begin();
nof_elements = n;
reset();
}
void Orbit::reset()
{
assert(!orbits_vec.empty());
assert(!in_orbit_vec.empty());
for(unsigned int i = 0; i < nof_elements; i++)
{
orbits[i].element = i;
orbits[i].next = 0;
orbits[i].size = 1;
in_orbit[i] = &orbits[i];
}
_nof_orbits = nof_elements;
}
void Orbit::merge_orbits(OrbitEntry *orbit1, OrbitEntry *orbit2)
{
if(orbit1 != orbit2)
{
_nof_orbits--;
/* Only update the elements in the smaller orbit */
if(orbit1->size > orbit2->size)
{
OrbitEntry * const temp = orbit2;
orbit2 = orbit1;
orbit1 = temp;
}
/* Link the elements of orbit1 to the almost beginning of orbit2 */
OrbitEntry *e = orbit1;
while(e->next)
{
in_orbit[e->element] = orbit2;
e = e->next;
}
in_orbit[e->element] = orbit2;
e->next = orbit2->next;
orbit2->next = orbit1;
/* Keep the minimal orbit representative in the beginning */
if(orbit1->element < orbit2->element)
{
const unsigned int temp = orbit1->element;
orbit1->element = orbit2->element;
orbit2->element = temp;
}
orbit2->size += orbit1->size;
}
}
void Orbit::merge_orbits(unsigned int e1, unsigned int e2)
{
merge_orbits(in_orbit[e1], in_orbit[e2]);
}
bool Orbit::is_minimal_representative(unsigned int element) const
{
return(get_minimal_representative(element) == element);
}
unsigned int Orbit::get_minimal_representative(unsigned int element) const
{
OrbitEntry * const orbit = in_orbit[element];
return(orbit->element);
}
unsigned int Orbit::orbit_size(unsigned int element) const
{
return(in_orbit[element]->size);
}
} // namespace bliss_digraphs