libmoost
/home/mhx/git/github/libmoost/include/moost/container/policies/sparse_hash_map.hpp
Go to the documentation of this file.
00001 /* vim:set ts=3 sw=3 sts=3 et: */
00028 #ifndef MOOST_SPARSE_HASH_MAP_POLICY_HPP
00029 #define MOOST_SPARSE_HASH_MAP_POLICY_HPP
00030 
00031 #include "generic_map.hpp"
00032 #include "../sparse_hash_map.hpp"
00033 
00034 namespace moost { namespace container { namespace policies {
00035 
00039 template <typename TKey, typename TVal>
00040 class sparse_hs_map : public generic_map< moost::container::sparse_hash_map<TKey, TVal> >
00041 {
00042 public:
00043 
00044    typedef typename moost::container::sparse_hash_map<TKey, TVal> map_type;
00045 
00046 public:
00047 
00048    sparse_hs_map(size_t hint_size = 1048576)
00049       : m_hintSize(hint_size)
00050    {}
00051 
00052    virtual ~sparse_hs_map(){}
00053 
00055    virtual void init(map_type& map) const
00056    {
00057       if ( m_hintSize > 0 )
00058          map.resize(m_hintSize);
00059    }
00060 
00062    virtual void resize(map_type& map, size_t numKeys) const
00063    { map.resize(numKeys); }
00064 
00065 private:
00066    size_t m_hintSize;
00067 };
00068 
00069 // -----------------------------------------------------------------------------
00070 
00071 template <typename TKey, typename TVal>
00072 struct map_policy_selector< TKey, TVal, moost::container::sparse_hash_map<TKey, TVal> >
00073 {
00074    // will return generic_map
00075    typedef sparse_hs_map<TKey, TVal>  policy_type;
00076 };
00077 
00078 }}}
00079 
00080 #endif // MOOST_SPARSE_HASH_MAP_POLICY_HPP