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.
More...
#include <nameset.h>
Classes | |
class | Name |
Handles of names in a NameSet.Class Name provides the handles (i.e., char*s) 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 207 of file nameset.cpp.
References NameSet::max(), NameSet::mem, NameSet::memmax, NameSet::memused, and soplex::spx_alloc().
~NameSet | ( | ) |
destructor.
Definition at line 219 of file nameset.cpp.
References NameSet::mem, and soplex::spx_free().
void add | ( | const char * | str | ) |
Definition at line 25 of file nameset.cpp.
Referenced by NameSet::add(), and NameSet::has().
void add | ( | DataKey & | key, |
const char * | str | ||
) |
adds name str
to NameSet.
Definition at line 31 of file nameset.cpp.
References NameSet::factor, NameSet::hashtab, HASHTABLE_FILLFACTOR, NameSet::max(), NameSet::mem, NameSet::memFactor, NameSet::memMax(), NameSet::memPack(), NameSet::memRemax(), NameSet::memSize(), NameSet::memused, NameSet::reMax(), NameSet::size(), SPX_MAXSTRLEN, and soplex::spxSnprintf().
void add | ( | const NameSet & | set | ) |
Definition at line 66 of file nameset.cpp.
References NameSet::add(), NameSet::hashtab, and NameSet::num().
adds all names in set
to NameSet.
Definition at line 77 of file nameset.cpp.
References NameSet::add(), NameSet::hashtab, and NameSet::num().
void clear | ( | ) |
removes all names from NameSet.
Definition at line 137 of file nameset.cpp.
References NameSet::hashtab, and NameSet::memused.
Referenced by NameSet::remove().
bool has | ( | int | pnum | ) | const |
does NameSet has a name with number pnum
?
Definition at line 238 of file nameset.h.
Referenced by NameSet::isConsistent(), and NameSet::remove().
bool has | ( | const char * | str | ) | const |
does NameSet has a name str
?
Definition at line 244 of file nameset.h.
References DataHashTable< HashItem, Info >::has().
bool has | ( | const DataKey & | pkey | ) | const |
does NameSet has a name with DataKey pkey
?
Definition at line 251 of file nameset.h.
References NameSet::add(), and NameSet::key().
bool isConsistent | ( | ) | const |
consistency check.
Definition at line 224 of file nameset.cpp.
References NameSet::has(), NameSet::hashtab, NameSet::key(), NameSet::mem, NameSet::memmax, NameSet::memused, MSGinconsistent, and NameSet::num().
Referenced by NameSet::remove().
DataKey key | ( | int | pnum | ) | const |
returns DataKey of the pnum
'th name in NameSet.
Definition at line 204 of file nameset.h.
Referenced by NameSet::has(), NameSet::isConsistent(), NameSet::memPack(), NameSet::memRemax(), soplex::operator<<(), and NameSet::remove().
DataKey key | ( | const char * | str | ) | const |
returns DataKey of name str
in NameSet.
Definition at line 210 of file nameset.h.
References DataHashTable< HashItem, Info >::get().
int max | ( | ) | const |
returns maximum nr. of names that fit into NameSet.
Definition at line 180 of file nameset.h.
Referenced by NameSet::add(), and NameSet::NameSet().
int memMax | ( | ) | const |
returns maximum length of string memory.
Definition at line 192 of file nameset.h.
References NameSet::memmax.
Referenced by NameSet::add(), and NameSet::memPack().
void memPack | ( | ) |
garbage collection.
Definition at line 161 of file nameset.cpp.
References NameSet::hashtab, NameSet::key(), NameSet::mem, NameSet::memMax(), NameSet::memSize(), NameSet::memused, NameSet::num(), soplex::spx_alloc(), soplex::spx_free(), SPX_MAXSTRLEN, and soplex::spxSnprintf().
Referenced by NameSet::add(), and NameSet::remove().
void memRemax | ( | int | newmax = 0 | ) |
resets memMax() to newmax
.
Definition at line 150 of file nameset.cpp.
References NameSet::hashtab, NameSet::key(), NameSet::mem, NameSet::memmax, NameSet::memSize(), NameSet::num(), and soplex::spx_realloc().
Referenced by NameSet::add(), and NameSet::remove().
int memSize | ( | ) | const |
returns used length of string memory.
Definition at line 198 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 174 of file nameset.h.
Referenced by NameSet::add(), NameSet::isConsistent(), NameSet::memPack(), NameSet::memRemax(), and soplex::operator<<().
int number | ( | const DataKey & | pkey | ) | const |
returns number of name with DataKey pkey
in NameSet.
Definition at line 218 of file nameset.h.
Referenced by NameSet::number().
int number | ( | const char * | str | ) | const |
returns number of name str
in NameSet.
Definition at line 224 of file nameset.h.
References DataHashTable< HashItem, Info >::get(), DataHashTable< HashItem, Info >::has(), and NameSet::number().
const char* operator[] | ( | int | pnum | ) | const |
const char* operator[] | ( | const DataKey & | pkey | ) | const |
void reMax | ( | int | newmax = 0 | ) |
resets max() to newmax
.
Definition at line 144 of file nameset.cpp.
References NameSet::hashtab.
Referenced by NameSet::add(), and NameSet::remove().
void remove | ( | const DataKey & | key | ) |
removes name with DataKey key
from NameSet.
Definition at line 101 of file nameset.cpp.
References NameSet::has(), NameSet::hashtab, and NameSet::mem.
void remove | ( | int | pnum | ) |
removes pnum
'th name from NameSet.
Definition at line 279 of file nameset.h.
References NameSet::clear(), NameSet::key(), NameSet::memPack(), NameSet::memRemax(), and NameSet::reMax().
void remove | ( | const char * | str | ) |
removes name str
from NameSet.
Definition at line 88 of file nameset.cpp.
References NameSet::hashtab.
void remove | ( | const DataKey | keys[], |
int | n | ||
) |
removes n
names with DataKeys keys
from NameSet.
Definition at line 109 of file nameset.cpp.
void remove | ( | const int | nums[], |
int | n | ||
) |
removes n
names with numbers nums
from NameSet.
Definition at line 115 of file nameset.cpp.
void remove | ( | int | dstat[] | ) |
remove all entries where dstat
is less than zero.
Definition at line 121 of file nameset.cpp.
References NameSet::hashtab, NameSet::isConsistent(), and NameSet::mem.
int size | ( | ) | const |
returns maximum DataKey::idx used in NameSet.
Definition at line 186 of file nameset.h.
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 324 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 153 of file nameset.h.
Referenced by NameSet::add(), NameSet::clear(), NameSet::isConsistent(), NameSet::memPack(), NameSet::memRemax(), NameSet::reMax(), and NameSet::remove().
|
private |
string memory
Definition at line 146 of file nameset.h.
Referenced by NameSet::add(), NameSet::isConsistent(), NameSet::memPack(), NameSet::memRemax(), NameSet::NameSet(), 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 332 of file nameset.h.
Referenced by NameSet::add().
|
private |
size of string memory
Definition at line 147 of file nameset.h.
Referenced by NameSet::isConsistent(), NameSet::memMax(), NameSet::memRemax(), and NameSet::NameSet().
|
private |
size of used string memory
Definition at line 148 of file nameset.h.
Referenced by NameSet::add(), NameSet::clear(), NameSet::isConsistent(), NameSet::memPack(), NameSet::memSize(), and NameSet::NameSet().