我尝试创建将映射std::string
到的哈希映射,std::string
到目前为止我使用了以下代码:
template<typename TKey, typename TValue>
struct lockfree_hash_map_traits_t
: public cds::container::split_list::type_traits
{
typedef cds::container::michael_list_tag ordered_list ; // what type of ordered list we want to use
typedef std::hash<TKey> hash ; // hash functor for the key stored in split-list map
// Type traits for our MichaelList class
struct ordered_list_traits: public cds::container::michael_list::type_traits {
typedef std::less<TKey> less; // comparer that specifies order of list nodes
};
};
template<typename TKey, typename TValue>
class lockfree_hash_map_t {
public:
typedef
cds::container::SplitListMap<cds::gc::HP, TKey, TValue, lockfree_hash_map_traits_t<TKey, TValue> >
base_hash_map;
// ... some stuff
private:
base_hash_map _map;
};
它基于 libcds 文档。但我不确定我是否正确使用哈希映射......根据描述 SplitListMap 底层列表的论文应该按键的哈希排序,但文档建议使用 std::less<TKey>
指定迈克尔列表顺序。使用std::less<std::string>
正确吗?