Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit c59fd1f

Browse files
author
Ivan Butygin
committed
multimap
1 parent 213eccc commit c59fd1f

File tree

3 files changed

+15
-42
lines changed

3 files changed

+15
-42
lines changed

Diff for: sdc/_concurrent_hash.cpp

+6-19
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@
2626

2727
#include <Python.h>
2828
#include <cstdint>
29-
#include <tbb/concurrent_hash_map.h>
30-
#include <tbb/concurrent_vector.h>
29+
#include <tbb/concurrent_unordered_map.h>
3130

3231

3332
template<typename Key, typename Val>
34-
using hashmap = tbb::concurrent_hash_map<Key,tbb::concurrent_vector<Val>>;
33+
using hashmap = tbb::concurrent_unordered_multimap<Key,Val>;
3534

3635
template<typename Key, typename Val>
3736
using iter_range = std::pair<typename hashmap<Key, Val>::iterator, typename hashmap<Key, Val>::iterator>;
@@ -54,12 +53,7 @@ void delete_int_hashmap(void* obj)
5453
void addelem_int_hashmap(void* obj, int64_t key, size_t val)
5554
{
5655
auto& h = *static_cast<int_hashmap*>(obj);
57-
int_hashmap::accessor ac;
58-
h.insert(ac, key);
59-
auto& vec = ac->second;
60-
ac.release();
61-
vec.push_back(val);
62-
// h[key].push_back(val);
56+
h.insert({key,val});
6357
}
6458

6559
void* createiter_int_hashmap(void* obj)
@@ -86,16 +80,10 @@ int64_t iterkey_int_hashmap(void* it)
8680
return r.first->first;
8781
}
8882

89-
size_t itersize_int_hashmap(void* it)
83+
size_t iterval_int_hashmap(void* it)
9084
{
9185
auto& r = *static_cast<int_hashmap_iters*>(it);
92-
return r.first->second.size();
93-
}
94-
95-
size_t iterelem_int_hashmap(void* it, size_t index)
96-
{
97-
auto& r = *static_cast<int_hashmap_iters*>(it);
98-
return r.first->second[index];
86+
return r.first->second;
9987
}
10088

10189
void deleteiter_int_hashmap(void* obj)
@@ -128,8 +116,7 @@ PyMODINIT_FUNC PyInit_hconcurrent_hash()
128116
REGISTER(enditer_int_hashmap)
129117
REGISTER(nextiter_int_hashmap)
130118
REGISTER(iterkey_int_hashmap)
131-
REGISTER(itersize_int_hashmap)
132-
REGISTER(iterelem_int_hashmap)
119+
REGISTER(iterval_int_hashmap)
133120
REGISTER(deleteiter_int_hashmap)
134121
#undef REGISTER
135122
return m;

Diff for: sdc/concurrent_hash.py

+7-19
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
ll.add_symbol('enditer_int_hashmap', hconcurrent_hash.enditer_int_hashmap)
4343
ll.add_symbol('nextiter_int_hashmap', hconcurrent_hash.nextiter_int_hashmap)
4444
ll.add_symbol('iterkey_int_hashmap', hconcurrent_hash.iterkey_int_hashmap)
45-
ll.add_symbol('itersize_int_hashmap', hconcurrent_hash.itersize_int_hashmap)
46-
ll.add_symbol('iterelem_int_hashmap', hconcurrent_hash.iterelem_int_hashmap)
45+
ll.add_symbol('iterval_int_hashmap', hconcurrent_hash.iterval_int_hashmap)
4746
ll.add_symbol('deleteiter_int_hashmap', hconcurrent_hash.deleteiter_int_hashmap)
4847

4948
_create_int_hashmap = types.ExternalFunction("create_int_hashmap",
@@ -61,10 +60,8 @@
6160
types.void(types.voidptr))
6261
_iterkey_int_hashmap = types.ExternalFunction("iterkey_int_hashmap",
6362
types.int64(types.voidptr))
64-
_itersize_int_hashmap = types.ExternalFunction("itersize_int_hashmap",
65-
types.intp(types.voidptr))
66-
_iterelem_int_hashmap = types.ExternalFunction("iterelem_int_hashmap",
67-
types.intp(types.voidptr, types.intp))
63+
_iterval_int_hashmap = types.ExternalFunction("iterval_int_hashmap",
64+
types.intp(types.voidptr))
6865
_deleteiter_int_hashmap = types.ExternalFunction("deleteiter_int_hashmap",
6966
types.void(types.voidptr))
7067

@@ -97,11 +94,7 @@ def iterkey_int_hashmap():
9794
pass
9895

9996

100-
def itersize_int_hashmap():
101-
pass
102-
103-
104-
def iterelem_int_hashmap():
97+
def iterval_int_hashmap():
10598
pass
10699

107100

@@ -144,14 +137,9 @@ def iterkey_int_hashmap_overload(h):
144137
return lambda h: _iterkey_int_hashmap(h)
145138

146139

147-
@overload(itersize_int_hashmap)
148-
def itersize_int_hashmap_overload(h):
149-
return lambda h: _itersize_int_hashmap(h)
150-
151-
152-
@overload(iterelem_int_hashmap)
153-
def iterelem_int_hashmap_overload(h, i):
154-
return lambda h, i: _iterelem_int_hashmap(h, i)
140+
@overload(iterval_int_hashmap)
141+
def iterval_int_hashmap_overload(h):
142+
return lambda h: _iterval_int_hashmap(h)
155143

156144

157145
@overload(deleteiter_int_hashmap)

Diff for: sdc/tests/test_dataframe.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1806,10 +1806,8 @@ def test_impl():
18061806
it = sdc.concurrent_hash.createiter_int_hashmap(h)
18071807
while 0 == sdc.concurrent_hash.enditer_int_hashmap(it):
18081808
key = sdc.concurrent_hash.iterkey_int_hashmap(it)
1809-
sz = sdc.concurrent_hash.itersize_int_hashmap(it)
1810-
for i in range(sz):
1811-
val = sdc.concurrent_hash.iterelem_int_hashmap(it, i)
1812-
print(key, val)
1809+
val = sdc.concurrent_hash.iterval_int_hashmap(it)
1810+
print(key, val)
18131811

18141812
sdc.concurrent_hash.nextiter_int_hashmap(it)
18151813

0 commit comments

Comments
 (0)