LibCds:Michael Hashmap和Split Order List [英] LibCds: Michael Hashmap and Split Order List

查看:383
本文介绍了LibCds:Michael Hashmap和Split Order List的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 libcds ,他们有一个实现Michael Hash Map和Split order list。 / p>

根据我从文档收集的信息,我是如何实现他们的:



包括:

  #include< cds / map / michael_hash_map.h> 
#include< cds / map / split_ordered_list.h>
using namespace cds;

代码:

 code> class TestDs {
public:
virtual bool containsKey(int key)= 0;
virtual int get(int key)= 0;
virtual int put(int key,int value)= 0;
virtual int remove(int key)= 0;

virtual int size()= 0;
virtual const char * name()= 0;
virtual void print()= 0;
virtual void shutdown()= 0;
};

代码:

 code> class Michael:public TestDs {
private:

cds :: map :: MichaelHashMap< int,int,cds :: map :: pair_traits< int,int& ,cds :: map :: type_traits,CDS_DEFAULT_ALLOCATOR> _ds;
public:
Michael(const Configuration& config):_ds(config.initial_count,config.load_factor){
}

bool containsKey(int key){
return(_ds.find(key)!= 0);
}

int get(int key){
return _ds.find(key);
}

int put(int key,int value){
return _ds.insert(key,value);
}

int remove(int key){
return _ds.erase(key);
}

int size(){
return _ds.size();
}
const char * name(){
returnMicheal;
}
void print(){}
void shutdown(){}

};

和:

  class CDSSplit:public TestDs {
private:
cds :: map :: SplitOrderedList public:
CDSSplit(const Configuration& config):_ds(config.initial_count,config.load_factor){
}

bool containsKey(int key){
return(_ds.find(key)!= 0);
}

int get(int key){
return _ds.find(key);
}

int put(int key,int value){
return _ds.insert(key,value);
}

int remove(int key){
return _ds.erase(key);
}

int size(){
return _ds.size();
}
const char * name(){
returnCDSSPlit;
}
void print(){}
void shutdown(){}

};

我通过调用以下方式启动结构:

  TestDs * _gTestDs1 = new Michael(_gConfiguration); 
TestDs * _gTestDs2 = new CDSSplit(_gConfiguration);

然而,当CDSSplit启动时或迈克尔首次执行插入操作时, / p>

库安装正常,没有警告,我使用其他散列表我没有得到任何错误。



感谢任何帮助



(也发布,在图书馆的讨论页面上有更少的细节,但是没有出现在那里,



编译标志: -std = c ++ 0x -O3 -msse2 -m32 -DNDEBUG -DINTEL -g -D_REENTRANT -lrt -pthread -fno-strict-aliasing -l cds -l tbb -lllalloc



GDB输出:

 编程接收信号SIGSEGV,分段故障。 
cds :: ordered_list :: details :: michael_list :: implementation< cds :: gc :: hzp_gc,cds :: ordered_list :: details :: michael_list :: adapter< cds :: gc :: hzp_gc,int, int,cds :: map :: pair_traits< int,int>,cds :: ordered_list :: type_traits,std :: allocator< int> >,std :: allocator< int> > :: insert(this = 0xafd42028,refHead = ...,pNode = 0x8440060)at /usr/include/cds/ordered_list/details/michael_list_hpgen.h:457
457 position pos(gc_base_class :: getGC ));
(gdb)backtrace
#0 cds :: ordered_list :: details :: michael_list :: implementation< cds :: gc :: hzp_gc,cds :: ordered_list :: details :: michael_list :: adaptor< cds :: gc :: hzp_gc,int,int,cds :: map :: pair_traits< int,int> ;, cds :: ordered_list :: type_traits,std :: allocator< int> >,std :: allocator< int> > :: insert(this = 0xafd42028,refHead = ...,pNode = 0x8440060)at /usr/include/cds/ordered_list/details/michael_list_hpgen.h:457
#1 0x0805323e in insert(this = 0x8470070 ,key = 2,value = 2)在/usr/include/cds/ordered_list/details/michael_list_hpgen.h:430
#2插入(这是= 0x8470070,key = 2,value = 2) include / cds / ordered_list / details / michael_list_hpgen.h:195
#3 insert(this = 0x8470070,key = 2,value = 2)at /usr/include/cds/map/michael_hash_map.h:487
#4 Michael :: put(this = 0x8470070,key = 2,value = 2)at ../test/main.cpp:450
#5 0x0804b129 in FillTable(table_size = 5033165)at ../测试/ main.cpp:876
#6 0x0804c7b2在RunBenchmark()在../test/main.cpp:961
#7 0x0804e617在main(argc = 9,argv = 0xbffff714)在.. /test/main.cpp:846


解决方案

a href =http://libcds.sourceforge.net/doc/cds-api/index.html =nofollow>文档,它看起来像您缺少CDS和线程管理器的初始化

  #include< cds / threading / model.h> //线程管理器
#include< cds / gc / hzp / hzp.h> // Hazard Pointer GC

// ...

int main()
{
//初始化CDS库
cds: :Initialize();

//初始化您使用的垃圾收集器
cds :: gc :: hzp :: GarbageCollector :: Construct();

//做一些有用的工作

配置_gConfiguration;
TestDs * _gTestDs1 = new Michael(_gConfiguration);
TestDs * _gTestDs2 = new CDSSplit(_gConfiguration);

//终止GC
cds :: gc :: hzp :: GarbageCollector :: Destruct();

//终止CDS库
cds :: Terminate();

return 0;
}


I am using libcds and they have an implementation of Michael Hash Map and Split order list.

Based on the information I gathered from the doc here is how I implemented them:

includes:

#include <cds/map/michael_hash_map.h>
#include <cds/map/split_ordered_list.h>
using namespace cds;

Code:

  class TestDs {
public:
    virtual bool containsKey(int key)=0;
    virtual int get(int key)=0;
    virtual int put(int key, int value)=0;
    virtual int remove(int key)=0;

    virtual int size()=0;
    virtual const char* name()=0;
    virtual void print()=0;
    virtual void shutdown()=0;
};

Code:

class Michael: public TestDs{
private:

    cds::map::MichaelHashMap<int,int,cds::map::pair_traits <int, int>, cds::map::type_traits, CDS_DEFAULT_ALLOCATOR> _ds;
public:
        Michael(const Configuration& config) : _ds(config.initial_count,config.load_factor) {
        }

    bool containsKey(int key) {
        return (_ds.find(key)!=0);
    }

    int get(int key) {
        return _ds.find(key);
    }

    int put(int key, int value) {
        return _ds.insert(key,value);
    }

    int remove(int key) {
        return _ds.erase(key);
    }

    int size() {
        return _ds.size();
    }
    const char* name() {
        return "Micheal";
    }
    void print() {}
    void shutdown() {}

};

And:

class CDSSplit: public TestDs{
private:
    cds::map::SplitOrderedList<int,int,cds::map::pair_traits<int,int> ,cds::map::split_list::type_traits,CDS_DEFAULT_ALLOCATOR> _ds;
public:
    CDSSplit(const Configuration& config) : _ds(config.initial_count, config.load_factor) {
    }

    bool containsKey(int key) {
        return (_ds.find(key)!=0);
    }

    int get(int key) {
        return _ds.find(key);
    }

    int put(int key, int value) {
        return _ds.insert(key,value);
    }

    int remove(int key) {
        return _ds.erase(key);
    }

    int size() {
        return _ds.size();
    }
    const char* name() {
        return "CDSSPlit";
    }
    void print() {}
    void shutdown() {}

};

I initiate the structures by calling:

TestDs* _gTestDs1 = new Michael(_gConfiguration);
TestDs* _gTestDs2 = new CDSSplit(_gConfiguration);

However I get segmentation faults, when CDSSplit is initiated, or when Michael has its first insert performed.

The Library installed fine with no warnings, and I use other hashtables I don't get any errors.

Thanks for any help

(Also posted, with less detail on the discussion page for the library, but there doesn't appear to be much presence there, will post back if anything is posted there)

Compile Flags: -std=c++0x -O3 -msse2 -m32 -DNDEBUG -DINTEL -g -D_REENTRANT -lrt -pthread -fno-strict-aliasing -l cds -l tbb -lllalloc

GDB Output:

    Program received signal SIGSEGV, Segmentation fault.
cds::ordered_list::details::michael_list::implementation<cds::gc::hzp_gc, cds::ordered_list::details::michael_list::adapter<cds::gc::hzp_gc, int, int, cds::map::pair_traits<int, int>, cds::ordered_list::type_traits, std::allocator<int> >, std::allocator<int> >::insert (this=0xafd42028, refHead=..., pNode=0x8440060) at /usr/include/cds/ordered_list/details/michael_list_hpgen.h:457
457             position pos( gc_base_class::getGC() )  ;
(gdb) backtrace
#0  cds::ordered_list::details::michael_list::implementation<cds::gc::hzp_gc, cds::ordered_list::details::michael_list::adapter<cds::gc::hzp_gc, int, int, cds::map::pair_traits<int, int>, cds::ordered_list::type_traits, std::allocator<int> >, std::allocator<int> >::insert (this=0xafd42028, refHead=..., pNode=0x8440060) at /usr/include/cds/ordered_list/details/michael_list_hpgen.h:457
#1  0x0805323e in insert (this=0x8470070, key=2, value=2) at /usr/include/cds/ordered_list/details/michael_list_hpgen.h:430
#2  insert (this=0x8470070, key=2, value=2) at /usr/include/cds/ordered_list/details/michael_list_hpgen.h:195
#3  insert (this=0x8470070, key=2, value=2) at /usr/include/cds/map/michael_hash_map.h:487
#4  Michael::put (this=0x8470070, key=2, value=2) at ../test/main.cpp:450
#5  0x0804b129 in FillTable (table_size=5033165) at ../test/main.cpp:876
#6  0x0804c7b2 in RunBenchmark () at ../test/main.cpp:961
#7  0x0804e617 in main (argc=9, argv=0xbffff714) at ../test/main.cpp:846

解决方案

According to the docs, it looks like you are missing the initialization of CDS and the threading manager:

#include <cds/threading/model.h>    // threading manager
#include <cds/gc/hzp/hzp.h>         // Hazard Pointer GC

// ...

int main()
{
    // Initialize CDS library
    cds::Initialize() ;

    // Initialize Garbage collector(s) that you use 
    cds::gc::hzp::GarbageCollector::Construct() ;

    // Do some useful work 

    Configuration _gConfiguration;
    TestDs* _gTestDs1 = new Michael(_gConfiguration);
    TestDs* _gTestDs2 = new CDSSplit(_gConfiguration);

    // Terminate GCs 
    cds::gc::hzp::GarbageCollector::Destruct() ;

    // Terminate CDS library
    cds::Terminate()    ;

    return 0;
}

这篇关于LibCds:Michael Hashmap和Split Order List的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆