Changes libcds library path
[junction.git] / test / test.h
1 #ifndef _JUNCTION_TEST_H
2 #define _JUNCTION_TEST_H
3
4 #include <junction/ConcurrentMap_Crude.h>
5 #include <junction/ConcurrentMap_Grampa.h>
6 #include <junction/ConcurrentMap_Leapfrog.h>
7 #include <junction/ConcurrentMap_Linear.h>
8
9 #include <cds_test/stress_test.h>
10 #include <cds_test/stress_test_util.h>
11
12 #include <algorithm>
13 #include <iostream>
14 #include <memory>
15 #include <random>
16 #include <thread>
17
18 namespace junction_test {
19
20 typedef junction::ConcurrentMap_Grampa<size_t, size_t> GrampaMap;
21 typedef junction::ConcurrentMap_Linear<size_t, size_t> LinearMap;
22 typedef junction::ConcurrentMap_Leapfrog<size_t, size_t> LeapfrogMap;
23 typedef junction::ConcurrentMap_Crude<size_t, size_t> CrudeMap;
24
25 template <typename Map, typename Key, typename Value>
26 static bool map_insert(Map* map, Key key, Value value) {
27   auto iter = map->insertOrFind(key);
28   if (!iter.getValue() || iter.getValue() != value) {
29     // Insert/update the <key,value> pair
30     iter.assignValue(value);
31     return true;
32   } else {
33     return false;
34   }
35 }
36
37 template <typename Map, typename Key>
38 static bool map_delete(Map* map, Key key) {
39   auto iter = map->find(key);
40   if (iter.getValue()) {
41     iter.eraseValue();
42     return true;
43   } else {
44     return false;
45   }
46 }
47
48 template <typename Map, typename Key> static bool map_find(Map* map, Key key) {
49   auto iter = map->find(key);
50   if (iter.getValue()) {
51     return true;
52   } else {
53     return false;
54   }
55 }
56
57 // Specialization for CrudeMap
58 template <typename Key, typename Value>
59 static bool map_insert(CrudeMap* map, Key key, Value value) {
60   auto old_val = map->get(key);
61   if (!old_val || old_val != value) {
62     map->assign(key, value);
63     return true;
64   } else {
65     return false;
66   }
67 }
68
69 template <typename Key> static bool map_delete(CrudeMap* map, Key key) {
70   if (map->get(key)) {
71     map->assign(key, ((Key)0));
72     return true;
73   } else {
74     return false;
75   }
76 }
77
78 template <typename Key> static bool map_find(CrudeMap* map, Key key) {
79   return map->get(key) != ((Key)0);
80 }
81
82 } // namespace junction_test
83
84 #endif