LibCds: Michael Hashmap and Split Order List
LibCds: Michael Hashmap and Split Order List
我正在使用libcds,他们有一个Michael Hash Map和Split order list的实现。
根据我从文档中收集的信息,我是如何实现它们的:
包括:
#include <cds/map/michael_hash_map.h>
#include <cds/map/split_ordered_list.h>
using namespace cds;
代码:
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;
};
代码: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() {}
};
:
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() {}
};
我通过调用
来初始化结构TestDs* _gTestDs1 = new Michael(_gConfiguration);
TestDs* _gTestDs2 = new CDSSplit(_gConfiguration);
然而,当CDSSplit启动时,或者当Michael执行其第一次插入时,我得到分段错误。
库安装良好,没有任何警告,我使用其他哈希表,我没有得到任何错误。
谢谢你的帮助
(也张贴,较少的细节在讨论页上的图书馆,但似乎没有太多的存在,将张贴回来,如果有任何张贴在那里)
编译标志:-std=c++0x -O3 -msse2 -m32 -DNDEBUG -DINTEL -g -D_REENTRANT -lrt -pthread -fno-strict-aliasing -l cds -l tbb -lllalloc
GDB输出:
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
根据文档,看起来您缺少了CDS和线程管理器的初始化:
#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() ;
// attach this thread to CDS:
cds::threading::Manager::attachThread() ;
// 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;
}
相关文章:
- Ascending order c++
- 如何处理Boost Spirit X3导致Visual Studio 2019 "static initialization order fiasco"?
- 如何获取C++中的输入并将其"split"到列表中?换句话说,取 N 个输入并放入 N 长度的数组中
- 当我编译XG-Bosst时,出现错误"error: 'Split' is not a member of 'xgboost::common' ……"
- C++:如何用split查找单词?Regex
- 使用 boost::split 按分隔符的前 N 次匹配来拆分字符串
- "static initialization order fiasco"是 constexpr 变量的问题吗?
- 在使用 In Order 遍历成员函数时引发异常(堆栈溢出)时出现问题
- boost::split会在输入字符串不是常量时更改输入字符串吗?
- 什么是 Python 的 map(int,input().split()) 的 C++ 等价物
- 为什么在与静态库链接时强制执行 order(例如 source.cxx -lstatic)
- "The order of evaluation of expressions is left to right."是什么意思
- cv::split() 在至强处理器上崩溃,但在其他地方工作
- 使用boost :: split分开字符串
- memory_order_seq_cst操作的"happens before"关系和"precedes in a single total order"关系有什么区别?
- BOOST :: Split即使使用Token_compress_on将一个空字符串推向向量
- undefined 方法 'split' for nil:nilClass
- 为什么在使用boost :: split时必须使用boost :: is_any_of
- "std::map with mutexes"与并行插入、查找、擦除之间是否有任何速度测试"libcds maps (Michael Hashmap and Split Order List)"?
- LibCds: Michael Hashmap and Split Order List