ModErn Text Analysis
META Enumerates Textual Applications
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
meta::util::invertible_map< Key, Value > Class Template Reference

This data structure indexes by keys as well as values, allowing constant amortized lookup time by key or value. More...

#include <invertible_map.h>

Classes

class  Iterator
 The invertible_map iterator is really just a wrapper for the forward (key -> value) unordered_map iterator. More...
 

Public Types

typedef std::unordered_map< Key, Value >::const_iterator InnerIterator
 The "inner" iterator representation of the invertible_map.
 
typedef Iterator iterator
 Easier typename to deal with if capital, also lets const_iterator share same name.
 
typedef Iterator const_iterator
 Lets const_iterator be interchangeable with "iterator".
 

Public Member Functions

 invertible_map ()
 Constructor.
 
bool empty () const
 
size_t size () const
 
Key get_key (const Value &value) const
 
Value get_value (const Key &key) const
 
bool contains_key (const Key &key) const
 
bool contains_value (const Value &value) const
 
void insert (const Key &key, const Value &value)
 Inserts a (key, value) pair into the invertible map. More...
 
void insert (const std::pair< Key, Value > &pair)
 Convenience function to add a (key, value) pair into the invertible map. More...
 
void clear ()
 Frees all keys from this object.
 
const_iterator begin () const
 
const_iterator end () const
 

Private Attributes

std::unordered_map< Key, Value > forward_
 The internal map representing Key -> Value pairs.
 
std::unordered_map< Value, Key > backward_
 The internal map representing Value -> Key pairs.
 

Detailed Description

template<class Key, class Value>
class meta::util::invertible_map< Key, Value >

This data structure indexes by keys as well as values, allowing constant amortized lookup time by key or value.

All keys and values must be unique.

Member Function Documentation

§ empty()

template<class Key , class Value >
bool meta::util::invertible_map< Key, Value >::empty ( ) const
Returns
whether the invertible map is empty

§ size()

template<class Key , class Value >
size_t meta::util::invertible_map< Key, Value >::size ( ) const
Returns
the number of elements in the invertible map

§ get_key()

template<class Key , class Value>
Key meta::util::invertible_map< Key, Value >::get_key ( const Value &  value) const
Parameters
valueThe value to search by
Returns
a key given a value

§ get_value()

template<class Key, class Value >
Value meta::util::invertible_map< Key, Value >::get_value ( const Key &  key) const
Parameters
keyThe key to search by
Returns
a value given a key

§ contains_key()

template<class Key, class Value >
bool meta::util::invertible_map< Key, Value >::contains_key ( const Key &  key) const
Parameters
keyThe key to search for
Returns
whether the map contains the given key

§ contains_value()

template<class Key , class Value>
bool meta::util::invertible_map< Key, Value >::contains_value ( const Value &  value) const
Parameters
valueThe value to search for
Returns
whether the map contains the given value

§ insert() [1/2]

template<class Key, class Value>
void meta::util::invertible_map< Key, Value >::insert ( const Key &  key,
const Value &  value 
)

Inserts a (key, value) pair into the invertible map.

Parameters
keyThe key to insert
valueThe value to insert

§ insert() [2/2]

template<class Key, class Value>
void meta::util::invertible_map< Key, Value >::insert ( const std::pair< Key, Value > &  pair)

Convenience function to add a (key, value) pair into the invertible map.

Parameters
pairThe pair to add

§ begin()

template<class Key , class Value >
invertible_map< Key, Value >::const_iterator meta::util::invertible_map< Key, Value >::begin ( ) const
Returns
an iterator to the beginning of this container

§ end()

template<class Key , class Value >
invertible_map< Key, Value >::const_iterator meta::util::invertible_map< Key, Value >::end ( ) const
Returns
an iterator to the end of this container

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