由Google提供的BTree地图

时间:2013-03-21 23:06:59

标签: c++ b-tree

我正在尝试使用Google's C++ BTree

代码:

typedef btree_map<int, int> MyMap;
MyMap *obj_map = new MyMap;
obj_map->insert(make_pair(1,1));
obj_map->insert(make_pair(2,2));
obj_map->insert(make_pair(3,3));
obj_map->insert(make_pair(4,4));
obj_map->insert(make_pair(5,5));
obj_map->insert(make_pair(6,6));

MyMap::const_iterator lookup = obj_map->find(4);
printf("found %d", *lookup);

我第一次运行它时会发出警告,但是Eclipse会提示输入错误:

ref_impl/../include/btree.h: In instantiation of ‘btree::btree_node<Params>::const_reference btree::btree_node<Params>::value(int) const [with Params = btree::btree_map_params<int, int, std::less<int>, std::allocator<std::pair<const int, int> >, 256>; btree::btree_node<Params>::const_reference = const std::pair<const int, int>&]’:
ref_impl/../include/btree.h:806:32:   required from ‘btree::btree_iterator<Node, Reference, Pointer>::reference btree::btree_iterator<Node, Reference, Pointer>::operator*() const [with Node = const btree::btree_node<btree::btree_map_params<int, int, std::less<int>, std::allocator<std::pair<const int, int> >, 256> >; Reference = const std::pair<const int, int>&; Pointer = const std::pair<const int, int>*; btree::btree_iterator<Node, Reference, Pointer>::reference = const std::pair<const int, int>&]’
ref_impl/core.cpp:404:22:   required from here
ref_impl/../include/btree.h:560:63: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

如果我再次运行程序,它会运行并显示正确的结果。问题是,如果我在实际程序中使用上述实现,则不会出现持久性结果。

有关如何解决此问题的任何建议吗?

0 个答案:

没有答案