libmoost
moost::container::multi_map< TKey, TVal, TLocMap > Class Template Reference

multi_map is a container that associates keys to list of values. More...

#include <multi_map.hpp>

Inheritance diagram for moost::container::multi_map< TKey, TVal, TLocMap >:
Collaboration diagram for moost::container::multi_map< TKey, TVal, TLocMap >:

List of all members.

Classes

class  const_iterator
class  const_range
class  iterator
class  range

Public Types

typedef TKey first_type
typedef TVal second_type
typedef
policies::map_policy_selector
< TKey, multimap_value_type,
TLocMap >::policy_type 
loc_map_policy_type
typedef std::vector< TVal >
::iterator 
range_iterator
typedef std::vector< TVal >
::const_iterator 
const_range_iterator

Public Member Functions

iterator begin ()
const_iterator begin () const
iterator end ()
const_iterator end () const
 multi_map (const loc_map_policy_type &locHandlerPolicy=loc_map_policy_type())
template<int WhichKey, typename Iterator >
void create_map (Iterator first, Iterator last, size_t suggestedSize=128)
template<typename Iterator , typename GetKeyPolicy , typename GetValuesPolicy >
void create_map (Iterator first, Iterator last, const GetKeyPolicy &getKey, const GetValuesPolicy &getValues, size_t suggestedSize=128)
template<int WhichKey, typename TFirst , typename TSecond >
void create_map (std::vector< TFirst, TSecond > &i2i, bool doSort=true)
template<int WhichKey, typename TFirst , typename TSecond >
void create_map_compressed (std::vector< TFirst, TSecond > &i2i, bool doSort=true)
template<int WhichKey, typename Iterator >
void create_map_compressed (Iterator first, Iterator last, size_t suggestedSize=128)
range operator[] (const TKey &key)
const_range operator[] (const TKey &key) const
void clear ()
 Will clear the whole table.
size_t size () const
 Returns the number of keys.
bool empty () const

Protected Attributes

TLocMap m_locations
loc_map_policy_type m_locHandlerPolicy
std::vector< TVal > m_data

Private Types

typedef multi_map< TKey, TVal,
TLocMap > 
self_type

Detailed Description

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
class moost::container::multi_map< TKey, TVal, TLocMap >

multi_map is a container that associates keys to list of values.

It is similar in concept of having an hashmap: hm[key] -> {val, val, val, ..} but it's way more efficient.

Note:
This is a read only data structure: once it has been built no other data can be added, unless clear has been called.

Example usage:

moost::container::multi_map<int, float> test;
vector< pair<int, float> > data;

data.push_back( make_pair(10, 2.0f) );
data.push_back( make_pair(10, 3.0f) );
data.push_back( make_pair(10, 1.0f) );
data.push_back( make_pair(12, 1.0f) );

test.create_map<1>(data); // using the first of the pair as key, it will sort itself

moost::container::multi_map<int, float>::range rt;
rt = test[10];
moost::container::multi_map<int, float>::range_iterator mapIt;
for ( mapIt = rt.begin(); mapIt != rt.end(); ++mapIt )
   cout << *mapIt << endl;

Is it also possible to define a different container for the locatin map, i.e. when the keys are within a well know range a vector might be a better solution:

typedef multi_map< int, float, vector<multimap_value_t> > multi_map_vec;
multi_map_vec::loc_map_policy_type policy(10) // max key index is 9
multi_map_vec data(policy);

In the case of the default location map (dense_hash_map) the empty key can be easily set by using the location map policy, i.e. to set it to -1 we just do

typedef moost::container::multi_map<int, float> map_type;
map_type test(map_type::loc_map_policy_type(-1));

Definition at line 94 of file multi_map.hpp.


Member Typedef Documentation

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
typedef std::vector<TVal>::const_iterator moost::container::multi_map< TKey, TVal, TLocMap >::const_range_iterator

Definition at line 110 of file multi_map.hpp.

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
typedef TKey moost::container::multi_map< TKey, TVal, TLocMap >::first_type

Definition at line 102 of file multi_map.hpp.

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
typedef policies::map_policy_selector< TKey, multimap_value_type, TLocMap>::policy_type moost::container::multi_map< TKey, TVal, TLocMap >::loc_map_policy_type
template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
typedef std::vector<TVal>::iterator moost::container::multi_map< TKey, TVal, TLocMap >::range_iterator

Definition at line 109 of file multi_map.hpp.

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
typedef TVal moost::container::multi_map< TKey, TVal, TLocMap >::second_type

Definition at line 103 of file multi_map.hpp.

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
typedef multi_map<TKey, TVal, TLocMap> moost::container::multi_map< TKey, TVal, TLocMap >::self_type [private]

Definition at line 98 of file multi_map.hpp.


Constructor & Destructor Documentation

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
moost::container::multi_map< TKey, TVal, TLocMap >::multi_map ( const loc_map_policy_type locHandlerPolicy = loc_map_policy_type()) [inline]

Definition at line 310 of file multi_map.hpp.


Member Function Documentation

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
iterator moost::container::multi_map< TKey, TVal, TLocMap >::begin ( ) [inline]

Definition at line 302 of file multi_map.hpp.

Here is the caller graph for this function:

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
const_iterator moost::container::multi_map< TKey, TVal, TLocMap >::begin ( ) const [inline]

Definition at line 303 of file multi_map.hpp.

template<typename TKey , typename TVal , typename TLocMap >
void moost::container::multi_map< TKey, TVal, TLocMap >::clear ( )

Will clear the whole table.

Definition at line 595 of file multi_map.hpp.

Here is the caller graph for this function:

template<typename TKey , typename TVal , typename TLocMap >
template<int WhichKey, typename Iterator >
void moost::container::multi_map< TKey, TVal, TLocMap >::create_map ( Iterator  first,
Iterator  last,
size_t  suggestedSize = 128 
)

Create the map from a vector of pairs, where the key is either the first or the second element of the pair, and it is specified by the template argument (either 1 or 2 are valid).

Parameters:
i2ithe item2item vector of pairs
doSortif true it will sort by the keys. This is a required step and takes a bit of time because it is using a stable sort. If your data is already sorted by the key, you can avoid this.

Definition at line 406 of file multi_map.hpp.

template<typename TKey , typename TVal , typename TLocMap >
template<typename Iterator , typename GetKeyPolicy , typename GetValuesPolicy >
void moost::container::multi_map< TKey, TVal, TLocMap >::create_map ( Iterator  first,
Iterator  last,
const GetKeyPolicy &  getKey,
const GetValuesPolicy &  getValues,
size_t  suggestedSize = 128 
)

Create the map from a couple of iterators. It allows to specify getKey and getValue policies to access special type of structures.

Definition at line 446 of file multi_map.hpp.

template<typename TKey , typename TVal , typename TLocMap >
template<int WhichKey, typename TFirst , typename TSecond >
void moost::container::multi_map< TKey, TVal, TLocMap >::create_map ( std::vector< TFirst, TSecond > &  i2i,
bool  doSort = true 
)

Create the map from a vector of pairs, where the key is either the first or the second element of the pair, and it is specified by the template argument (either 1 or 2 are valid).

Parameters:
i2ithe item2item vector of pairs
doSortif true it will sort by the keys. This is a required step and takes a bit of time because it is using a stable sort. If your data is already sorted by the key, you can avoid this.

Definition at line 387 of file multi_map.hpp.

template<typename TKey , typename TVal , typename TLocMap >
template<int WhichKey, typename TFirst , typename TSecond >
void moost::container::multi_map< TKey, TVal, TLocMap >::create_map_compressed ( std::vector< TFirst, TSecond > &  i2i,
bool  doSort = true 
)

Definition at line 480 of file multi_map.hpp.

template<typename TKey , typename TVal , typename TLocMap >
template<int WhichKey, typename Iterator >
void moost::container::multi_map< TKey, TVal, TLocMap >::create_map_compressed ( Iterator  first,
Iterator  last,
size_t  suggestedSize = 128 
)

Equivalent to create_map, but will map the keys with a _single_ value to the same memory location thus saving memory. Use it only if you have a lot of entries with a single value and (if it's a data structure) the operator < is implemented.

See also:
create_map

Definition at line 499 of file multi_map.hpp.

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
bool moost::container::multi_map< TKey, TVal, TLocMap >::empty ( ) const [inline]

Definition at line 370 of file multi_map.hpp.

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
iterator moost::container::multi_map< TKey, TVal, TLocMap >::end ( ) [inline]

Definition at line 305 of file multi_map.hpp.

Here is the caller graph for this function:

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
const_iterator moost::container::multi_map< TKey, TVal, TLocMap >::end ( ) const [inline]

Definition at line 306 of file multi_map.hpp.

template<typename TKey, typename TVal , typename TLocMap >
multi_map< TKey, TVal, TLocMap >::range moost::container::multi_map< TKey, TVal, TLocMap >::operator[] ( const TKey &  key)

Definition at line 558 of file multi_map.hpp.

template<typename TKey, typename TVal , typename TLocMap >
multi_map< TKey, TVal, TLocMap >::const_range moost::container::multi_map< TKey, TVal, TLocMap >::operator[] ( const TKey &  key) const

Definition at line 577 of file multi_map.hpp.

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
size_t moost::container::multi_map< TKey, TVal, TLocMap >::size ( ) const [inline]

Returns the number of keys.

Definition at line 367 of file multi_map.hpp.

Here is the caller graph for this function:


Member Data Documentation

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
std::vector<TVal> moost::container::multi_map< TKey, TVal, TLocMap >::m_data [protected]

Definition at line 378 of file multi_map.hpp.

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
TLocMap moost::container::multi_map< TKey, TVal, TLocMap >::m_locations [protected]

Definition at line 375 of file multi_map.hpp.

template<typename TKey, typename TVal, typename TLocMap = moost::container::dense_hash_map<TKey, multimap_value_type >>
loc_map_policy_type moost::container::multi_map< TKey, TVal, TLocMap >::m_locHandlerPolicy [protected]

Definition at line 376 of file multi_map.hpp.


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