Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将libcds SplitListMap与std::string一起使用_C++_C++11_Libcds - Fatal编程技术网

C++ 将libcds SplitListMap与std::string一起使用

C++ 将libcds SplitListMap与std::string一起使用,c++,c++11,libcds,C++,C++11,Libcds,我尝试创建将std::string映射到std::string的哈希映射, 到目前为止,我使用了以下代码: 模板 结构无锁\u散列\u映射\u特征\u t :public cds::container::split\u list::type\u traits { typedef CD::container::michael_list_tag ordered_list;//我们要使用哪种类型的ordered list typedef std::hash hash;//存储在拆分列表映射中的键的h

我尝试创建将
std::string
映射到
std::string
的哈希映射, 到目前为止,我使用了以下代码:

模板
结构无锁\u散列\u映射\u特征\u t
:public cds::container::split\u list::type\u traits
{
typedef CD::container::michael_list_tag ordered_list;//我们要使用哪种类型的ordered list
typedef std::hash hash;//存储在拆分列表映射中的键的hash functor
//我们MichaelList班的类型特征
结构有序列表特征:公共CD::容器::michael列表::类型特征{
typedef std::less;//指定列表节点顺序的比较器
};
};
模板
类无锁\u散列\u映射\u t{
公众:
类型定义
cds::container::SplitListMap
基本哈希映射;
//…一些东西
私人:
基本哈希映射;
};
它基于libcds文档。但我不确定我是否正确使用哈希映射。。。 根据描述SplitListMap的论文 底层列表应该按键的散列排序,但文档建议使用
std::less
来指定列表顺序。
std::less的使用正确吗?

哈希映射通常是这样的。哈希函数可以为不同的键生成一个哈希代码。这被称为碰撞。当我们搜索一个键时,我们计算该键的散列,在映射中搜索该散列(通常散列只是散列表中的一个索引),然后将找到的项的键与我们的键进行比较。因此std::less是必要的。

关于这个问题,您可以提供一个示例,说明如何在主函数中初始化此映射并添加一个元素吗?我还在文档中搜索,只写了
int2int\u映射名为我造成了一个异常(参考文档中给出的示例)。
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;
};