ROSE 0.11.145.192
|
One-to-one mapping between source and target values.
This container holds a one-to-one mapping from values in a domain to values in a range and can look up values in the forward or reverse direction in log time. It does so by consistently maintaining two maps: a forward map and a reverse map. The forward map maps values in the domain to values in the range, while the reverse map goes the other direction. The forward and reverse methods return const references to these maps. The BiMap container provides methods for modifying the mapping.
#include <Sawyer/BiMap.h>
Public Types | |
typedef S | Source |
Type of values in the domain. | |
typedef T | Target |
Type of values in the range. | |
typedef Sawyer::Container::Map< Source, Target > | Forward |
Type for domain-to-range map. | |
typedef Sawyer::Container::Map< Target, Source > | Reverse |
Type for range-to-domain map. | |
Public Member Functions | |
BiMap () | |
Default constructor. | |
BiMap (const BiMap &other) | |
Copy constructor. | |
template<class U > | |
BiMap (const BiMap< Source, U > &a, const BiMap< U, Target > &b) | |
Construct a new map by composition of two maps. | |
void | clear () |
Erase all mappings. | |
bool | eraseSource (const Source &source) |
Erase domain value and its associated range value. | |
bool | eraseTarget (const Target &target) |
Erase range value and its associated domain value. | |
bool | erase (const Source &source, const Target &target) |
Erase a specific map entry. | |
void | insert (const Source &source, const Target &target) |
Insert a new mapping. | |
const Forward & | forward () const |
Return forward mapping. | |
const Reverse & | reverse () const |
Return reverse mapping. | |
typedef S Sawyer::Container::BiMap< S, T >::Source |
typedef T Sawyer::Container::BiMap< S, T >::Target |
typedef Sawyer::Container::Map<Source, Target> Sawyer::Container::BiMap< S, T >::Forward |
typedef Sawyer::Container::Map<Target, Source> Sawyer::Container::BiMap< S, T >::Reverse |
|
inline |
|
inline |
Construct a new map by composition of two maps.
Given two BiMap objects where the range type of the first is the domain type of the second, construct a new BiMap from the domain of the first to the range of the second. The new map will contain only those domain/range pairs that map across both input maps.
Definition at line 50 of file BiMap.h.
References Sawyer::Container::Map< K, T, Cmp, Alloc >::exists(), Sawyer::Container::Map< K, T, Cmp, Alloc >::insert(), and Sawyer::Container::Map< K, T, Cmp, Alloc >::nodes().
|
inline |
Erase all mappings.
This results in a map whose state is the same as a default-constructed BiMap.
Definition at line 63 of file BiMap.h.
References Sawyer::Container::Map< K, T, Cmp, Alloc >::clear().
|
inline |
Erase domain value and its associated range value.
If source
exists in this map's domain, then it is removed along with the corresponding value in the range. Otherwise the map is not modified. Returns true if the map was modified, false if not.
Definition at line 72 of file BiMap.h.
References Sawyer::Container::Map< K, T, Cmp, Alloc >::erase(), and Sawyer::Container::Map< K, T, Cmp, Alloc >::exists().
Referenced by Sawyer::Container::BiMap< S, T >::insert().
|
inline |
Erase range value and its associated domain value.
If target
exists in this map's range, then it is removed along with the corresponding value in the domain. Otherwise the map is not modified. Returns true if the map was modified, false if not.
Definition at line 84 of file BiMap.h.
References Sawyer::Container::Map< K, T, Cmp, Alloc >::erase(), and Sawyer::Container::Map< K, T, Cmp, Alloc >::exists().
Referenced by Sawyer::Container::BiMap< S, T >::insert().
|
inline |
Erase a specific map entry.
Erases the 1:1 mapping between source
and target
if present. This is a no-op unless source
is a member of the domain and target
is a member of the range and source
maps to target
(and vice versa). Returns true if the map was modified, false if not.
Definition at line 97 of file BiMap.h.
References Sawyer::Container::Map< K, T, Cmp, Alloc >::erase(), and Sawyer::Container::Map< K, T, Cmp, Alloc >::exists().
|
inline |
Insert a new mapping.
Creates a new mapping from source
in the domain to target
in the range. If source
is already a member of the domain then it is first erased along with its corresponding value in the range; likewise, if target
is already a member of the range then it is first erased along with its corresponding value in the domain.
Definition at line 110 of file BiMap.h.
References Sawyer::Container::BiMap< S, T >::eraseSource(), Sawyer::Container::BiMap< S, T >::eraseTarget(), and Sawyer::Container::Map< K, T, Cmp, Alloc >::insert().
|
inline |
|
inline |