98 static_assert(std::is_trivially_copyable<DATA>::value,
99 "Only trivially copyable types are allowed with DataSet, since it does memcopy");
146 void add(
const DATA& item)
159 assert(
num() + n <=
max());
161 for(
int i = 0; i < n; ++i)
162 add(newkey[i], item[i]);
166 void add(
const DATA* items,
int n)
169 assert(
num() + n <=
max());
171 for(
int i = 0; i < n; ++i)
180 for(
int i = 0; i <
set.num(); ++i)
181 add(newkey[i],
set[i]);
189 for(
int i = 0; i <
set.num(); ++i)
200 if(firstfree != -themax - 1)
202 newkey.
idx = -firstfree - 1;
206 newkey.
idx = thesize++;
241 void remove(
int removenum)
245 int idx = thekey[removenum].
idx;
248 firstfree = -idx - 1;
250 while(-firstfree == thesize)
258 if(removenum != thenum)
260 thekey[removenum] = thekey[
thenum];
269 remove(
number(removekey));
277 void remove(
int perm[])
279 int k, j, first = -1;
282 for(k = j = 0; k <
num(); ++k)
288 int idx = thekey[k].
idx;
290 firstfree = -idx - 1;
299 for(k = first, j =
num(); k < j; ++k)
303 thekey[perm[k]] = thekey[k];
314 void remove(
const DataKey* keys,
int n,
int* perm)
318 for(
int i =
num() - 1; i >= 0; --i)
322 perm[
number(keys[n])] = -1;
330 remove(keys, n, perm.
get_ptr());
333 void remove(
const int* nums,
int n,
int* perm)
337 for(
int i =
num() - 1; i >= 0; --i)
346 void remove(
const int* nums,
int n)
349 remove(nums, n, perm.
get_ptr());
357 firstfree = -themax - 1;
372 assert(n >= 0 && n < thenum);
378 assert(n >= 0 && n < thenum);
385 assert(k.
idx < thesize);
391 assert(k.
idx < thesize);
420 assert(n >= 0 && n <
num());
427 assert(
number(item) >= 0);
428 return thekey[
number(item)];
446 ptrdiff_t idx =
reinterpret_cast<const struct Item*
>(item) -
theitem;
448 if(idx < 0 || idx >=
size())
463 return (n >= 0 && n <
num());
467 bool has(
const DATA* item)
const 497 struct Item* old_theitem =
theitem;
498 newmax = (newmax <
size()) ?
size() : newmax;
502 while(*lastfree != -themax - 1)
505 *lastfree = -newmax - 1;
511 return reinterpret_cast<char*
>(
theitem)
512 - reinterpret_cast<char*>(old_theitem);
518 #ifdef ENABLE_CONSISTENCY_CHECKS 520 if(
theitem == 0 || thekey == 0)
523 if(thesize > themax || thenum > themax || thenum > thesize)
526 if(thesize == thenum && firstfree != -themax - 1)
529 if(thesize != thenum && firstfree == -themax - 1)
532 for(
int i = 0; i <
thenum; ++i)
550 , themax(pmax < 1 ? 8 : pmax)
555 firstfree = -themax - 1;
577 , thesize(old.thesize)
597 memcpy(thekey, old.
thekey, themax *
sizeof(*thekey));
619 for(i = 0; i < rhs.
size(); ++i)
622 for(i = 0; i < rhs.
num(); ++i)
623 thekey[i] = rhs.
thekey[i];
626 firstfree = -themax - 1;
660 #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.
#define SPX_MSG_INCONSISTENT(name)
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.
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