1 /*------------------------------------------------------------------------
2 Junction: Concurrent data structures in C++
3 Copyright (c) 2016 Jeff Preshing
5 Distributed under the Simplified BSD License.
6 Original location: https://github.com/preshing/junction
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the LICENSE file for more information.
11 ------------------------------------------------------------------------*/
13 #ifndef JUNCTION_EXTRA_IMPL_MAPADAPTER_TERVEL_H
14 #define JUNCTION_EXTRA_IMPL_MAPADAPTER_TERVEL_H
16 #include <junction/Core.h>
18 #if !JUNCTION_WITH_TERVEL
19 #error "You must configure with JUNCTION_WITH_TERVEL=1!"
22 #include <tervel/util/tervel.h>
23 #include <tervel/containers/wf/hash-map/wf_hash_map.h>
30 static TURF_CONSTEXPR const char* MapName = "Tervel HashMap";
32 tervel::Tervel m_tervel;
34 MapAdapter(ureg numThreads) : m_tervel(numThreads) {
39 MapAdapter& m_adapter;
40 tervel::ThreadContext* m_context;
42 ThreadContext(MapAdapter& adapter, ureg) : m_adapter(adapter), m_context(NULL) {
45 void registerThread() {
46 m_context = new tervel::ThreadContext(&m_adapter.m_tervel);
49 void unregisterThread() {
59 tervel::containers::wf::HashMap<u64, u64> m_map;
62 Map(ureg capacity) : m_map(capacity, 3) {
65 void set(u32 key, void* value) {
66 m_map.insert(key, (u64) value);
70 typename tervel::containers::wf::HashMap<u64, u64>::ValueAccessor va;
71 if (m_map.at(key, va))
72 return (void*) *va.value();
82 static ureg getInitialCapacity(ureg maxPopulation) {
83 return maxPopulation / 4;
88 } // namespace junction
90 #endif // JUNCTION_EXTRA_IMPL_MAPADAPTER_TERVEL_H