save
[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
55 void threadA(void *arg) {
56         /*
57         IntWrapper *k1 = new IntWrapper(3), *k2 = new IntWrapper(5),
58                 *k3 = new IntWrapper(1024), *k4 = new IntWrapper(1025);
59         IntWrapper *v1 = new IntWrapper(1024), *v2 = new IntWrapper(1025),
60                 *v3 = new IntWrapper(73), *v4 = new IntWrapper(81);
61         table->put(k1, v1);
62         table->put(k2, v2);
63         val1 = table->get(k3);
64         table->put(k3, v3);
65         */
66 }
67
68 void threadB(void *arg) {
69         /*
70         IntWrapper *k1 = new IntWrapper(3), *k2 = new IntWrapper(5),
71                 *k3 = new IntWrapper(1024), *k4 = new IntWrapper(1025);
72         IntWrapper *v1 = new IntWrapper(1024), *v2 = new IntWrapper(1025),
73                 *v3 = new IntWrapper(73), *v4 = new IntWrapper(81);
74         table->put(k1, v3);
75         val1 = table->get(k2);
76         table->put(k2, v4);
77         val1 = table->get(k2);
78         */
79 }
80
81 void threadMain(void *arg) {
82         /*
83         for (int i = 0; i < 5; i++) {
84                 IntWrapper *k = new IntWrapper(i), *v = new IntWrapper(i * 2);
85                 table->put(k, v);
86         }
87         */
88         IntWrapper *k1 = new IntWrapper(3), *k2 = new IntWrapper(5),
89                 *k3 = new IntWrapper(1024), *k4 = new IntWrapper(1025);
90         IntWrapper *v1 = new IntWrapper(1024), *v2 = new IntWrapper(1025),
91                 *v3 = new IntWrapper(73), *v4 = new IntWrapper(81);
92         table->put(k1, v3);
93         val1 = table->get(k2);
94 }
95
96 int user_main(int argc, char *argv[]) {
97         thrd_t t1, t2;
98         table = new cliffc_hashtable<IntWrapper, IntWrapper>();
99         val1 = NULL;
100         val2 = NULL;
101         //threadMain(NULL);
102
103         thrd_create(&t1, threadA, NULL);
104         thrd_create(&t2, threadB, NULL);
105         threadMain(NULL);
106
107         thrd_join(t1);
108         thrd_join(t2);
109         /*
110         if (val1 == NULL) {
111                 cout << "val1: NULL" << endl;
112         } else {
113                 cout << val1->get() << endl;
114         }
115         //MODEL_ASSERT(val1 == NULL || val1->get() == 2 || val1->get() == 81);
116         if (val2 == NULL) {
117                 cout << "val2: NULL" << endl;
118         } else {
119                 cout << val2->get() << endl;
120         }
121         */
122         return 0;
123 }
124