Set of data objects. More...
#include <dataset.h>
Classes | |
struct | Item |
Public Member Functions | |
Extension | |
void | add (DataKey &newkey, const DATA &item) |
adds an element. More... | |
void | add (const DATA &item) |
adds element item . More... | |
void | add (DataKey newkey[], const DATA *item, int n) |
add several items. More... | |
void | add (const DATA *items, int n) |
adds n elements from items . More... | |
void | add (DataKey newkey[], const DataSet< DATA > &set) |
adds several new items. More... | |
void | add (const DataSet< DATA > &set) |
adds all elements of set . More... | |
DATA * | create (DataKey &newkey) |
creates new data element in DataSet. More... | |
DATA * | create () |
creates new (uninitialized) data element in DataSet. More... | |
Shrinkage | |
When elements are removed from a DataSet, 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 | |
DATA & | operator[] (int n) |
const DATA & | operator[] (int n) const |
returns element number n . More... | |
DATA & | operator[] (const DataKey &k) |
const DATA & | operator[] (const DataKey &k) const |
returns element with DataKey k . More... | |
Inquiry | |
int | max () const |
returns maximum number of elements that would fit into DataSet. More... | |
int | num () const |
returns number of elements currently in DataSet. More... | |
int | size () const |
returns the maximum DataKey::idx currently in DataSet. More... | |
DataKey | key (int n) const |
returns DataKey of n 'th element in DataSet. More... | |
DataKey | key (const DATA *item) const |
returns DataKey of element item in DataSet. More... | |
int | number (const DataKey &k) const |
returns the number of the element with DataKey k in DataSet or -1, if it doesn't exist. More... | |
int | number (const DATA *item) const |
returns the number of element item in DataSet, throws exception if it doesn't exist. More... | |
bool | has (const DataKey &k) const |
Is k a valid DataKey of an element in DataSet? More... | |
bool | has (int n) const |
Is n a valid number of an element in DataSet? More... | |
bool | has (const DATA *item) const |
Does item belong to DataSet? More... | |
Miscellaneous | |
ptrdiff_t | reMax (int newmax=0) |
resets max() to newmax . More... | |
bool | isConsistent () const |
consistency check. More... | |
Constructors / Destructors | |
DataSet (int pmax=8) | |
default constructor. More... | |
DataSet (const DataSet &old) | |
copy constructor. More... | |
DataSet< DATA > & | operator= (const DataSet< DATA > &rhs) |
assignment operator. More... | |
~DataSet () | |
destructor. More... | |
Protected Attributes | |
Types | |
struct soplex::DataSet::Item * | theitem |
array of elements in the DataSet 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 DataSet More... | |
int | firstfree |
first unused element in theitem More... | |
Set of data objects.
Class DataSet manages of sets of data objects of a template type DATA. For constructing a DataSet 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 DataSet will core dump. However, method reMax() allows to reset max() without loss of elements currently in the DataSet. The current number of elements in a DataSet is returned by method num().
Adding elements to a DataSet is done via methods add() or create(), while remove() removes elements from a DataSet. When adding an element to a DataSet the new element is assigned a DataKey. DataKeys serve to access DATA elements in a set via a version of the subscript operator[](DataKey).
For convenience all elements in a DataSet 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 DataSet is that the Key of an element remains unchanged as long as the element is a member of the DataSet, while the numbers will change in an undefined way, if other elements are added to or removed from the DataSet.
The elements in a DataSet 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 DataSet. The current number of elements in the DataSet is counted in thenum.
In theitem only elements 0 thru thesize-1 are used, but only some of them actually contain real data elements of the DataSet. 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.
|
explicit |
default constructor.
Definition at line 545 of file dataset.h.
References DataSet< DATA >::firstfree, DataSet< DATA >::isConsistent(), soplex::spx_alloc(), soplex::spx_free(), DataSet< DATA >::theitem, DataSet< DATA >::thekey, and DataSet< DATA >::themax.
copy constructor.
Definition at line 571 of file dataset.h.
References DataSet< DATA >::firstfree, DataSet< DATA >::isConsistent(), soplex::spx_alloc(), soplex::spx_free(), DataSet< DATA >::theitem, DataSet< DATA >::thekey, and DataSet< DATA >::themax.
~DataSet | ( | ) |
destructor.
Definition at line 646 of file dataset.h.
References soplex::spx_free(), DataSet< DATA >::theitem, and DataSet< DATA >::thekey.
void add | ( | const DATA & | item | ) |
void add | ( | const DATA * | items, |
int | n | ||
) |
adds n
elements from items
.
Definition at line 164 of file dataset.h.
References DataSet< DATA >::add(), DataSet< DATA >::max(), and DataSet< DATA >::num().
void add | ( | const DataSet< DATA > & | set | ) |
adds all elements of set
.
Definition at line 183 of file dataset.h.
References DataSet< DATA >::add(), DataSet< DATA >::max(), and DataSet< DATA >::num().
void add | ( | DataKey & | newkey, |
const DATA & | item | ||
) |
adds an element.
Definition at line 135 of file dataset.h.
References DataSet< DATA >::create().
Referenced by DataSet< DATA >::add().
void add | ( | DataKey | newkey[], |
const DATA * | item, | ||
int | n | ||
) |
add several items.
Definition at line 154 of file dataset.h.
References DataSet< DATA >::add(), DataSet< DATA >::max(), and DataSet< DATA >::num().
adds several new items.
Definition at line 174 of file dataset.h.
References DataSet< DATA >::add(), DataSet< DATA >::max(), and DataSet< DATA >::num().
void clear | ( | ) |
remove all elements.
Definition at line 351 of file dataset.h.
References DataSet< DATA >::firstfree, DataSet< DATA >::themax, DataSet< DATA >::thenum, and DataSet< DATA >::thesize.
Referenced by NameSet::clear(), and DataSet< DATA >::operator=().
DATA * create | ( | ) |
creates new (uninitialized) data element in DataSet.
Definition at line 215 of file dataset.h.
References DataSet< DATA >::create().
Referenced by DataSet< DATA >::add(), and DataSet< DATA >::create().
DATA * create | ( | DataKey & | newkey | ) |
creates new data element in DataSet.
Definition at line 194 of file dataset.h.
References DataSet< DATA >::Item::data, DataSet< DATA >::firstfree, DataKey::idx, DataSet< DATA >::Item::info, DataSet< DATA >::max(), DataSet< DATA >::num(), DataSet< DATA >::theitem, DataSet< DATA >::thekey, DataSet< DATA >::themax, DataSet< DATA >::thenum, and DataSet< DATA >::thesize.
Referenced by NameSet::add().
bool has | ( | const DATA * | item | ) | const |
Does item
belong to DataSet?
Definition at line 465 of file dataset.h.
References DataSet< DATA >::number().
bool has | ( | const DataKey & | k | ) | const |
Is k
a valid DataKey of an element in DataSet?
Definition at line 453 of file dataset.h.
References DataKey::idx, DataSet< DATA >::Item::info, and DataSet< DATA >::theitem.
Referenced by NameSet::has(), and DataSet< DATA >::remove().
bool has | ( | int | n | ) | const |
Is n
a valid number of an element in DataSet?
Definition at line 459 of file dataset.h.
References DataSet< DATA >::num().
bool isConsistent | ( | ) | const |
consistency check.
Definition at line 514 of file dataset.h.
References DataSet< DATA >::firstfree, SPX_MSG_INCONSISTENT, DataSet< DATA >::theitem, DataSet< DATA >::thekey, DataSet< DATA >::themax, DataSet< DATA >::thenum, and DataSet< DATA >::thesize.
Referenced by DataSet< DATA >::DataSet(), NameSet::isConsistent(), and DataSet< DATA >::operator=().
DataKey key | ( | const DATA * | item | ) | const |
returns DataKey of element item
in DataSet.
Definition at line 423 of file dataset.h.
References DataSet< DATA >::number(), and DataSet< DATA >::thekey.
DataKey key | ( | int | n | ) | const |
returns DataKey of n
'th element in DataSet.
Definition at line 416 of file dataset.h.
References DataSet< DATA >::num(), and DataSet< DATA >::thekey.
Referenced by NameSet::key().
int max | ( | ) | const |
returns maximum number of elements that would fit into DataSet.
Definition at line 398 of file dataset.h.
References DataSet< DATA >::themax.
Referenced by DataSet< DATA >::add(), DataSet< DATA >::create(), NameSet::max(), NameSet::NameSet(), and DataSet< DATA >::operator=().
int num | ( | ) | const |
returns number of elements currently in DataSet.
Definition at line 404 of file dataset.h.
References DataSet< DATA >::thenum.
Referenced by DataSet< DATA >::add(), DataSet< DATA >::create(), DataSet< DATA >::has(), DataSet< DATA >::key(), NameSet::num(), DataSet< DATA >::operator=(), NameSet::remove(), and DataSet< DATA >::remove().
int number | ( | const DATA * | item | ) | const |
returns the number of element item
in DataSet, throws exception if it doesn't exist.
Definition at line 442 of file dataset.h.
References DataSet< DATA >::Item::info, DataSet< DATA >::size(), and DataSet< DATA >::theitem.
int number | ( | const DataKey & | k | ) | const |
returns the number of the element with DataKey k
in DataSet or -1, if it doesn't exist.
Definition at line 431 of file dataset.h.
References DataKey::idx, DataSet< DATA >::Item::info, DataSet< DATA >::size(), and DataSet< DATA >::theitem.
Referenced by DataSet< DATA >::has(), DataSet< DATA >::key(), NameSet::number(), and DataSet< DATA >::remove().
assignment operator.
The assignment operator involves reMax()ing the lvalue DataSet 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 data elements.
Definition at line 606 of file dataset.h.
References DataSet< DATA >::clear(), DataSet< DATA >::firstfree, DataSet< DATA >::Item::info, DataSet< DATA >::isConsistent(), DataSet< DATA >::max(), DataSet< DATA >::num(), DataSet< DATA >::reMax(), DataSet< DATA >::size(), DataSet< DATA >::theitem, DataSet< DATA >::thekey, DataSet< DATA >::themax, DataSet< DATA >::thenum, and DataSet< DATA >::thesize.
DATA & operator[] | ( | const DataKey & | k | ) |
Definition at line 381 of file dataset.h.
References DataSet< DATA >::Item::data, DataKey::idx, DataSet< DATA >::theitem, and DataSet< DATA >::thesize.
const DATA & operator[] | ( | const DataKey & | k | ) | const |
returns element with DataKey k
.
Definition at line 387 of file dataset.h.
References DataSet< DATA >::Item::data, DataKey::idx, DataSet< DATA >::theitem, and DataSet< DATA >::thesize.
DATA & operator[] | ( | int | n | ) |
Definition at line 368 of file dataset.h.
References DataSet< DATA >::Item::data, DataKey::idx, DataSet< DATA >::theitem, DataSet< DATA >::thekey, and DataSet< DATA >::thenum.
const DATA & operator[] | ( | int | n | ) | const |
returns element number n
.
Definition at line 374 of file dataset.h.
References DataSet< DATA >::Item::data, DataKey::idx, DataSet< DATA >::theitem, DataSet< DATA >::thekey, and DataSet< DATA >::thenum.
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 DataSets elements in memory, reMax() returns the number of bytes the addresses of elements in the DataSet have been moved. Note, that this is identical for all elements in the DataSet.
Definition at line 493 of file dataset.h.
References DataSet< DATA >::firstfree, DataSet< DATA >::Item::info, DataSet< DATA >::size(), soplex::spx_realloc(), DataSet< DATA >::theitem, DataSet< DATA >::thekey, and DataSet< DATA >::themax.
Referenced by DataSet< DATA >::operator=(), and NameSet::reMax().
void remove | ( | const DataKey & | removekey | ) |
removes element with key removekey
.
Definition at line 265 of file dataset.h.
References DataSet< DATA >::number(), and DataSet< DATA >::remove().
void remove | ( | const DataKey * | keys, |
int | n | ||
) |
remove n
elements given by keys
.
Definition at line 325 of file dataset.h.
References DataArray< T >::get_ptr(), DataSet< DATA >::num(), and DataSet< DATA >::remove().
void remove | ( | const DataKey * | keys, |
int | n, | ||
int * | perm | ||
) |
remove n
elements given by keys
and perm
.
Definition at line 312 of file dataset.h.
References DataSet< DATA >::num(), DataSet< DATA >::number(), and DataSet< DATA >::remove().
void remove | ( | const int * | nums, |
int | n | ||
) |
remove n
elements with numbers nums
.
Definition at line 344 of file dataset.h.
References DataArray< T >::get_ptr(), DataSet< DATA >::num(), and DataSet< DATA >::remove().
void remove | ( | const int * | nums, |
int | n, | ||
int * | perm | ||
) |
remove n
elements given by nums
and perm
.
Definition at line 331 of file dataset.h.
References DataSet< DATA >::num(), and DataSet< DATA >::remove().
void remove | ( | int | perm[] | ) |
remove multiple elements.
This method removes all elements for the DataSet with an index i such that perm
[i] < 0. Upon completion, perm
contains the new numbering of elements.
Definition at line 275 of file dataset.h.
References DataSet< DATA >::firstfree, DataKey::idx, DataSet< DATA >::Item::info, DataSet< DATA >::num(), DataSet< DATA >::theitem, DataSet< DATA >::thekey, and DataSet< DATA >::thenum.
void remove | ( | int | removenum | ) |
removes the removenum
'th element.
Definition at line 239 of file dataset.h.
References DataSet< DATA >::firstfree, DataSet< DATA >::has(), DataKey::idx, DataSet< DATA >::Item::info, DataSet< DATA >::theitem, DataSet< DATA >::thekey, DataSet< DATA >::thenum, and DataSet< DATA >::thesize.
Referenced by NameSet::remove(), and DataSet< DATA >::remove().
int size | ( | ) | const |
returns the maximum DataKey::idx currently in DataSet.
Definition at line 410 of file dataset.h.
References DataSet< DATA >::thesize.
Referenced by DataSet< DATA >::number(), DataSet< DATA >::operator=(), DataSet< DATA >::reMax(), and NameSet::size().
|
protected |
first unused element in theitem
Definition at line 121 of file dataset.h.
Referenced by DataSet< DATA >::clear(), DataSet< DATA >::create(), DataSet< DATA >::DataSet(), DataSet< DATA >::isConsistent(), DataSet< DATA >::operator=(), DataSet< DATA >::reMax(), and DataSet< DATA >::remove().
|
protected |
array of elements in the DataSet
Referenced by DataSet< DATA >::create(), DataSet< DATA >::DataSet(), DataSet< DATA >::has(), DataSet< DATA >::isConsistent(), DataSet< DATA >::number(), DataSet< DATA >::operator=(), DataSet< DATA >::operator[](), DataSet< DATA >::reMax(), DataSet< DATA >::remove(), and DataSet< DATA >::~DataSet().
|
protected |
DataKey::idx's of elements.
Definition at line 117 of file dataset.h.
Referenced by DataSet< DATA >::create(), DataSet< DATA >::DataSet(), DataSet< DATA >::isConsistent(), DataSet< DATA >::key(), DataSet< DATA >::operator=(), DataSet< DATA >::operator[](), DataSet< DATA >::reMax(), DataSet< DATA >::remove(), and DataSet< DATA >::~DataSet().
|
protected |
length of arrays theitem and thekey
Definition at line 118 of file dataset.h.
Referenced by DataSet< DATA >::clear(), DataSet< DATA >::create(), DataSet< DATA >::DataSet(), DataSet< DATA >::isConsistent(), DataSet< DATA >::max(), DataSet< DATA >::operator=(), and DataSet< DATA >::reMax().
|
protected |
number of elements in DataSet
Definition at line 120 of file dataset.h.
Referenced by DataSet< DATA >::clear(), DataSet< DATA >::create(), DataSet< DATA >::isConsistent(), DataSet< DATA >::num(), DataSet< DATA >::operator=(), DataSet< DATA >::operator[](), and DataSet< DATA >::remove().
|
protected |
highest used element in theitem
Definition at line 119 of file dataset.h.
Referenced by DataSet< DATA >::clear(), DataSet< DATA >::create(), DataSet< DATA >::isConsistent(), DataSet< DATA >::operator=(), DataSet< DATA >::operator[](), DataSet< DATA >::remove(), and DataSet< DATA >::size().