Changes libcds library path
[junction.git] / junction / extra / impl / MapAdapter_LibCuckoo.h
1 /*------------------------------------------------------------------------
2   Junction: Concurrent data structures in C++
3   Copyright (c) 2016 Jeff Preshing
4
5   Distributed under the Simplified BSD License.
6   Original location: https://github.com/preshing/junction
7
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 ------------------------------------------------------------------------*/
12
13 #ifndef JUNCTION_EXTRA_IMPL_MAPADAPTER_LIBCUCKOO_H
14 #define JUNCTION_EXTRA_IMPL_MAPADAPTER_LIBCUCKOO_H
15
16 #include <junction/Core.h>
17
18 #if !JUNCTION_WITH_LIBCUCKOO
19 #error "You must configure with JUNCTION_WITH_LIBCUCKOO=1!"
20 #endif
21
22 #include <libcuckoo/cuckoohash_map.hh>
23
24 namespace junction {
25 namespace extra {
26
27 class MapAdapter {
28 public:
29     static TURF_CONSTEXPR const char* getMapName() { return "libcuckoo cuckoohash_map"; }
30
31     MapAdapter(ureg) {
32     }
33
34     class ThreadContext {
35     public:
36         ThreadContext(MapAdapter&, ureg) {
37         }
38
39         void registerThread() {
40         }
41
42         void unregisterThread() {
43         }
44
45         void update() {
46         }
47     };
48
49     class Map {
50     private:
51         cuckoohash_map<u32, void*> m_map;
52
53     public:
54         Map(ureg capacity) : m_map(capacity) {
55         }
56
57         void assign(u32 key, void* value) {
58             m_map.insert(key, value);
59         }
60
61         void* get(u32 key) {
62             void* result;
63             return m_map.find(key, result) ? result : NULL;
64         }
65
66         void erase(u32 key) {
67             m_map.erase(key);
68         }
69     };
70
71     static ureg getInitialCapacity(ureg maxPopulation) {
72         return maxPopulation / 4;
73     }
74 };
75
76 } // namespace extra
77 } // namespace junction
78
79 #endif // JUNCTION_EXTRA_IMPL_MAPADAPTER_LIBCUCKOO_H