SoPlex
|
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. | |
void | add (const DATA &item) |
adds element item . | |
void | add (DataKey newkey[], const DATA *item, int n) |
add several items. | |
void | add (const DATA *items, int n) |
adds n elements from items . | |
void | add (DataKey newkey[], const DataSet< DATA > &set) |
adds several new items. | |
void | add (const DataSet< DATA > &set) |
adds all elements of set . | |
DATA * | create (DataKey &newkey) |
creates new data element in DataSet. | |
DATA * | create () |
creates new (uninitialized) data element in DataSet. | |
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 int* perm, which returns the new order after the removal: If perm[i] < 0, the element numbered i prior to the removal operation has been removed from the set. Otherwise, perm[i] = j >= 0 means that the element with number i prior to the removal operation has been renumbered to j. Removing a single element from a DataSet yields a simple renumbering of the elements: The last element in the set (i.e., element num()-1) is moved to the index of the removed element. | |
void | remove (int removenum) |
removes the removenum 'th element. | |
void | remove (const DataKey &removekey) |
removes element with key removekey . | |
void | remove (int perm[]) |
remove multiple elements. | |
void | remove (const DataKey *keys, int n, int *perm) |
remove n elements given by keys and perm . | |
void | remove (const DataKey *keys, int n) |
remove n elements given by keys . | |
void | remove (const int *nums, int n, int *perm) |
remove n elements given by nums and perm . | |
void | remove (const int *nums, int n) |
remove n elements with numbers nums . | |
void | clear () |
remove all elements. | |
Access | |
DATA & | operator[] (int n) |
const DATA & | operator[] (int n) const |
returns element number n . | |
DATA & | operator[] (const DataKey &k) |
const DATA & | operator[] (const DataKey &k) const |
returns element with DataKey k . | |
Inquiry | |
int | max () const |
returns maximum number of elements that would fit into DataSet. | |
int | num () const |
returns number of elements currently in DataSet. | |
int | size () const |
returns the maximum DataKey::idx currently in DataSet. | |
DataKey | key (int n) const |
returns DataKey of n 'th element in DataSet. | |
DataKey | key (const DATA *item) const |
returns DataKey of element item in 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. | |
int | number (const DATA *item) const |
returns the number of element item in DataSet, throws exception if it doesn't exist. | |
bool | has (const DataKey &k) const |
Is k a valid DataKey of an element in DataSet? | |
bool | has (int n) const |
Is n a valid number of an element in DataSet? | |
bool | has (const DATA *item) const |
Does item belong to DataSet? | |
Miscellaneous | |
ptrdiff_t | reMax (int newmax=0) |
resets max() to newmax . | |
bool | isConsistent () const |
consistency check. | |
Constructors / Destructors | |
DataSet (int pmax=8) | |
default constructor. | |
DataSet (const DataSet &old) | |
copy constructor. | |
DataSet< DATA > & | operator= (const DataSet< DATA > &rhs) |
assignment operator. | |
~DataSet () | |
destructor. |
Protected Attributes | |
Types | |
struct soplex::DataSet::Item * | theitem |
array of elements in the DataSet | |
Data | |
DataKey * | thekey |
DataKey::idx's of elements. | |
int | themax |
length of arrays theitem and thekey | |
int | thesize |
highest used element in theitem | |
int | thenum |
number of elements in DataSet | |
int | firstfree |
first unused element in theitem |
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 firstfree, isConsistent(), soplex::spx_alloc(), soplex::spx_free(), theitem, thekey, themax, thenum, and thesize.
Referenced by DataSet().
copy constructor.
Definition at line 571 of file dataset.h.
References DataSet(), firstfree, isConsistent(), soplex::spx_alloc(), soplex::spx_free(), theitem, thekey, themax, thenum, and thesize.
~DataSet | ( | ) |
destructor.
Definition at line 646 of file dataset.h.
References soplex::spx_free(), theitem, and thekey.
void add | ( | const DATA & | item | ) |
void add | ( | const DATA * | items, |
int | n ) |
void add | ( | const DataSet< DATA > & | set | ) |
void add | ( | DataKey & | newkey, |
const DATA & | item ) |
void add | ( | DataKey | newkey[], |
const DATA * | item, | ||
int | n ) |
void clear | ( | ) |
DATA * create | ( | ) |
DATA * create | ( | DataKey & | newkey | ) |
bool has | ( | const DATA * | item | ) | const |
bool has | ( | const DataKey & | k | ) | const |
bool has | ( | int | n | ) | const |
bool isConsistent | ( | ) | const |
DataKey key | ( | const DATA * | item | ) | const |
DataKey key | ( | int | n | ) | const |
int max | ( | ) | const |
int num | ( | ) | const |
int number | ( | const DATA * | item | ) | const |
int number | ( | const DataKey & | k | ) | const |
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 clear(), firstfree, DataSet< DATA >::Item::info, isConsistent(), max(), num(), reMax(), size(), theitem, thekey, themax, thenum, and thesize.
DATA & operator[] | ( | const DataKey & | k | ) |
Definition at line 381 of file dataset.h.
References DataKey::idx, theitem, and thesize.
const DATA & operator[] | ( | const DataKey & | k | ) | const |
DATA & operator[] | ( | int | n | ) |
const DATA & operator[] | ( | int | n | ) | const |
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 firstfree, size(), soplex::spx_realloc(), theitem, thekey, and themax.
Referenced by operator=().
void remove | ( | const DataKey & | removekey | ) |
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(), num(), and remove().
void remove | ( | const DataKey * | keys, |
int | n, | ||
int * | perm ) |
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(), num(), and remove().
void remove | ( | const int * | nums, |
int | n, | ||
int * | perm ) |
void remove | ( | int | perm[] | ) |
void remove | ( | int | removenum | ) |
int size | ( | ) | const |
returns the maximum DataKey::idx currently in DataSet.
Definition at line 410 of file dataset.h.
References thesize.
Referenced by number(), number(), operator=(), and reMax().
|
protected |
|
protected |
array of elements in the DataSet
Referenced by create(), DataSet(), DataSet(), has(), isConsistent(), number(), number(), operator=(), operator[](), operator[](), operator[](), operator[](), reMax(), remove(), remove(), and ~DataSet().
|
protected |
DataKey::idx's of elements.
Definition at line 117 of file dataset.h.
Referenced by create(), DataSet(), DataSet(), isConsistent(), key(), key(), operator=(), operator[](), operator[](), reMax(), remove(), remove(), and ~DataSet().
|
protected |
length of arrays theitem and thekey
Definition at line 118 of file dataset.h.
Referenced by clear(), create(), DataSet(), DataSet(), isConsistent(), max(), operator=(), and reMax().
|
protected |
number of elements in DataSet
Definition at line 120 of file dataset.h.
Referenced by clear(), create(), DataSet(), DataSet(), isConsistent(), num(), operator=(), operator[](), operator[](), remove(), and remove().
|
protected |
highest used element in theitem
Definition at line 119 of file dataset.h.
Referenced by clear(), create(), DataSet(), DataSet(), isConsistent(), operator=(), operator[](), operator[](), remove(), and size().