Commit 21c34835 authored by will's avatar will Committed by Stefan Behnel

Add missing unordered_map template defaults (GH-3686)

parent 6e3c9562
from .utility cimport pair from .utility cimport pair
cdef extern from "<unordered_map>" namespace "std" nogil: cdef extern from "<unordered_map>" namespace "std" nogil:
cdef cppclass unordered_map[T, U]: cdef cppclass unordered_map[T, U, HASH=*, PRED=*, ALLOCATOR=*]:
ctypedef T key_type ctypedef T key_type
ctypedef U mapped_type ctypedef U mapped_type
ctypedef pair[const T, U] value_type ctypedef pair[const T, U] value_type
......
...@@ -140,6 +140,11 @@ def test_unordered_set_functionality(): ...@@ -140,6 +140,11 @@ def test_unordered_set_functionality():
return "pass" return "pass"
cdef extern from "cpp_unordered_map_helper.h":
cdef cppclass IntVectorHash:
pass
def test_unordered_map_functionality(): def test_unordered_map_functionality():
""" """
>>> test_unordered_map_functionality() >>> test_unordered_map_functionality()
...@@ -153,6 +158,8 @@ def test_unordered_map_functionality(): ...@@ -153,6 +158,8 @@ def test_unordered_map_functionality():
unordered_map[int, int] int_map2 unordered_map[int, int] int_map2
unordered_map[int, int*] intptr_map unordered_map[int, int*] intptr_map
const int* intptr const int* intptr
unordered_map[vector[int], int, IntVectorHash] int_vector_map
vector[int] intvec
assert int_map[1] == 2 assert int_map[1] == 2
assert int_map.size() == 1 assert int_map.size() == 1
assert int_map.erase(1) == 1 # returns number of elements erased assert int_map.erase(1) == 1 # returns number of elements erased
...@@ -183,4 +190,12 @@ def test_unordered_map_functionality(): ...@@ -183,4 +190,12 @@ def test_unordered_map_functionality():
intptr_map[0] = NULL intptr_map[0] = NULL
intptr = intptr_map.const_at(0) intptr = intptr_map.const_at(0)
intvec = [1, 2]
int_vector_map[intvec] = 3
intvec = [4, 5]
int_vector_map[intvec] = 6
assert int_vector_map[intvec] == 6
intvec = [1, 2]
assert int_vector_map[intvec] == 3
return "pass" return "pass"
#include <functional>
#include <vector>
struct IntVectorHash {
size_t operator()(const std::vector<int>& v) const {
std::hash<int> hasher;
size_t seed = 0;
for (int i : v) {
seed ^= hasher(i) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
return seed;
}
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment