Set of strings. More...
#include <nameset.h>
Classes | |
class | Name |
Handles of names in a NameSet. More... | |
Public Member Functions | |
Inquiry | |
const char * | operator[] (int pnum) const |
returns num 'th name of NameSet. More... | |
const char * | operator[] (const DataKey &pkey) const |
returns name for DataKey pkey of NameSet. More... | |
int | num () const |
returns nr. of names in NameSet. More... | |
int | max () const |
returns maximum nr. of names that fit into NameSet. More... | |
int | size () const |
returns maximum DataKey::idx used in NameSet. More... | |
int | memMax () const |
returns maximum length of string memory. More... | |
int | memSize () const |
returns used length of string memory. More... | |
DataKey | key (int pnum) const |
returns DataKey of the pnum 'th name in NameSet. More... | |
DataKey | key (const char *str) const |
returns DataKey of name str in NameSet. More... | |
int | number (const DataKey &pkey) const |
returns number of name with DataKey pkey in NameSet. More... | |
int | number (const char *str) const |
returns number of name str in NameSet. More... | |
bool | has (int pnum) const |
does NameSet has a name with number pnum ? More... | |
bool | has (const char *str) const |
does NameSet has a name str ? More... | |
bool | has (const DataKey &pkey) const |
does NameSet has a name with DataKey pkey ? More... | |
Extension | |
void | add (const char *str) |
void | add (DataKey &key, const char *str) |
adds name str to NameSet. More... | |
void | add (const NameSet &set) |
void | add (DataKey key[], const NameSet &nset) |
adds all names in set to NameSet. More... | |
Shrinking | |
void | remove (const DataKey &key) |
removes name with DataKey key from NameSet. More... | |
void | remove (int pnum) |
removes pnum 'th name from NameSet. More... | |
void | remove (const char *str) |
removes name str from NameSet. More... | |
void | remove (const DataKey keys[], int n) |
removes n names with DataKeys keys from NameSet. More... | |
void | remove (const int nums[], int n) |
removes n names with numbers nums from NameSet. More... | |
void | remove (int dstat[]) |
remove all entries where dstat is less than zero. More... | |
void | clear () |
removes all names from NameSet. More... | |
Memory Control | |
void | reMax (int newmax=0) |
resets max() to newmax . More... | |
void | memRemax (int newmax=0) |
resets memMax() to newmax . More... | |
void | memPack () |
garbage collection. More... | |
Miscellaneous | |
bool | isConsistent () const |
consistency check. More... | |
Constructors / Destructors | |
NameSet (int max=10000, int mmax=-1, Real fac=2, Real memFac=2) | |
default constructor. More... | |
~NameSet () | |
destructor. More... | |
Public Attributes | |
Control Parameters | |
Real | factor |
memory extension factor for entries. More... | |
Real | memFactor |
memory extension factor for names. More... | |
Private Member Functions | |
Blocked | |
NameSet (const NameSet &old) | |
copy constructor. More... | |
NameSet & | operator= (const NameSet &rhs) |
assignment operator. More... | |
Private Attributes | |
Data | |
DataSet< int > | set |
name set. More... | |
char * | mem |
string memory More... | |
int | memmax |
size of string memory More... | |
int | memused |
size of used string memory More... | |
DataHashTable< Name, DataKey > | hashtab |
hashtable for names More... | |
Set of strings.
Class NameSet implements a symbol or name table. It allows to store or remove names (i.e., char*
), but does not provide means for manipulating stored names.
Names in a NameSet may be accessed via numbers from 0 through num()-1 and via DataKeys. See DataSet for a description of these concepts.
At a time a NameSet can hold a maximum of max() entries. This can be reset with method reMax(). If more than max() names are added to a NameSet, it adjusts itself automatically to the required size. This implies, that references to names within a NameSet may become invalid if the NameSet is expanded.
All names (i.e., the actual char strings) in a NameSet are stored in one continuous memory block of size memMax(). At one time memSize() bytes of it are used for actually saving names; the remaining memory is free to hold additional names. memRemax() can be used to reset memMax() but not lower than to memSize(). Method memPack() performs a garbage collection to gain free memory resulting from removed names.
default constructor.
max | start value for max() |
mmax | start value for memMax() |
fac | start value for factor |
memFac | start value for memFactor |
Definition at line 216 of file nameset.cpp.
References DataSet< DATA >::max(), NameSet::mem, NameSet::memmax, NameSet::memused, NameSet::set, and soplex::spx_alloc().
~NameSet | ( | ) |
destructor.
Definition at line 228 of file nameset.cpp.
References NameSet::mem, and soplex::spx_free().
void add | ( | const char * | str | ) |
void add | ( | const NameSet & | set | ) |
Definition at line 75 of file nameset.cpp.
References NameSet::add(), NameSet::hashtab, and NameSet::num().
void add | ( | DataKey & | key, |
const char * | str | ||
) |
adds name str
to NameSet.
Definition at line 40 of file nameset.cpp.
References DataSet< DATA >::create(), NameSet::factor, NameSet::hashtab, NameSet::max(), NameSet::mem, NameSet::memFactor, NameSet::memMax(), NameSet::memPack(), NameSet::memRemax(), NameSet::memSize(), NameSet::memused, NameSet::reMax(), NameSet::set, NameSet::size(), SOPLEX_HASHTABLE_FILLFACTOR, SPX_MAXSTRLEN, and soplex::spxSnprintf().
adds all names in set
to NameSet.
Definition at line 86 of file nameset.cpp.
References NameSet::add(), NameSet::hashtab, and NameSet::num().
void clear | ( | ) |
removes all names from NameSet.
Definition at line 146 of file nameset.cpp.
References DataSet< DATA >::clear(), NameSet::hashtab, NameSet::memused, and NameSet::set.
bool has | ( | const char * | str | ) | const |
bool has | ( | const DataKey & | pkey | ) | const |
does NameSet has a name with DataKey pkey
?
Definition at line 262 of file nameset.h.
References DataSet< DATA >::has(), and NameSet::set.
bool has | ( | int | pnum | ) | const |
does NameSet has a name with number pnum
?
Definition at line 249 of file nameset.h.
References DataSet< DATA >::has(), and NameSet::set.
Referenced by NameSet::isConsistent(), and NameSet::remove().
bool isConsistent | ( | ) | const |
consistency check.
Definition at line 233 of file nameset.cpp.
References NameSet::has(), NameSet::hashtab, DataSet< DATA >::isConsistent(), NameSet::key(), NameSet::mem, NameSet::memmax, NameSet::memused, NameSet::num(), NameSet::set, and SPX_MSG_INCONSISTENT.
Referenced by NameSet::remove().
DataKey key | ( | const char * | str | ) | const |
returns DataKey of name str
in NameSet.
Definition at line 221 of file nameset.h.
References NameSet::hashtab.
DataKey key | ( | int | pnum | ) | const |
returns DataKey of the pnum
'th name in NameSet.
Definition at line 215 of file nameset.h.
References DataSet< DATA >::key(), and NameSet::set.
Referenced by NameSet::isConsistent(), NameSet::memPack(), NameSet::memRemax(), soplex::operator<<(), and NameSet::remove().
int max | ( | ) | const |
returns maximum nr. of names that fit into NameSet.
Definition at line 191 of file nameset.h.
References DataSet< DATA >::max(), and NameSet::set.
Referenced by NameSet::add().
int memMax | ( | ) | const |
returns maximum length of string memory.
Definition at line 203 of file nameset.h.
References NameSet::memmax.
Referenced by NameSet::add(), and NameSet::memPack().
void memPack | ( | ) |
garbage collection.
Definition at line 170 of file nameset.cpp.
References NameSet::hashtab, NameSet::key(), NameSet::mem, NameSet::memMax(), NameSet::memSize(), NameSet::memused, NameSet::num(), NameSet::set, soplex::spx_alloc(), soplex::spx_free(), SPX_MAXSTRLEN, and soplex::spxSnprintf().
Referenced by NameSet::add().
void memRemax | ( | int | newmax = 0 | ) |
resets memMax() to newmax
.
Definition at line 159 of file nameset.cpp.
References NameSet::hashtab, NameSet::key(), NameSet::mem, NameSet::memmax, NameSet::memSize(), NameSet::num(), NameSet::set, and soplex::spx_realloc().
Referenced by NameSet::add().
int memSize | ( | ) | const |
returns used length of string memory.
Definition at line 209 of file nameset.h.
References NameSet::memused.
Referenced by NameSet::add(), NameSet::memPack(), and NameSet::memRemax().
int num | ( | ) | const |
returns nr. of names in NameSet.
Definition at line 185 of file nameset.h.
References DataSet< DATA >::num(), and NameSet::set.
Referenced by NameSet::add(), NameSet::isConsistent(), NameSet::memPack(), NameSet::memRemax(), and soplex::operator<<().
int number | ( | const char * | str | ) | const |
returns number of name str
in NameSet.
Definition at line 235 of file nameset.h.
References NameSet::hashtab, and NameSet::number().
int number | ( | const DataKey & | pkey | ) | const |
returns number of name with DataKey pkey
in NameSet.
Definition at line 229 of file nameset.h.
References DataSet< DATA >::number(), and NameSet::set.
Referenced by NameSet::number().
const char * operator[] | ( | const DataKey & | pkey | ) | const |
returns name for DataKey pkey
of NameSet.
Definition at line 179 of file nameset.h.
References NameSet::mem, and NameSet::set.
const char * operator[] | ( | int | pnum | ) | const |
returns num
'th name of NameSet.
Definition at line 173 of file nameset.h.
References NameSet::mem, and NameSet::set.
void reMax | ( | int | newmax = 0 | ) |
resets max() to newmax
.
Definition at line 153 of file nameset.cpp.
References NameSet::hashtab, DataSet< DATA >::reMax(), and NameSet::set.
Referenced by NameSet::add().
void remove | ( | const char * | str | ) |
removes name str
from NameSet.
Definition at line 97 of file nameset.cpp.
References NameSet::hashtab, DataSet< DATA >::remove(), and NameSet::set.
void remove | ( | const DataKey & | key | ) |
removes name with DataKey key
from NameSet.
Definition at line 110 of file nameset.cpp.
References NameSet::has(), NameSet::hashtab, NameSet::mem, DataSet< DATA >::remove(), and NameSet::set.
Referenced by NameSet::remove().
void remove | ( | const DataKey | keys[], |
int | n | ||
) |
removes n
names with DataKeys keys
from NameSet.
Definition at line 118 of file nameset.cpp.
References NameSet::remove().
void remove | ( | const int | nums[], |
int | n | ||
) |
removes n
names with numbers nums
from NameSet.
Definition at line 124 of file nameset.cpp.
References NameSet::remove().
void remove | ( | int | dstat[] | ) |
remove all entries where dstat
is less than zero.
Definition at line 130 of file nameset.cpp.
References NameSet::hashtab, NameSet::isConsistent(), NameSet::mem, DataSet< DATA >::num(), DataSet< DATA >::remove(), and NameSet::set.
void remove | ( | int | pnum | ) |
removes pnum
'th name from NameSet.
Definition at line 290 of file nameset.h.
References NameSet::key(), and NameSet::remove().
int size | ( | ) | const |
returns maximum DataKey::idx used in NameSet.
Definition at line 197 of file nameset.h.
References NameSet::set, and DataSet< DATA >::size().
Referenced by NameSet::add().
Real factor |
memory extension factor for entries.
When more than max() names are added to a NameSet, it is automatically resized to fit the additional names. Parameter factor
is the factor by which the element memory is extended to do so.
Definition at line 335 of file nameset.h.
Referenced by NameSet::add().
|
private |
hashtable for names
Every name in a NameSet is assigned a DataKey by which it can be accessed (see NameSet::operator[]()). See DataKey for a more detailed description of the concept of Keys.
Definition at line 164 of file nameset.h.
Referenced by NameSet::add(), NameSet::clear(), NameSet::has(), NameSet::isConsistent(), NameSet::key(), NameSet::memPack(), NameSet::memRemax(), NameSet::number(), NameSet::reMax(), and NameSet::remove().
|
private |
string memory
Definition at line 157 of file nameset.h.
Referenced by NameSet::add(), NameSet::isConsistent(), NameSet::memPack(), NameSet::memRemax(), NameSet::NameSet(), NameSet::operator[](), NameSet::remove(), and NameSet::~NameSet().
Real memFactor |
memory extension factor for names.
When the names added to a NameSet do no longer fit into the name memory (i.e. the memory for saving the strings), it is automatically resized to fit the additional names. Parameter memFactor
is the factor by which this memory is extended to do so.
Definition at line 343 of file nameset.h.
Referenced by NameSet::add().
|
private |
size of string memory
Definition at line 158 of file nameset.h.
Referenced by NameSet::isConsistent(), NameSet::memMax(), NameSet::memRemax(), and NameSet::NameSet().
|
private |
size of used string memory
Definition at line 159 of file nameset.h.
Referenced by NameSet::add(), NameSet::clear(), NameSet::isConsistent(), NameSet::memPack(), NameSet::memSize(), and NameSet::NameSet().
|
private |
name set.
Definition at line 156 of file nameset.h.
Referenced by NameSet::add(), NameSet::clear(), NameSet::has(), NameSet::isConsistent(), NameSet::key(), NameSet::max(), NameSet::memPack(), NameSet::memRemax(), NameSet::NameSet(), NameSet::num(), NameSet::number(), NameSet::operator[](), NameSet::reMax(), NameSet::remove(), and NameSet::size().