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;
88 IntSet::IntSetObject::in(
int n)
const {
93 int m = l + (
r - l) / 2;
94 if ((this->r[m].
min <= n) && (n <= this->r[m].
max)) {
98 }
else if (n < this->r[m].
min) {
108 IntSet::IntSetObject::equal(
const IntSetObject& iso)
const {
109 assert((
size == iso.size) || (n == iso.n));
110 for (
int i=0;
i<n;
i++)
111 if ((r[i].
min != iso.r[i].min) || (r[i].max != iso.r[i].max))
116 IntSet::IntSetObject::~IntSetObject(
void) {
124 bool operator ()(
const Range &x,
const Range &y);
129 return x.min < y.min;
133 IntSet::normalize(Range* r,
int n) {
148 r[j].min =
min; r[j].max =
max; j++;
149 min = r[i].min;
max = r[i].max; i++;
157 IntSetObject* o = IntSetObject::allocate(n);
159 for (
int i=0;
i<n;
i++) {
160 s +=
static_cast<unsigned int>(
r[
i].max) -
161 static_cast<unsigned int>(r[i].
min) + 1U;
170 IntSet::init(
const int r[],
int n) {
173 Range* dr = reg.alloc<Range>(n);
174 for (
int i=0;
i<n;
i++) {
175 dr[
i].min=
r[
i]; dr[
i].max=
r[
i];
181 IntSet::init(
const int r[][2],
int n) {
184 Range* dr = reg.alloc<Range>(n);
186 for (
int i=0;
i<n;
i++)
187 if (r[i][0] <= r[i][1]) {
188 dr[j].min=
r[
i][0]; dr[j].max=
r[
i][1]; j++;
194 int n =
static_cast<int>(r.size());
197 Range* dr = reg.
alloc<Range>(n);
200 dr[j].min=dr[j].max=k; j++;
206 int n =
static_cast<int>(r.size());
209 Range* dr = reg.
alloc<Range>(n);
211 for (
const std::pair<int,int>& k : r)
212 if (k.first <= k.second) {
213 dr[j].min=k.first; dr[j].max=k.second; j++;
220 IntSet::init(
int n,
int m) {
222 IntSetObject* o = IntSetObject::allocate(1);
223 o->r[0].min = n; o->r[0].max = m;
224 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 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})