4
# cython: language_level=3
6
from libcpp.map cimport multimap
7
from libcpp.unordered_map cimport unordered_multimap
8
from libcpp.utility cimport pair
10
def test_multimap_insert(vals):
12
>>> test_multimap_insert([(1,1),(2,2),(2,2),(3,3),(-1,-1)])
13
[(-1, -1), (1, 1), (2, 2), (2, 2), (3, 3)]
15
cdef multimap[int,int] mm = multimap[int, int]()
16
cdef multimap[int, int].iterator it
19
return [ (item.first, item.second) for item in mm ]
21
def test_multimap_insert_it(vals):
23
>>> test_multimap_insert_it([(1,1),(2,2),(2,2),(3,3),(-1,-1)])
24
[(-1, -1), (1, 1), (2, 2), (2, 2), (3, 3)]
26
cdef unordered_multimap[int,int] umm = unordered_multimap[int,int]()
27
cdef multimap[int,int] mm = multimap[int,int]()
29
umm.insert(pair[int,int](k, v))
30
mm.insert(umm.begin(), umm.end())
31
return [ (item.first, item.second) for item in mm ]
33
def test_const_multimap_insert_it(vals):
35
>>> test_const_multimap_insert_it([(1,1),(2,2),(2,2),(3,3),(-1,-1)])
36
[(-1, -1), (1, 1), (2, 2), (2, 2), (3, 3)]
38
cdef unordered_multimap[int,int] umm = unordered_multimap[int,int]()
39
cdef multimap[int,int] mm = multimap[int,int]()
41
umm.insert(pair[int,int](k, v))
42
mm.insert(umm.cbegin(), umm.cend())
43
return [ (item.first, item.second) for item in mm ]
45
def test_multimap_count(vals, to_find):
47
>>> test_multimap_count([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 1)
49
>>> test_multimap_count([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 2)
52
cdef multimap[int,int] mm = multimap[int,int]()
55
return mm.count(to_find)
57
def test_multimap_erase(vals, int to_remove):
59
>>> test_multimap_erase([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 1)
60
[(-1, -1), (2, 2), (2, 2), (3, 3)]
61
>>> test_multimap_erase([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 2)
62
[(-1, -1), (1, 1), (3, 3)]
64
cdef multimap[int,int] mm = multimap[int,int]()
67
cdef size_t ret = mm.erase(to_remove)
68
return [ (item.first, item.second) for item in mm ]
70
def test_multimap_find_erase(vals, to_remove):
72
>>> test_multimap_find_erase([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 1)
73
[(-1, -1), (2, 2), (2, 2), (3, 3)]
74
>>> test_multimap_find_erase([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 2)
75
[(-1, -1), (1, 1), (2, 2), (3, 3)]
77
cdef multimap[int,int] mm = multimap[int,int]()
78
cdef multimap[int,int].iterator it
81
it = mm.find(to_remove)
83
return [ (item.first, item.second) for item in mm ]
86
def test_unordered_multimap_insert(vals):
88
>>> test_unordered_multimap_insert([(1,1),(2,2),(2,2),(3,3),(-1,-1)])
89
[(-1, -1), (1, 1), (2, 2), (2, 2), (3, 3)]
91
cdef unordered_multimap[int,int] umm = unordered_multimap[int,int]()
92
cdef unordered_multimap[int,int].iterator it
95
return sorted([ (item.first, item.second) for item in umm ])
97
def test_unordered_multimap_insert_it(vals):
99
>>> test_unordered_multimap_insert_it([(1,1),(2,2),(2,2),(3,3),(-1,-1)])
100
[(-1, -1), (1, 1), (2, 2), (2, 2), (3, 3)]
102
cdef multimap[int,int] mm = multimap[int,int]()
103
cdef unordered_multimap[int,int] umm = unordered_multimap[int,int]()
106
umm.insert(mm.begin(), mm.end())
107
return sorted([ (item.first, item.second) for item in umm ])
109
def test_const_unordered_multimap_insert_it(vals):
111
>>> test_const_unordered_multimap_insert_it([(1,1),(2,2),(2,2),(3,3),(-1,-1)])
112
[(-1, -1), (1, 1), (2, 2), (2, 2), (3, 3)]
114
cdef multimap[int,int] mm = multimap[int,int]()
115
cdef unordered_multimap[int,int] umm = unordered_multimap[int,int]()
118
umm.insert(mm.cbegin(), mm.cend())
119
return sorted([ (item.first, item.second) for item in umm ])
121
def test_unordered_multimap_count(vals, to_find):
123
>>> test_unordered_multimap_count([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 1)
125
>>> test_unordered_multimap_count([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 2)
128
cdef unordered_multimap[int,int] umm = unordered_multimap[int,int]()
131
return umm.count(to_find)
133
def test_unordered_multimap_erase(vals, int to_remove):
135
>>> test_unordered_multimap_erase([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 1)
136
[(-1, -1), (2, 2), (2, 2), (3, 3)]
137
>>> test_unordered_multimap_erase([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 2)
138
[(-1, -1), (1, 1), (3, 3)]
140
cdef unordered_multimap[int,int] umm = unordered_multimap[int,int]()
143
cdef size_t ret = umm.erase(to_remove)
144
return sorted([ (item.first, item.second) for item in umm ])
146
def test_unordered_multimap_find_erase(vals, to_remove):
148
>>> test_unordered_multimap_find_erase([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 1)
149
[(-1, -1), (2, 2), (2, 2), (3, 3)]
150
>>> test_unordered_multimap_find_erase([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 2)
151
[(-1, -1), (1, 1), (2, 2), (3, 3)]
153
cdef unordered_multimap[int,int] umm = unordered_multimap[int,int]()
154
cdef unordered_multimap[int,int].iterator it
157
it = umm.find(to_remove)
159
return sorted([ item for item in umm ])