2 #include "cliffc_hashtable.h"
6 template<typename TypeK, typename TypeV>
7 slot* const cliffc_hashtable<TypeK, TypeV>::MATCH_ANY = new slot(false, NULL);
9 template<typename TypeK, typename TypeV>
10 slot* const cliffc_hashtable<TypeK, TypeV>::NO_MATCH_OLD = new slot(false, NULL);
12 template<typename TypeK, typename TypeV>
13 slot* const cliffc_hashtable<TypeK, TypeV>::TOMBPRIME = new slot(true, NULL);
15 template<typename TypeK, typename TypeV>
16 slot* const cliffc_hashtable<TypeK, TypeV>::TOMBSTONE = new slot(false, NULL);
24 IntWrapper(int val) : _val(val) {}
26 IntWrapper() : _val(0) {}
28 IntWrapper(IntWrapper& copy) : _val(copy._val) {}
38 bool operator==(const IntWrapper& rhs) {
42 bool equals(const void *another) {
46 (IntWrapper*) another;
47 return ptr->_val == _val;
51 cliffc_hashtable<IntWrapper, IntWrapper> *table;
52 IntWrapper *val1, *val2;
53 IntWrapper *k0, *k1, *k2, *k3, *k4, *k5;
54 IntWrapper *v0, *v1, *v2, *v3, *v4, *v5;
56 void threadA(void *arg) {
59 Res = table->put(k3, v3);
60 res = Res == NULL ? 0 : Res->_val;
61 printf("Put1: key_%d, val_%d, res_%d\n", k3->_val, v3->_val, res);
64 res = Res == NULL ? 0 : Res->_val;
65 printf("Get2: key_%d, res_%d\n", k2->_val, res);
68 void threadB(void *arg) {
71 Res = table->put(k2, v2);
72 res = Res == NULL ? 0 : Res->_val;
73 printf("Put3: key_%d, val_%d, res_%d\n", k2->_val, v2->_val, res);
76 res = Res == NULL ? 0 : Res->_val;
77 printf("Get4: key_%d, res_%d\n", k3->_val, res);
80 int user_main(int argc, char *argv[]) {
82 table = new cliffc_hashtable<IntWrapper, IntWrapper>(32);
83 k1 = new IntWrapper(3);
84 k2 = new IntWrapper(5);
85 k3 = new IntWrapper(11);
86 k4 = new IntWrapper(7);
87 k5 = new IntWrapper(13);
89 v0 = new IntWrapper(2048);
90 v1 = new IntWrapper(1024);
91 v2 = new IntWrapper(47);
92 v3 = new IntWrapper(73);
93 v4 = new IntWrapper(81);
94 v5 = new IntWrapper(99);
96 thrd_create(&t1, threadA, NULL);
97 thrd_create(&t2, threadB, NULL);