89 static_assert(std::is_trivially_copyable<DATA>::value,
90 "Only trivially copyable types are allowed with DataSet, since it does memcopy");
137 void add(
const DATA& item)
150 assert(
num() + n <=
max());
152 for(
int i = 0; i < n; ++i)
153 add(newkey[i], item[i]);
157 void add(
const DATA* items,
int n)
160 assert(
num() + n <=
max());
162 for(
int i = 0; i < n; ++i)
171 for(
int i = 0; i <
set.num(); ++i)
172 add(newkey[i],
set[i]);
180 for(
int i = 0; i <
set.num(); ++i)
191 if(firstfree != -themax - 1)
193 newkey.
idx = -firstfree - 1;
197 newkey.
idx = thesize++;
232 void remove(
int removenum)
236 int idx = thekey[removenum].
idx;
239 firstfree = -idx - 1;
241 while(-firstfree == thesize)
249 if(removenum != thenum)
251 thekey[removenum] = thekey[
thenum];
260 remove(
number(removekey));
268 void remove(
int perm[])
270 int k, j, first = -1;
273 for(k = j = 0; k <
num(); ++k)
279 int idx = thekey[k].
idx;
281 firstfree = -idx - 1;
290 for(k = first, j =
num(); k < j; ++k)
294 thekey[perm[k]] = thekey[k];
305 void remove(
const DataKey* keys,
int n,
int* perm)
309 for(
int i =
num() - 1; i >= 0; --i)
313 perm[
number(keys[n])] = -1;
321 remove(keys, n, perm.
get_ptr());
324 void remove(
const int* nums,
int n,
int* perm)
328 for(
int i =
num() - 1; i >= 0; --i)
337 void remove(
const int* nums,
int n)
340 remove(nums, n, perm.
get_ptr());
348 firstfree = -themax - 1;
363 assert(n >= 0 && n < thenum);
369 assert(n >= 0 && n < thenum);
376 assert(k.
idx < thesize);
382 assert(k.
idx < thesize);
411 assert(n >= 0 && n <
num());
418 assert(
number(item) >= 0);
419 return thekey[
number(item)];
437 ptrdiff_t idx =
reinterpret_cast<const struct Item*
>(item) -
theitem;
439 if(idx < 0 || idx >=
size())
454 return (n >= 0 && n <
num());
458 bool has(
const DATA* item)
const 488 struct Item* old_theitem =
theitem;
489 newmax = (newmax <
size()) ?
size() : newmax;
493 while(*lastfree != -themax - 1)
496 *lastfree = -newmax - 1;
502 return reinterpret_cast<char*
>(
theitem)
503 - reinterpret_cast<char*>(old_theitem);
509 #ifdef ENABLE_CONSISTENCY_CHECKS 511 if(
theitem == 0 || thekey == 0)
514 if(thesize > themax || thenum > themax || thenum > thesize)
517 if(thesize == thenum && firstfree != -themax - 1)
520 if(thesize != thenum && firstfree == -themax - 1)
523 for(
int i = 0; i <
thenum; ++i)
541 , themax(pmax < 1 ? 8 : pmax)
546 firstfree = -themax - 1;
568 , thesize(old.thesize)
588 memcpy(thekey, old.
thekey, themax *
sizeof(*thekey));
610 for(i = 0; i < rhs.
size(); ++i)
613 for(i = 0; i < rhs.
num(); ++i)
614 thekey[i] = rhs.
thekey[i];
617 firstfree = -themax - 1;
651 #endif // _DATASET_H_ DataKey * thekey
DataKey::idx's of elements.
int thenum
number of elements in DataSet
struct soplex::DataSet::Item * theitem
array of elements in the DataSet
DATA & operator[](const DataKey &k)
DataKey key(int n) const
returns DataKey of n 'th element in DataSet.
Entry identifier class for items of a DataSet.
void add(const DATA *items, int n)
adds n elements from items.
Memory allocation routines.
void add(const DataSet< DATA > &set)
adds all elements of set.
T * get_ptr()
get a C pointer to the data.
Exception classes for SoPlex.
ptrdiff_t reMax(int newmax=0)
resets max() to newmax.
int info
element number. info [0,thesize-1] iff element is used
int number(const DATA *item) const
returns the number of element item in DataSet, throws exception if it doesn't exist.
bool has(const DATA *item) const
Does item belong to DataSet?
Entry identifier class for items of a DataSet.Every item in a DataSet is assigned a DataKey by which ...
Exception class for out of memory exceptions.This class is derived from the SoPlex exception base cla...
void spx_alloc(T &p, int n=1)
Allocate memory.
Set of data objects.Class DataSet manages of sets of data objects of a template type DATA...
DataSet(const DataSet &old)
copy constructor.
void add(DataKey &newkey, const DATA &item)
adds an element.
DATA * create()
creates new (uninitialized) data element in DataSet.
bool has(int n) const
Is n a valid number of an element in DataSet?
DataSet< DATA > & operator=(const DataSet< DATA > &rhs)
assignment operator.
int thesize
highest used element in theitem
void clear()
remove all elements.
bool isConsistent() const
consistency check.
DataKey key(const DATA *item) const
returns DataKey of element item in DataSet.
int firstfree
first unused element in theitem
void spx_realloc(T &p, int n)
Change amount of allocated memory.
Exception base class.This class implements a base class for our SoPlex exceptions We provide a what()...
Everything should be within this namespace.
bool has(const DataKey &k) const
Is k a valid DataKey of an element in DataSet?
DataSet(int pmax=8)
default constructor.
void add(DataKey newkey[], const DataSet< DATA > &set)
adds several new items.
Save arrays of arbitrary types.
int size() const
returns the maximum DataKey::idx currently in DataSet.
const DATA & operator[](const DataKey &k) const
returns element with DataKey k.
int max() const
returns maximum number of elements that would fit into DataSet.
int number(const DataKey &k) const
returns the number of the element with DataKey k in DataSet or -1, if it doesn't exist.
DATA * create(DataKey &newkey)
creates new data element in DataSet.
#define MSGinconsistent(name)
Save arrays of data objects.
void add(const DATA &item)
adds element item.
int num() const
returns number of elements currently in DataSet.
int idx
(locally) unique key index
void spx_free(T &p)
Release memory.
const DATA & operator[](int n) const
returns element number n.
void add(DataKey newkey[], const DATA *item, int n)
add several items.
int themax
length of arrays theitem and thekey