ROSE  0.11.96.11
Public Types | Public Member Functions | List of all members
Sawyer::Container::BiMap< S, T > Class Template Reference

Description

template<class S, class T>
class Sawyer::Container::BiMap< S, T >

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.

Definition at line 26 of file BiMap.h.

#include <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, TargetForward
 Type for domain-to-range map.
 
typedef Sawyer::Container::Map< Target, SourceReverse
 Type for range-to-domain map.
 

Public Member Functions

 BiMap ()
 Default constructor. More...
 
 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. More...
 
void clear ()
 Erase all mappings. More...
 
bool eraseSource (const Source &source)
 Erase domain value and its associated range value. More...
 
bool eraseTarget (const Target &target)
 Erase range value and its associated domain value. More...
 
bool erase (const Source &source, const Target &target)
 Erase a specific map entry. More...
 
void insert (const Source &source, const Target &target)
 Insert a new mapping. More...
 
const Forwardforward () const
 Return forward mapping. More...
 
const Reversereverse () const
 Return reverse mapping. More...
 

Constructor & Destructor Documentation

◆ BiMap() [1/2]

template<class S , class T >
Sawyer::Container::BiMap< S, T >::BiMap ( )
inline

Default constructor.

Constructs an empty mapping.

Definition at line 39 of file BiMap.h.

◆ BiMap() [2/2]

template<class S , class T >
template<class U >
Sawyer::Container::BiMap< S, T >::BiMap ( const BiMap< Source, U > &  a,
const BiMap< U, Target > &  b 
)
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().

Here is the call graph for this function:

Member Function Documentation

◆ clear()

template<class S , class T >
void Sawyer::Container::BiMap< S, T >::clear ( )
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().

Here is the call graph for this function:

◆ eraseSource()

template<class S , class T >
bool Sawyer::Container::BiMap< S, T >::eraseSource ( const Source source)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eraseTarget()

template<class S , class T >
bool Sawyer::Container::BiMap< S, T >::eraseTarget ( const Target target)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erase()

template<class S , class T >
bool Sawyer::Container::BiMap< S, T >::erase ( const Source source,
const Target target 
)
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().

Here is the call graph for this function:

◆ insert()

template<class S , class T >
void Sawyer::Container::BiMap< S, T >::insert ( const Source source,
const Target target 
)
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().

Here is the call graph for this function:

◆ forward()

template<class S , class T >
const Forward& Sawyer::Container::BiMap< S, T >::forward ( ) const
inline

Return forward mapping.

The keys of the forward map are values in the domain, and its values are in the range.

Definition at line 120 of file BiMap.h.

◆ reverse()

template<class S , class T >
const Reverse& Sawyer::Container::BiMap< S, T >::reverse ( ) const
inline

Return reverse mapping.

The keys of the reverse map are values in the range, and its values are in the domain.

Definition at line 127 of file BiMap.h.


The documentation for this class was generated from the following file: