Grafalgo
Library of useful data structures and algorithms
|
Data structure that assigns small integer identifiers to large keys. More...
#include <IdMap.h>
Public Member Functions | |
IdMap (int) | |
Constructor for IdMap, allocates space and initializes table. | |
~IdMap () | |
Destructor for IdMap. | |
void | clear () |
Remove all elements from map. | |
void | resize (int) |
Resize a IdMap object. | |
void | expand (int) |
Expand the space available for this IdMap. | |
void | copyFrom (const IdMap &) |
Copy into this from source. | |
int | firstId () const |
Get the first assigned identifier, in some arbitrary order. | |
int | nextId (int) const |
Get the next assigned identifier, in some arbitrary order. | |
int | size () const |
The size of the mapping. | |
int | getId (uint64_t) const |
Get the id for a given key. | |
uint64_t | getKey (int) const |
Get the key that was mapped to the given identifier. | |
int | addPair (uint64_t) |
Add a new key->id pair. | |
int | addPair (uint64_t, int) |
Add a new key->id pair. | |
void | dropPair (uint64_t) |
Remove a pair from the mapping. | |
bool | validKey (uint64_t) const |
Determine if a given key has been mapped to an identfier. | |
bool | validId (int) const |
Determine if a given identifier has been assigned to a key. | |
string & | toString (string &) const |
Create a string representation of the IdMap. | |
Private Member Functions | |
void | makeSpace (int) |
Allocate and initialize space for list. | |
void | freeSpace () |
Free dynamic storage used by list. | |
Private Attributes | |
HashTbl * | ht |
SetPair * | ids |
Static Private Attributes | |
static const int | MAXID = (1 << 20)-1 |
largest possible identifier |
Data structure that assigns small integer identifiers to large keys.
This is useful in contexts where the "natural identifiers" in an application can vary over a large range, but the number of distinct identifiers that are in use at one time is relatively small. This data structure can be used to map the "natural identfiers" into integers in a restricted range 1..max, where max is specified when the data structure is initialized.
grafalgo::IdMap::IdMap | ( | int | n1 | ) |
grafalgo::IdMap::~IdMap | ( | ) |
int grafalgo::IdMap::addPair | ( | uint64_t | key | ) |
int grafalgo::IdMap::addPair | ( | uint64_t | key, |
int | id | ||
) |
Add a new key->id pair.
key | is the key for which an id is required |
id | is the requested id that the key is to be mapped to |
Definition at line 95 of file IdMap.cpp.
void grafalgo::IdMap::clear | ( | ) | [virtual] |
Remove all elements from map.
Implements grafalgo::Adt.
Definition at line 64 of file IdMap.cpp.
void grafalgo::IdMap::copyFrom | ( | const IdMap & | source | ) |
void grafalgo::IdMap::dropPair | ( | uint64_t | key | ) |
void grafalgo::IdMap::expand | ( | int | size | ) | [virtual] |
Expand the space available for this IdMap.
Rebuilds old value in new space.
size | is the size of the resized object. |
Implements grafalgo::Adt.
Definition at line 57 of file IdMap.cpp.
int grafalgo::IdMap::firstId | ( | ) | const [inline] |
void grafalgo::IdMap::freeSpace | ( | ) | [private] |
int grafalgo::IdMap::getId | ( | uint64_t | key | ) | const [inline] |
uint64_t grafalgo::IdMap::getKey | ( | int | id | ) | const [inline] |
void grafalgo::IdMap::makeSpace | ( | int | size | ) | [private] |
int grafalgo::IdMap::nextId | ( | int | id | ) | const [inline] |
void grafalgo::IdMap::resize | ( | int | size | ) | [virtual] |
Resize a IdMap object.
The old value is discarded.
size | is the size of the resized object. |
Implements grafalgo::Adt.
Definition at line 45 of file IdMap.cpp.
int grafalgo::IdMap::size | ( | ) | const [inline] |
string & grafalgo::IdMap::toString | ( | string & | s | ) | const [virtual] |
Create a string representation of the IdMap.
s | is the string in which the result is returned. |
Implements grafalgo::Adt.
Definition at line 113 of file IdMap.cpp.
bool grafalgo::IdMap::validId | ( | int | id | ) | const [inline] |
bool grafalgo::IdMap::validKey | ( | uint64_t | key | ) | const [inline] |