44#ifdef GECODE_HAS_FAULT_INJECTION
45 std::atomic<int> IntSet::IntSetObject::fault_live_objects{0};
48 IntSet::IntSetObject::operator
new(
size_t s) {
49 void* p = ::operator
new(s);
50 fault_live_objects.fetch_add(1, std::memory_order_relaxed);
55 IntSet::IntSetObject::operator
delete(
void* p) {
56 fault_live_objects.fetch_sub(1, std::memory_order_relaxed);
61 IntSet::fault_reset_allocations(
void) {
62 IntSetObject::fault_live_objects.store(0, std::memory_order_relaxed);
66 IntSet::fault_live_allocations(
void) {
67 return IntSetObject::fault_live_objects.load(std::memory_order_relaxed);
72 IntSet::IntSetObject::allocate(
int n) {
73 IntSetObject* o =
new IntSetObject;
78#ifdef GECODE_HAS_FAULT_INJECTION
91 IntSet::IntSetObject::in(
int n)
const {
96 int m = l + (
r - l) / 2;
97 if ((this->r[m].
min <= n) && (n <= this->r[m].
max)) {
101 }
else if (n < this->r[m].
min) {
111 IntSet::IntSetObject::equal(
const IntSetObject& iso)
const {
112 assert((
size == iso.size) || (n == iso.n));
113 for (
int i=0;
i<n;
i++)
114 if ((r[i].
min != iso.r[i].min) || (r[i].max != iso.r[i].max))
119 IntSet::IntSetObject::~IntSetObject(
void) {
127 bool operator ()(
const Range &x,
const Range &y);
132 return x.min < y.min;
136 IntSet::normalize(Range* r,
int n) {
151 r[j].min =
min; r[j].max =
max; j++;
152 min = r[i].min;
max = r[i].max; i++;
160 IntSetObject* o = IntSetObject::allocate(n);
162 for (
int i=0;
i<n;
i++) {
163 s +=
static_cast<unsigned int>(
r[
i].max) -
164 static_cast<unsigned int>(r[i].
min) + 1U;
173 IntSet::init(
const int r[],
int n) {
176 Range* dr = reg.alloc<Range>(n);
177 for (
int i=0;
i<n;
i++) {
178 dr[
i].min=
r[
i]; dr[
i].max=
r[
i];
184 IntSet::init(
const int r[][2],
int n) {
187 Range* dr = reg.alloc<Range>(n);
189 for (
int i=0;
i<n;
i++)
190 if (r[i][0] <= r[i][1]) {
191 dr[j].min=
r[
i][0]; dr[j].max=
r[
i][1]; j++;
197 int n =
static_cast<int>(r.size());
200 Range* dr = reg.
alloc<Range>(n);
203 dr[j].min=dr[j].max=k; j++;
209 int n =
static_cast<int>(r.size());
212 Range* dr = reg.
alloc<Range>(n);
214 for (
const std::pair<int,int>& k : r)
215 if (k.first <= k.second) {
216 dr[j].min=k.first; dr[j].max=k.second; j++;
223 IntSet::init(
int n,
int m) {
225 IntSetObject* o = IntSetObject::allocate(1);
226 o->r[0].min = n; o->r[0].max = m;
227 o->size =
static_cast<unsigned int>(m) -
static_cast<unsigned int>(n) + 1U;
void free(T *b, long unsigned int n)
Delete n objects starting at b.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
Sort ranges according to increasing minimum.
bool operator()(const Range &x, const Range &y)
int min(int i) const
Return minimum of range at position i.
int max(int i) const
Return maximum of range at position i.
int max(void) const
Return maximum of entire set.
unsigned int size(void) const
Return size (cardinality) of set.
IntSet(void)
Initialize as empty set.
static const IntSet empty
Empty set.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
SharedHandle::Object * object(void) const
Access to the shared object.
Heap heap
The single global heap.
void check(Phase p)
Check failpoint for phase p.
void quicksort(Type *l, Type *r, Less &less)
Standard quick sort.
Gecode toplevel namespace
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Gecode::IntArgs i({1, 2, 3, 4})