I want to add hash functionality to unordered_map but having trouble understanding the semantics in cython
I have the following definition
cdef extern from * using namespace "std":
"""
struct pair_hash {
template <class T1, class T2>
std::size_t operator () (const std::pair<T1,T2> &p) const {
auto h1 = std::hash<T1>{}(p.first);
auto h2 = std::hash<T2>{}(p.second);
return h1 ^ h2;
}
};
"""
cdef cppclass pair_hash:
pass
cdef cppclass unordered_map[T, U, H]:
pass
I have browsed around the unordered_map code to see how bindings is done.
My question is how to approach these bindings in general? So far I have deduced that mapping would involve
- Correct name space
- tell cython what the object is through
cppclass - provide method names to be bound
Here, however I need to bind a template and I am a little lost on how to approach this.