edits
[cdsspec-compiler.git] / benchmark / cliffc-hashtable / main.cc
1 #include <iostream>
2 #include <threads.h>
3 #include "cliffc_hashtable.h"
4
5 using namespace std;
6
7 template<typename TypeK, typename TypeV>
8 slot* const cliffc_hashtable<TypeK, TypeV>::MATCH_ANY = new slot(false, NULL);
9
10 template<typename TypeK, typename TypeV>
11 slot* const cliffc_hashtable<TypeK, TypeV>::NO_MATCH_OLD = new slot(false, NULL);
12
13 template<typename TypeK, typename TypeV>
14 slot* const cliffc_hashtable<TypeK, TypeV>::TOMBPRIME = new slot(true, NULL);
15
16 template<typename TypeK, typename TypeV>
17 slot* const cliffc_hashtable<TypeK, TypeV>::TOMBSTONE = new slot(false, NULL);
18
19
20 class IntWrapper {
21         private:
22                 public:
23             int _val;
24
25                 IntWrapper(int val) : _val(val) {}
26
27                 IntWrapper() : _val(0) {}
28
29                 IntWrapper(IntWrapper& copy) : _val(copy._val) {}
30
31                 int get() {
32                         return _val;
33                 }
34
35                 int hashCode() {
36                         return _val;
37                 }
38                 
39                 bool operator==(const IntWrapper& rhs) {
40                         return false;
41                 }
42
43                 bool equals(const void *another) {
44                         if (another == NULL)
45                                 return false;
46                         IntWrapper *ptr =
47                                 (IntWrapper*) another;
48                         return ptr->_val == _val;
49                 }
50 };
51
52 cliffc_hashtable<IntWrapper, IntWrapper> *table;
53 IntWrapper *val1, *val2;
54 IntWrapper *k0, *k1, *k2, *k3, *k4, *k5;
55 IntWrapper *v0, *v1, *v2, *v3, *v4, *v5;
56
57 void threadA(void *arg) {
58         IntWrapper *Res;
59         int res;
60         Res = table->put(k3, v3);
61         res = Res == NULL ? 0 : Res->_val;
62         printf("Put1: key_%d, val_%d, res_%d\n", k3->_val, v3->_val, res);
63
64         Res = table->get(k2);
65         res = Res == NULL ? 0 : Res->_val;
66         printf("Get2: key_%d, res_%d\n", k2->_val, res);
67 }
68
69 void threadB(void *arg) {
70         IntWrapper *Res;
71         int res;
72         Res = table->put(k2, v2);
73         res = Res == NULL ? 0 : Res->_val;
74         printf("Put3: key_%d, val_%d, res_%d\n", k2->_val, v2->_val, res);
75
76         Res = table->get(k3);
77         res = Res == NULL ? 0 : Res->_val;
78         printf("Get4: key_%d, res_%d\n", k3->_val, res);
79 }
80
81 void threadC(void *arg) {
82 }
83
84 int user_main(int argc, char *argv[]) {
85         thrd_t t1, t2, t3;
86         table = new cliffc_hashtable<IntWrapper, IntWrapper>(32);
87     k1 = new IntWrapper(3);
88         k2 = new IntWrapper(5);
89         k3 = new IntWrapper(11);
90         k4 = new IntWrapper(7);
91         k5 = new IntWrapper(13);
92
93         v0 = new IntWrapper(2048);
94         v1 = new IntWrapper(1024);
95         v2 = new IntWrapper(47);
96         v3 = new IntWrapper(73);
97         v4 = new IntWrapper(81);
98         v5 = new IntWrapper(99);
99
100         thrd_create(&t1, threadA, NULL);
101         thrd_create(&t2, threadB, NULL);
102         thrd_create(&t3, threadC, NULL);
103         thrd_join(t1);
104         thrd_join(t2);
105         thrd_join(t3);
106         
107         return 0;
108 }
109
110