edits
[cdsspec-compiler.git] / benchmark / cliffc-hashtable / main.cc
index 6c75aff28849d0e77d3f77163e45153319c39a43..5c4f93c2b80d353dcbad61b22ea041ca01b7f338 100644 (file)
@@ -19,8 +19,8 @@ slot* const cliffc_hashtable<TypeK, TypeV>::TOMBSTONE = new slot(false, NULL);
 
 class IntWrapper {
        private:
-           int _val;
                public:
+           int _val;
 
                IntWrapper(int val) : _val(val) {}
 
@@ -35,6 +35,10 @@ class IntWrapper {
                int hashCode() {
                        return _val;
                }
+               
+               bool operator==(const IntWrapper& rhs) {
+                       return false;
+               }
 
                bool equals(const void *another) {
                        if (another == NULL)
@@ -45,13 +49,62 @@ class IntWrapper {
                }
 };
 
+cliffc_hashtable<IntWrapper, IntWrapper> *table;
+IntWrapper *val1, *val2;
+IntWrapper *k0, *k1, *k2, *k3, *k4, *k5;
+IntWrapper *v0, *v1, *v2, *v3, *v4, *v5;
+
+void threadA(void *arg) {
+       IntWrapper *Res;
+       int res;
+       Res = table->put(k3, v3);
+       res = Res == NULL ? 0 : Res->_val;
+       printf("Put1: key_%d, val_%d, res_%d\n", k3->_val, v3->_val, res);
+
+       Res = table->get(k2);
+       res = Res == NULL ? 0 : Res->_val;
+       printf("Get2: key_%d, res_%d\n", k2->_val, res);
+}
+
+void threadB(void *arg) {
+       IntWrapper *Res;
+       int res;
+       Res = table->put(k2, v2);
+       res = Res == NULL ? 0 : Res->_val;
+       printf("Put3: key_%d, val_%d, res_%d\n", k2->_val, v2->_val, res);
+
+       Res = table->get(k3);
+       res = Res == NULL ? 0 : Res->_val;
+       printf("Get4: key_%d, res_%d\n", k3->_val, res);
+}
+
+void threadC(void *arg) {
+}
+
 int user_main(int argc, char *argv[]) {
-       cliffc_hashtable<IntWrapper, IntWrapper> table;
-       IntWrapper k1(3), k2(4), v1(1), v2(2);
-       
+       thrd_t t1, t2, t3;
+       table = new cliffc_hashtable<IntWrapper, IntWrapper>(32);
+    k1 = new IntWrapper(3);
+       k2 = new IntWrapper(5);
+       k3 = new IntWrapper(11);
+       k4 = new IntWrapper(7);
+       k5 = new IntWrapper(13);
 
-       table.put(k1, v1);
-       table.put(k2, v2);
-       cout << table.get(k2)->get() << endl;
-       return 1;
+       v0 = new IntWrapper(2048);
+       v1 = new IntWrapper(1024);
+       v2 = new IntWrapper(47);
+       v3 = new IntWrapper(73);
+       v4 = new IntWrapper(81);
+       v5 = new IntWrapper(99);
+
+       thrd_create(&t1, threadA, NULL);
+       thrd_create(&t2, threadB, NULL);
+       thrd_create(&t3, threadC, NULL);
+       thrd_join(t1);
+       thrd_join(t2);
+       thrd_join(t3);
+       
+       return 0;
 }
+
+