124 T* newelem =
create(newkey);
126 assert(newelem != 0);
138 assert(newelem != 0);
147 assert(
num() + n <=
max());
149 for(
int i = 0; i < n; ++i)
150 add(newkey[i], item[i]);
154 void add(
const T* items,
int n)
157 assert(
num() + n <=
max());
159 for(
int i = 0; i < n; ++i)
168 for(
int i = 0; i <
set.num(); ++i)
169 add(newkey[i],
set[i]);
177 for(
int i = 0; i <
set.num(); ++i)
188 if(firstfree != -themax - 1)
190 newkey.
idx = -firstfree - 1;
194 newkey.
idx = thesize++;
229 void remove(
int removenum)
233 int idx = thekey[removenum].
idx;
236 firstfree = -idx - 1;
238 while(-firstfree == thesize)
246 if(removenum != thenum)
248 thekey[removenum] = thekey[
thenum];
257 remove(
number(removekey));
265 void remove(
int perm[])
267 int k, j, first = -1;
270 for(k = j = 0; k <
num(); ++k)
276 int idx = thekey[k].
idx;
278 firstfree = -idx - 1;
287 for(k = first, j =
num(); k < j; ++k)
291 thekey[perm[k]] = thekey[k];
302 void remove(
const DataKey* keys,
int n,
int* perm)
306 for(
int i =
num() - 1; i >= 0; --i)
310 perm[
number(keys[n])] = -1;
318 remove(keys, n, perm.
get_ptr());
321 void remove(
const int* nums,
int n,
int* perm)
325 for(
int i =
num() - 1; i >= 0; --i)
334 void remove(
const int* nums,
int n)
337 remove(nums, n, perm.
get_ptr());
345 firstfree = -themax - 1;
360 assert(n >= 0 && n < thenum);
366 assert(n >= 0 && n < thenum);
373 assert(k.
idx < thesize);
379 assert(k.
idx < thesize);
408 assert(n >= 0 && n <
num());
415 assert(
number(item) >= 0);
416 return thekey[
number(item)];
434 ptrdiff_t idx =
reinterpret_cast<const struct Item*
>(item) -
theitem;
436 if(idx < 0 || idx >=
size())
451 return (n >= 0 && n <
num());
455 bool has(
const T* item)
const 487 newmax = (newmax <
size()) ?
size() : newmax;
491 while(*lastfree != -themax - 1)
494 *lastfree = -newmax - 1;
499 for(i = 0; i <
max(); i++)
506 for(; i < newmax; i++)
507 new(&(newMem[i])) Item();
510 ptrdiff_t pshift =
reinterpret_cast<char*
>(newMem) - reinterpret_cast<char*>(
theitem);
525 #ifdef ENABLE_CONSISTENCY_CHECKS 527 if(
theitem == 0 || thekey == 0)
530 if(thesize > themax || thenum > themax || thenum > thesize)
533 if(thesize == thenum && firstfree != -themax - 1)
536 if(thesize != thenum && firstfree == -themax - 1)
539 for(
int i = 0; i <
thenum; ++i)
557 , themax(pmax < 1 ? 8 : pmax)
562 firstfree = -themax - 1;
567 for(
int i = 0; i <
themax; i++)
588 , thesize(old.thesize)
600 for(i = 0; i < old.
thenum; i++)
604 for(; i < old.
themax; i++)
617 memcpy(thekey, old.
thekey, themax *
sizeof(*thekey));
639 for(i = 0; i < rhs.
size(); ++i)
642 for(i = 0; i < rhs.
num(); ++i)
643 thekey[i] = rhs.
thekey[i];
646 firstfree = -themax - 1;
680 #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.
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.
#define MSGinconsistent(name)
Save arrays of data objects.
int idx
(locally) unique key index
void spx_free(T &p)
Release memory.