133 T* newelem =
create(newkey);
135 assert(newelem != 0);
147 assert(newelem != 0);
156 assert(
num() + n <=
max());
158 for(
int i = 0; i < n; ++i)
159 add(newkey[i], item[i]);
163 void add(
const T* items,
int n)
166 assert(
num() + n <=
max());
168 for(
int i = 0; i < n; ++i)
177 for(
int i = 0; i <
set.num(); ++i)
178 add(newkey[i],
set[i]);
186 for(
int i = 0; i <
set.num(); ++i)
197 if(firstfree != -themax - 1)
199 newkey.
idx = -firstfree - 1;
203 newkey.
idx = thesize++;
238 void remove(
int removenum)
242 int idx = thekey[removenum].
idx;
245 firstfree = -idx - 1;
247 while(-firstfree == thesize)
255 if(removenum != thenum)
257 thekey[removenum] = thekey[
thenum];
266 remove(
number(removekey));
274 void remove(
int perm[])
276 int k, j, first = -1;
279 for(k = j = 0; k <
num(); ++k)
285 int idx = thekey[k].
idx;
287 firstfree = -idx - 1;
296 for(k = first, j =
num(); k < j; ++k)
300 thekey[perm[k]] = thekey[k];
311 void remove(
const DataKey* keys,
int n,
int* perm)
315 for(
int i =
num() - 1; i >= 0; --i)
319 perm[
number(keys[n])] = -1;
327 remove(keys, n, perm.
get_ptr());
330 void remove(
const int* nums,
int n,
int* perm)
334 for(
int i =
num() - 1; i >= 0; --i)
343 void remove(
const int* nums,
int n)
346 remove(nums, n, perm.
get_ptr());
354 firstfree = -themax - 1;
369 assert(n >= 0 && n < thenum);
375 assert(n >= 0 && n < thenum);
382 assert(k.
idx < thesize);
388 assert(k.
idx < thesize);
417 assert(n >= 0 && n <
num());
424 assert(
number(item) >= 0);
425 return thekey[
number(item)];
443 ptrdiff_t idx =
reinterpret_cast<const struct Item*
>(item) -
theitem;
445 if(idx < 0 || idx >=
size())
460 return (n >= 0 && n <
num());
464 bool has(
const T* item)
const 496 newmax = (newmax <
size()) ?
size() : newmax;
500 while(*lastfree != -themax - 1)
503 *lastfree = -newmax - 1;
508 for(i = 0; i <
max(); i++)
515 for(; i < newmax; i++)
516 new(&(newMem[i])) Item();
519 ptrdiff_t pshift =
reinterpret_cast<char*
>(newMem) - reinterpret_cast<char*>(
theitem);
534 #ifdef ENABLE_CONSISTENCY_CHECKS 536 if(
theitem == 0 || thekey == 0)
539 if(thesize > themax || thenum > themax || thenum > thesize)
542 if(thesize == thenum && firstfree != -themax - 1)
545 if(thesize != thenum && firstfree == -themax - 1)
548 for(
int i = 0; i <
thenum; ++i)
566 , themax(pmax < 1 ? 8 : pmax)
571 firstfree = -themax - 1;
576 for(
int i = 0; i <
themax; i++)
597 , thesize(old.thesize)
609 for(i = 0; i < old.
thenum; i++)
613 for(; i < old.
themax; i++)
626 memcpy(thekey, old.
thekey, themax *
sizeof(*thekey));
648 for(i = 0; i < rhs.
size(); ++i)
651 for(i = 0; i < rhs.
num(); ++i)
652 thekey[i] = rhs.
thekey[i];
655 firstfree = -themax - 1;
689 #endif // _CLASSSET_H_ DataKey key(int n) const
returns DataKey of n 'th element in ClassSet.
int number(const DataKey &k) const
returns the number of the element with DataKey k in ClassSet or -1, if it doesn't exist...
int max() const
returns maximum number of elements that would fit into ClassSet.
void add(const T *items, int n)
adds n elements from items.
Entry identifier class for items of a DataSet.
int number(const T *item) const
returns the number of element item in ClassSet, throws exception if it doesn't exist.
Memory allocation routines.
int thesize
highest used element in theitem
T * get_ptr()
get a C pointer to the data.
ClassSet(const ClassSet &old)
copy constructor.
Exception classes for SoPlex.
bool has(const T *item) const
Does item belong to ClassSet?
void add(const ClassSet< T > &set)
adds all elements of set.
#define SPX_MSG_INCONSISTENT(name)
T * create(DataKey &newkey)
creates new class element in ClassSet.
ptrdiff_t reMax(int newmax=0)
resets max() to newmax.
void add(DataKey newkey[], const ClassSet< T > &set)
adds several new items.
void add(DataKey newkey[], const T *item, int n)
add several items.
DataKey * thekey
DataKey::idx's of elements.
ClassSet< T > & operator=(const ClassSet< T > &rhs)
assignment operator.
Entry identifier class for items of a DataSet.Every item in a DataSet is assigned a DataKey by which ...
Save arrays of data objects.
void add(const T &item)
adds element item.
bool isConsistent() const
consistency check.
struct soplex::ClassSet::Item * theitem
array of elements in the ClassSet
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.
bool has(const DataKey &k) const
Is k a valid DataKey of an element in ClassSet?
int thenum
number of elements in ClassSet
ClassSet(int pmax=8)
default constructor.
int firstfree
first unused element in theitem
void add(DataKey &newkey, const T &item)
adds an element.
int info
element number. info [0,thesize-1] iff element is used
Set of class objects.Class ClassSet manages of sets of class objects of a template type T...
const T & operator[](const DataKey &k) const
returns element with DataKey k.
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.
int num() const
returns number of elements currently in ClassSet.
int themax
length of arrays theitem and thekey
T * create()
creates new (uninitialized) class element in ClassSet.
Save arrays of arbitrary types.
bool has(int n) const
Is n a valid number of an element in ClassSet?
int size() const
returns the maximum DataKey::idx currently in ClassSet.
void clear()
remove all elements.
T & operator[](const DataKey &k)
const T & operator[](int n) const
returns element number n.
DataKey key(const T *item) const
returns DataKey of element item in ClassSet.
Save arrays of data objects.
int idx
(locally) unique key index
void spx_free(T &p)
Release memory.