44 forceinline
unsigned int
46 return static_cast<unsigned int>(
max -
min + 1);
51 assert((
min <= n) && (n <=
max));
54 const unsigned long offset =
55 static_cast<unsigned long>(n_words) *
56 static_cast<unsigned long>(n -
min);
114 forceinline
unsigned int
117 unsigned int l=0U, h=
n-1U;
120 unsigned int m = l + ((h-l) >> 1);
123 else if (k >
r[m].
max)
144 forceinline
unsigned int
146 return static_cast<unsigned int>((t -
td) /
static_cast<unsigned int>(
arity));
155 return &
vd[i].r[
vd[i].n-1U];
165 _add(t);
return *
this;
172 TupleSet::operator bool(
void)
const {
173 return object() !=
nullptr;
207 return (d !=
nullptr) && d->
failed();
229 return !(*
this == t);
239 forceinline
unsigned int
277 forceinline std::size_t
284 switch (
data().state) {
290 return EPK_DENSE_COMPRESSED;
299 forceinline
unsigned int
300 TupleSet::sparse_values(
void)
const {
304 forceinline
const unsigned int*
305 TupleSet::sparse_tuple_value_ids(
void)
const {
309 forceinline
const unsigned int*
310 TupleSet::sparse_support_offsets(
void)
const {
315 TupleSet::support_id(
int p,
int n,
unsigned int& gid)
const {
317 if ((p < 0) || (p >= d.arity))
320 if (v.base ==
nullptr)
322 unsigned int l = 0U, h = v.
n;
324 const unsigned int m = l + ((h-l) >> 1);
327 else if (n > v.r[m].max)
330 gid = v.base[m] +
static_cast<unsigned int>(n - v.r[m].min);
338 TupleSet::sparse_support(
int p,
int n,
339 const unsigned int*& b,
340 const unsigned int*& e,
341 unsigned int& gid)
const {
343 if ((d.sparse_offsets ==
nullptr) ||
344 (d.sparse_tuples ==
nullptr) ||
345 (d.sparse_n_vals == 0U))
347 if (!support_id(p,n,gid))
349 b = d.sparse_tuples + d.sparse_offsets[gid];
350 e = d.sparse_tuples + d.sparse_offsets[gid+1U];
355 TupleSet::dense_compressed_support(
int p,
int n,
362 unsigned int support_id0 = 0U;
363 if (!support_id(p,n,support_id0))
370 namespace Int {
namespace Extensional {
374 unsigned int& n_offsets) {
375 if (n_vals >=
static_cast<unsigned long long>
376 (std::numeric_limits<unsigned int>::max()))
378 n_offsets =
static_cast<unsigned int>(n_vals) + 1U;
382 forceinline
unsigned int
384 return ts.sparse_values();
387 forceinline
const unsigned int*
389 return ts.sparse_tuple_value_ids();
392 forceinline
const unsigned int*
394 return ts.sparse_support_offsets();
400 return ts.support_id(p,n,gid);
405 const unsigned int*& b,
406 const unsigned int*& e,
408 return ts.sparse_support(p,n,b,e,gid);
415 return ts.dense_compressed_support(p,n,b,e);
421 template<
class Char,
class Traits>
422 std::basic_ostream<Char,Traits>&
424 std::basic_ostringstream<Char,Traits> s;
425 s.copyfmt(os); s.width(0);
426 s <<
"Number of tuples: " << ts.
tuples()
427 <<
" (number of words: " << ts.
words() <<
" with "
429 for (
int a=0; a < ts.
arity(); a++) {
430 unsigned int size = 0U;
433 s <<
"\t[" << a <<
"] size: " << size
435 <<
static_cast<unsigned int>(ts.
lst(a)->
max - ts.
fst(a)->
min + 1)
437 << (ts.
lst(a) - ts.
fst(a) + 1U)
440 return os << s.str();
450 c = &(ts.
data().vd[i].r[0]);
471 forceinline
unsigned int
Passing integer arguments.
Exception: Tuple set already finalized
static bool dense_compressed_support(const TupleSet &ts, int p, int n, const TupleSet::CSupportWord *&b, const TupleSet::CSupportWord *&e)
Return compressed support words for position/value.
static bool support_id(const TupleSet &ts, int p, int n, unsigned int &gid)
Return support id for position/value.
static unsigned int sparse_values(const TupleSet &ts)
Return number of sparse support values.
static bool sparse_support(const TupleSet &ts, int p, int n, const unsigned int *&b, const unsigned int *&e, unsigned int &gid)
Return sparse support tuple id range for position/value.
static const unsigned int * sparse_support_offsets(const TupleSet &ts)
Return sparse support offsets.
static const unsigned int * sparse_tuple_value_ids(const TupleSet &ts)
Return tuple-value sparse ids.
Exception: Tuple set not yet finalized
Exception: uninitialized tuple set
SharedHandle::Object * object(void) const
Access to the shared object.
static const unsigned int bpb
Bits per base.
bool get(unsigned int i) const
Access value at bit i.
void set(unsigned int i)
Set bit i.
Compressed support data for one tuple-word block.
unsigned int compressed_n_entries
Number of compressed support entries.
int n_free
Number of free tuple entries of arity.
bool terminal(void) const
Is datastructure no longer mutable.
unsigned int * sparse_tuples
Sparse support tuple ids (size arity*n_tuples).
void resize(void)
Resize tuple data.
BitSetData * support
Pointer to all support data.
Data(int a)
Initialize as empty tuple set with arity a.
unsigned int * compressed_offsets
Compressed support offsets (size n_vals+1).
unsigned int n_words
Number of words for support.
bool failed(void) const
Has finalization failed.
static void set(BitSetData *d, unsigned int n)
Set bit n in bitset data d.
unsigned int * sparse_offsets
Sparse support offsets (size sparse_n_vals+1).
void finalize(void)
Finalize datastructure (disallows additions of more Tuples).
int n_tuples
Number of Tuples.
unsigned int sparse_n_vals
Number of sparse support values.
Tuple get(int i) const
Return tuple with number i.
unsigned int * sparse_tv
Tuple cell to sparse support id map (size arity*n_tuples).
State state
Tuple set lifecycle state and finalized representation.
CSupportWord * compressed_words
Compressed support words (size compressed_n_entries).
unsigned int tuple2idx(Tuple t) const
Map tuple address to index.
Range * range
Pointer to all ranges.
const Range * lst(int i) const
Return last range for position i.
bool finalized(void) const
Is datastructure finalized.
ValueData * vd
Value data.
const Range * fst(int i) const
Return first range for position i.
static const int n_initial_free
Initial number of free tuples.
Tuple add(void)
Return newly added tuple.
unsigned int * range_base
Pointer to all range support ids.
BitSetData * s
Begin of supports.
unsigned int width(void) const
Return the width.
const BitSetData * supports(unsigned int n_words, int n) const
Return the dense supports for value n.
bool operator()(void) const
Test whether iterator is still at a range.
Ranges(const TupleSet &ts, int i)
Initialize for column i.
int max(void) const
Return largest value of range.
const Range * l
Last range.
int min(void) const
Return smallest value of range.
void operator++(void)
Move iterator to next range (if possible).
const Range * c
Current range.
unsigned int width(void) const
Return width of range (distance between minimum and maximum).
Data about values in the table.
unsigned int start(int n) const
Find start range for value n.
unsigned int n
Number of ranges.
Class representing a set of tuples.
TupleSet(void)
Construct an uninitialized tuple set.
bool failed(void) const
Has tuple-set finalization failed.
void _add(const IntArgs &t)
Add tuple t to tuple set.
int tuples(void) const
Number of tuples.
int max(void) const
Return maximal value in all tuples.
bool operator!=(const TupleSet &t) const
Test whether tuple set is different from t.
bool finalized(void) const
Is tuple set successfully finalized.
ExtensionalPropKind representation(void) const
Return materialized tuple-set representation.
TupleSet & add(const IntArgs &t)
Add tuple t to tuple set.
bool operator==(const TupleSet &t) const
Test whether tuple set is equal to t.
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const TupleSet &ts)
Tuple operator[](int i) const
Get tuple i.
const Range * lst(int i) const
Return last range for position i.
int * Tuple
Type of a tuple.
std::size_t hash(void) const
Return hash key.
void finalize(void)
Finalize tuple set with dense support data.
bool equal(const TupleSet &t) const
Test whether tuple set is equal to t.
const Range * fst(int i) const
Return first range for position i.
unsigned int words(void) const
Return number of required bit set words.
int min(void) const
Return minimal value in all tuples.
Data & raw(void) const
Get raw data (must be initialized).
Gecode::Support::BitSetData BitSetData
Import bit set data type.
Data & data(void) const
Get data (must be initialized and finalized).
int arity(void) const
Arity of tuple set.
Heap heap
The single global heap.
ExtensionalPropKind
Support representation selection for extensional tuple sets.
bool support_offsets_size(unsigned long long n_vals, unsigned int &n_offsets)
Gecode toplevel namespace
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
#define GECODE_NEVER
Assert that this command is never executed.