Set of class objects.Class ClassSet manages of sets of class objects of a template type T. For constructing a ClassSet the maximum number of entries must be given. The current maximum number may be inquired with method max(). More...
#include <classset.h>
Classes | |
struct | Item |
Public Member Functions | |
Extension | |
void | add (DataKey &newkey, const T &item) |
adds an element. More... | |
void | add (const T &item) |
adds element item . More... | |
void | add (DataKey newkey[], const T *item, int n) |
add several items. More... | |
void | add (const T *items, int n) |
adds n elements from items . More... | |
void | add (DataKey newkey[], const ClassSet< T > &set) |
adds several new items. More... | |
void | add (const ClassSet< T > &set) |
adds all elements of set . More... | |
T * | create (DataKey &newkey) |
creates new class element in ClassSet. More... | |
T * | create () |
creates new (uninitialized) class element in ClassSet. More... | |
Shrinkage | |
When elements are removed from a ClassSet, the remaining ones are renumbered from 0 through the new size()-1. How this renumbering is performed will not be revealed, since it might be target of future changes. However, some methods provide a parameter | |
void | remove (int removenum) |
removes the removenum 'th element. More... | |
void | remove (const DataKey &removekey) |
removes element with key removekey . More... | |
void | remove (int perm[]) |
remove multiple elements. More... | |
void | remove (const DataKey *keys, int n, int *perm) |
remove n elements given by keys and perm . More... | |
void | remove (const DataKey *keys, int n) |
remove n elements given by keys . More... | |
void | remove (const int *nums, int n, int *perm) |
remove n elements given by nums and perm . More... | |
void | remove (const int *nums, int n) |
remove n elements with numbers nums . More... | |
void | clear () |
remove all elements. More... | |
Access | |
T & | operator[] (int n) |
const T & | operator[] (int n) const |
returns element number n . More... | |
T & | operator[] (const DataKey &k) |
const T & | operator[] (const DataKey &k) const |
returns element with DataKey k . More... | |
Inquiry | |
int | max () const |
returns maximum number of elements that would fit into ClassSet. More... | |
int | num () const |
returns number of elements currently in ClassSet. More... | |
int | size () const |
returns the maximum DataKey::idx currently in ClassSet. More... | |
DataKey | key (int n) const |
returns DataKey of n 'th element in ClassSet. More... | |
DataKey | key (const T *item) const |
returns DataKey of element item in ClassSet. More... | |
int | number (const DataKey &k) const |
returns the number of the element with DataKey k in ClassSet or -1, if it doesn't exist. More... | |
int | number (const T *item) const |
returns the number of element item in ClassSet, throws exception if it doesn't exist. More... | |
bool | has (const DataKey &k) const |
Is k a valid DataKey of an element in ClassSet? More... | |
bool | has (int n) const |
Is n a valid number of an element in ClassSet? More... | |
bool | has (const T *item) const |
Does item belong to ClassSet? More... | |
Miscellaneous | |
ptrdiff_t | reMax (int newmax=0) |
resets max() to newmax . More... | |
bool | isConsistent () const |
consistency check. More... | |
Constructors / Destructors | |
ClassSet (int pmax=8) | |
default constructor. More... | |
ClassSet (const ClassSet &old) | |
copy constructor. More... | |
ClassSet< T > & | operator= (const ClassSet< T > &rhs) |
assignment operator. More... | |
~ClassSet () | |
destructor. More... | |
Protected Attributes | |
Types | |
struct soplex::ClassSet::Item * | theitem |
array of elements in the ClassSet More... | |
Data | |
DataKey * | thekey |
DataKey::idx's of elements. More... | |
int | themax |
length of arrays theitem and thekey More... | |
int | thesize |
highest used element in theitem More... | |
int | thenum |
number of elements in ClassSet More... | |
int | firstfree |
first unused element in theitem More... | |
Set of class objects.
Class ClassSet manages of sets of class objects of a template type T. For constructing a ClassSet the maximum number of entries must be given. The current maximum number may be inquired with method max().
Adding more then max() elements to a ClassSet will core dump. However, method reMax() allows to reset max() without loss of elements currently in the ClassSet. The current number of elements in a ClassSet is returned by method num().
Adding elements to a ClassSet is done via methods add() or create(), while remove() removes elements from a ClassSet. When adding an element to a ClassSet the new element is assigned a DataKey. DataKeys serve to access CLASS elements in a set via a version of the subscript operator[](DataKey).
For convenience all elements in a ClassSet are implicitely numbered from 0 through num()-1 and can be accessed with these numbers using a 2nd subscript operator[](int). The reason for providing DataKeys to access elements of a ClassSet is that the Key of an element remains unchanged as long as the element is a member of the ClassSet, while the numbers will change in an undefined way, if other elements are added to or removed from the ClassSet.
The elements in a ClassSet and their DataKeys are stored in two arrays:
Both arrays have size themax.
In thekey only elements 0 thru thenum-1 contain DataKey::idx's of valid elements, i.e., elements currently in the ClassSet. The current number of elements in the ClassSet is counted in thenum.
In theitem only elements 0 thru thesize-1 are used, but only some of them actually contain real class elements of the ClassSet. They are recognized by having info >= 0, which gives the number of that element. Otherwise info < 0 indicates an unused element. Unused elements are linked in a single linked list: starting with element -firstfree-1
, the next free element is given by -info-1.
The last free element in the list is marked by info == -themax-1.
Finally all elements in theitem with index >= thesize
are unused as well.
Definition at line 85 of file classset.h.
|
explicit |
default constructor.
Definition at line 554 of file classset.h.
copy constructor.
Definition at line 584 of file classset.h.
~ClassSet | ( | ) |
destructor.
Definition at line 668 of file classset.h.
void add | ( | DataKey & | newkey, |
const T & | item | ||
) |
adds an element.
Definition at line 122 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::add().
void add | ( | const T & | item | ) |
adds element item
.
Definition at line 133 of file classset.h.
void add | ( | DataKey | newkey[], |
const T * | item, | ||
int | n | ||
) |
add several items.
Definition at line 144 of file classset.h.
void add | ( | const T * | items, |
int | n | ||
) |
adds n
elements from items
.
Definition at line 154 of file classset.h.
adds several new items.
Definition at line 164 of file classset.h.
void add | ( | const ClassSet< T > & | set | ) |
adds all elements of set
.
Definition at line 173 of file classset.h.
void clear | ( | ) |
remove all elements.
Definition at line 341 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::operator=().
T* create | ( | DataKey & | newkey | ) |
creates new class element in ClassSet.
Definition at line 184 of file classset.h.
T* create | ( | ) |
creates new (uninitialized) class element in ClassSet.
Definition at line 205 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::add(), and ClassSet< soplex::SVSetBase::DLPSV >::create().
bool has | ( | const DataKey & | k | ) | const |
Is k
a valid DataKey of an element in ClassSet?
Definition at line 443 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::remove().
bool has | ( | int | n | ) | const |
Is n
a valid number of an element in ClassSet?
Definition at line 449 of file classset.h.
bool has | ( | const T * | item | ) | const |
Does item
belong to ClassSet?
Definition at line 455 of file classset.h.
bool isConsistent | ( | ) | const |
consistency check.
Definition at line 523 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::ClassSet(), and ClassSet< soplex::SVSetBase::DLPSV >::operator=().
DataKey key | ( | int | n | ) | const |
returns DataKey of n
'th element in ClassSet.
Definition at line 406 of file classset.h.
DataKey key | ( | const T * | item | ) | const |
returns DataKey of element item
in ClassSet.
Definition at line 413 of file classset.h.
int max | ( | ) | const |
returns maximum number of elements that would fit into ClassSet.
Definition at line 388 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::add(), ClassSet< soplex::SVSetBase::DLPSV >::create(), ClassSet< soplex::SVSetBase::DLPSV >::operator=(), and ClassSet< soplex::SVSetBase::DLPSV >::reMax().
int num | ( | ) | const |
returns number of elements currently in ClassSet.
Definition at line 394 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::add(), ClassSet< soplex::SVSetBase::DLPSV >::create(), ClassSet< soplex::SVSetBase::DLPSV >::has(), ClassSet< soplex::SVSetBase::DLPSV >::key(), ClassSet< soplex::SVSetBase::DLPSV >::operator=(), and ClassSet< soplex::SVSetBase::DLPSV >::remove().
int number | ( | const DataKey & | k | ) | const |
returns the number of the element with DataKey k
in ClassSet or -1, if it doesn't exist.
Definition at line 421 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::has(), ClassSet< soplex::SVSetBase::DLPSV >::key(), and ClassSet< soplex::SVSetBase::DLPSV >::remove().
int number | ( | const T * | item | ) | const |
returns the number of element item
in ClassSet, throws exception if it doesn't exist.
Definition at line 432 of file classset.h.
assignment operator.
The assignment operator involves reMax()ing the lvalue ClassSet to the size needed for copying all elements of the rvalue. After the assignment all DataKeys from the lvalue are valid for the rvalue as well. They refer to a copy of the corresponding class elements.
Definition at line 628 of file classset.h.
T& operator[] | ( | int | n | ) |
Definition at line 358 of file classset.h.
const T& operator[] | ( | int | n | ) | const |
returns element number n
.
Definition at line 364 of file classset.h.
T& operator[] | ( | const DataKey & | k | ) |
Definition at line 371 of file classset.h.
const T& operator[] | ( | const DataKey & | k | ) | const |
returns element with DataKey k
.
Definition at line 377 of file classset.h.
ptrdiff_t reMax | ( | int | newmax = 0 | ) |
resets max() to newmax
.
This method will not succeed if newmax
< size(), in which case newmax
== size() will be taken. As generally this method involves copying the ClassSets elements in memory, reMax() returns the number of bytes the addresses of elements in the ClassSet have been moved. Note, that this is identical for all elements in the ClassSet.
Definition at line 483 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::operator=().
void remove | ( | int | removenum | ) |
removes the removenum
'th element.
Definition at line 229 of file classset.h.
void remove | ( | const DataKey & | removekey | ) |
removes element with key removekey
.
Definition at line 255 of file classset.h.
void remove | ( | int | perm[] | ) |
remove multiple elements.
This method removes all elements for the ClassSet with an index i such that perm
[i] < 0. Upon completion, perm
contains the new numbering of elements.
Definition at line 265 of file classset.h.
void remove | ( | const DataKey * | keys, |
int | n, | ||
int * | perm | ||
) |
remove n
elements given by keys
and perm
.
Definition at line 302 of file classset.h.
void remove | ( | const DataKey * | keys, |
int | n | ||
) |
remove n
elements given by keys
.
Definition at line 315 of file classset.h.
void remove | ( | const int * | nums, |
int | n, | ||
int * | perm | ||
) |
remove n
elements given by nums
and perm
.
Definition at line 321 of file classset.h.
void remove | ( | const int * | nums, |
int | n | ||
) |
remove n
elements with numbers nums
.
Definition at line 334 of file classset.h.
int size | ( | ) | const |
returns the maximum DataKey::idx currently in ClassSet.
Definition at line 400 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::number(), ClassSet< soplex::SVSetBase::DLPSV >::operator=(), and ClassSet< soplex::SVSetBase::DLPSV >::reMax().
|
protected |
first unused element in theitem
Definition at line 108 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::ClassSet(), ClassSet< soplex::SVSetBase::DLPSV >::operator=(), ClassSet< soplex::SVSetBase::DLPSV >::reMax(), and ClassSet< soplex::SVSetBase::DLPSV >::remove().
|
protected |
array of elements in the ClassSet
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::ClassSet(), ClassSet< soplex::SVSetBase::DLPSV >::create(), ClassSet< soplex::SVSetBase::DLPSV >::has(), ClassSet< soplex::SVSetBase::DLPSV >::isConsistent(), ClassSet< soplex::SVSetBase::DLPSV >::number(), ClassSet< soplex::SVSetBase::DLPSV >::operator=(), ClassSet< soplex::SVSetBase::DLPSV >::operator[](), ClassSet< soplex::SVSetBase::DLPSV >::reMax(), ClassSet< soplex::SVSetBase::DLPSV >::remove(), and ClassSet< soplex::SVSetBase::DLPSV >::~ClassSet().
|
protected |
DataKey::idx's of elements.
Definition at line 104 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::ClassSet(), and ClassSet< soplex::SVSetBase::DLPSV >::operator=().
|
protected |
length of arrays theitem and thekey
Definition at line 105 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::ClassSet(), ClassSet< soplex::SVSetBase::DLPSV >::max(), and ClassSet< soplex::SVSetBase::DLPSV >::operator=().
|
protected |
number of elements in ClassSet
Definition at line 107 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::ClassSet(), ClassSet< soplex::SVSetBase::DLPSV >::create(), ClassSet< soplex::SVSetBase::DLPSV >::isConsistent(), ClassSet< soplex::SVSetBase::DLPSV >::num(), ClassSet< soplex::SVSetBase::DLPSV >::operator=(), and ClassSet< soplex::SVSetBase::DLPSV >::remove().
|
protected |
highest used element in theitem
Definition at line 106 of file classset.h.
Referenced by ClassSet< soplex::SVSetBase::DLPSV >::operator=(), ClassSet< soplex::SVSetBase::DLPSV >::remove(), and ClassSet< soplex::SVSetBase::DLPSV >::size().