tbb无序映射哈希函数错误

时间:2017-07-28 14:33:13

标签: c++11 tbb

我希望将concurrent_unordered_map与一些自定义类型

一起使用

我将无序地图声明如下

typedef tbb::concurrent_unordered_map<openvdb::Coord, std::vector<openvdb::Vec3R>, anotherHashCompare> unordrd_vox_coordlist;

其他哈希比较定义为

struct anotherHashCompare {
static size_t hash( const openvdb::Coord &x ) {
    size_t h = 0;
    int s;
    s=x.x();
    h = (h*17)^s;
    s=x.y();
    h = (h*17)^s;
    s=x.z();
    h = (h*17)^s;


    return ((size_t)h);
}
//! True if strings are equal
static bool equal( const openvdb::Coord &x, const openvdb::Coord &y ) {
    return x==y;
}

};

现在,当我想在此地图对象中插入内容时

  

unordrd_vox_coordlist intrmd_nrmls;

像这样

  

intrmd_nrmls.insert(标准:: make_pair(it_rel_neigh-&gt;首先,per_vox_intermed_nrmls));

其中

  

per_vox_intermed_nrmls

的类型为

  

的std ::矢量

  

it_rel_neigh-&gt;首先

的类型为

  

openvdb ::坐标

我收到如下错误

$ make
g++  -O3 -fPIC -fopenmp -std=c++11 -pthread  -I./ -I/usr/local/include/eigen3 -I/home/rohit/openvdb/include -I/usr/local/include -I/home/rohit/Downloads/tbb2017_20170226oss/include  -I/usr/local/include -o pointsv9.o -c pointsv9.cpp
In file included from /home/rohit/Downloads/tbb2017_20170226oss/include/tbb/concurrent_hash_map.h:47:0,
                 from /home/rohit/openvdb/include/openvdb/tree/Tree.h:51,
                 from /home/rohit/openvdb/include/openvdb/Grid.h:39,
                 from /home/rohit/openvdb/include/openvdb/openvdb.h:39,
                 from tbb_structs1.h:16,
                 from pointsv9.cpp:6:
/home/rohit/Downloads/tbb2017_20170226oss/include/tbb/internal/_tbb_hash_compare_impl.h: In instantiation of ‘std::size_t tbb::interface5::internal::hash_compare<Key, Hasher, Key_equality>::operator()(const Key&) const [with Key = openvdb::v4_0_1::math::Coord; Hasher = anotherHashCompare; Key_equality = std::equal_to<openvdb::v4_0_1::math::Coord>; std::size_t = long unsigned int]’:
/home/rohit/Downloads/tbb2017_20170226oss/include/tbb/internal/_concurrent_unordered_impl.h:1276:53:   required from ‘std::pair<typename tbb::interface5::internal::split_ordered_list<typename Traits::value_type, typename Traits::allocator_type>::iterator, bool> tbb::interface5::internal::concurrent_unordered_base<Traits>::internal_insert(ValueType&&, tbb::interface5::internal::concurrent_unordered_base<Traits>::nodeptr_t) [with AllowCreate = tbb::internal::bool_constant<true>; ValueType = std::pair<const openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> > >; Traits = tbb::interface5::concurrent_unordered_map_traits<openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> >, tbb::interface5::internal::hash_compare<openvdb::v4_0_1::math::Coord, anotherHashCompare, std::equal_to<openvdb::v4_0_1::math::Coord> >, tbb::tbb_allocator<std::pair<const openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> > > >, false>; typename tbb::interface5::internal::split_ordered_list<typename Traits::value_type, typename Traits::allocator_type>::iterator = tbb::interface5::internal::solist_iterator<tbb::interface5::internal::split_ordered_list<std::pair<const openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> > >, tbb::tbb_allocator<std::pair<const openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> > > > >, std::pair<const openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> > > >; tbb::interface5::internal::concurrent_unordered_base<Traits>::nodeptr_t = tbb::interface5::internal::split_ordered_list<std::pair<const openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> > >, tbb::tbb_allocator<std::pair<const openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> > > > >::node*]’
/home/rohit/Downloads/tbb2017_20170226oss/include/tbb/internal/_concurrent_unordered_impl.h:980:73:   required from ‘std::pair<typename tbb::interface5::internal::split_ordered_list<typename Traits::value_type, typename Traits::allocator_type>::iterator, bool> tbb::interface5::internal::concurrent_unordered_base<Traits>::insert(tbb::interface5::internal::concurrent_unordered_base<Traits>::value_type&&) [with Traits = tbb::interface5::concurrent_unordered_map_traits<openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> >, tbb::interface5::internal::hash_compare<openvdb::v4_0_1::math::Coord, anotherHashCompare, std::equal_to<openvdb::v4_0_1::math::Coord> >, tbb::tbb_allocator<std::pair<const openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> > > >, false>; typename tbb::interface5::internal::split_ordered_list<typename Traits::value_type, typename Traits::allocator_type>::iterator = tbb::interface5::internal::solist_iterator<tbb::interface5::internal::split_ordered_list<std::pair<const openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> > >, tbb::tbb_allocator<std::pair<const openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> > > > >, std::pair<const openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> > > >; tbb::interface5::internal::concurrent_unordered_base<Traits>::value_type = std::pair<const openvdb::v4_0_1::math::Coord, std::vector<openvdb::v4_0_1::math::Vec3<double> > >]’
tbb_structs1.h:202:83:   required from here
/home/rohit/Downloads/tbb2017_20170226oss/include/tbb/internal/_tbb_hash_compare_impl.h:46:44: error: no match for call to ‘(const anotherHashCompare) (const openvdb::v4_0_1::math::Coord&)’
         return ((size_t)my_hash_object(key));
                                            ^
common.mk:52: recipe for target 'pointsv9.o' failed
make: *** [pointsv9.o] Error 1

请建议我如何更正我对has函数的定义

我尝试声明了两个新的结构,我将其传递给我的定义,但也会产生类似的错误

这是否意味着我应该像这样声明它们

    struct MyHashcpr_unordrd {
    static size_t hash( const openvdb::Coord &x ) {
        size_t h = 0;
        int s;
        s=x.x();
        h = (h*17)^s;
        s=x.y();
        h = (h*17)^s;
        s=x.z();
        h = (h*17)^s;


        return h;
    }

};

struct MyHasheqlty_unordrd {
        //! True if strings are equal
    static bool equal( const openvdb::Coord &x, const openvdb::Coord &y ) {
        return x==y;
    }
};

typedef tbb::concurrent_unordered_map<openvdb::Coord, std::vector<openvdb::Vec3R>, MyHashcpr_unordrd,MyHasheqlty_unordrd> unordrd_vec_of_coords;

因为这也会产生以下错误

错误:无法匹配调用'(const MyHasheqlty_unordrd)(const openvdb :: v4_0_1 :: math :: Coord&amp;,const openvdb :: v4_0_1 :: math :: Coord&amp;)'          return(!my_key_compare_object(key1,key2));

错误:无法匹配调用'(const MyHashcpr_unordrd)(const openvdb :: v4_0_1 :: math :: Coord&amp;)'          return((size_t)my_hash_object(key));

0 个答案:

没有答案