X-Git-Url: http://demsky.eecs.uci.edu/git/?p=model-checker-benchmarks.git;a=blobdiff_plain;f=cliffc-hashtable%2Fmain.cc;h=8d94528f21e0d6fa99e2a6e259c761544bfdfea7;hp=997703c630849cdb8b07b6ff56f52125996d8c1b;hb=e326d381460902d927b8862149ce5382f8509bbd;hpb=f19c4f0d0d8c054fdea82137c57dc0dca3059704 diff --git a/cliffc-hashtable/main.cc b/cliffc-hashtable/main.cc index 997703c..8d94528 100644 --- a/cliffc-hashtable/main.cc +++ b/cliffc-hashtable/main.cc @@ -1,104 +1,105 @@ #include - +#include #include "cliffc_hashtable.h" -#ifndef NORMAL -#include "threads.h" -#endif +using namespace std; -template -slot* const cliffc_hashtable::MATCH_ANY = new slot(false, NULL); +template +slot* const cliffc_hashtable::MATCH_ANY = new slot(false, NULL); -template -slot* const cliffc_hashtable::NO_MATCH_OLD = new slot(false, NULL); +template +slot* const cliffc_hashtable::NO_MATCH_OLD = new slot(false, NULL); -template -slot* const cliffc_hashtable::TOMBPRIME = new slot(true, NULL); +template +slot* const cliffc_hashtable::TOMBPRIME = new slot(true, NULL); -template -slot* const cliffc_hashtable::TOMBSTONE = new slot(false, NULL); +template +slot* const cliffc_hashtable::TOMBSTONE = new slot(false, NULL); -template -Hash cliffc_hashtable::hashFunc; -template -KeyEqualsTo cliffc_hashtable::keyEqualsTo; +class IntWrapper { + private: + public: + int _val; -template -ValEqualsTo cliffc_hashtable::valEqualsTo; + IntWrapper(int val) : _val(val) {} -class HashInt { - public: - int operator()(const int &val) const { - return val; - } -}; + IntWrapper() : _val(0) {} + + IntWrapper(IntWrapper& copy) : _val(copy._val) {} -class EqualsToInt { - public: - bool operator()(const int &val1, const int &val2) const { - return val1 == val2; - } + int get() { + return _val; + } + + int hashCode() { + return _val; + } + + bool operator==(const IntWrapper& rhs) { + return false; + } + + bool equals(const void *another) { + if (another == NULL) + return false; + IntWrapper *ptr = + (IntWrapper*) another; + return ptr->_val == _val; + } }; -int *k1, *k2, *v1, *v2; -cliffc_hashtable *table; +cliffc_hashtable *table; +IntWrapper *val1, *val2; +IntWrapper *k0, *k1, *k2, *k3, *k4, *k5; +IntWrapper *v0, *v1, *v2, *v3, *v4, *v5; void threadA(void *arg) { - table->put(*k1, *v1); - int *r1 = table->get(*k2); - if (r1) { - printf("r1=%d\n", *r1); - } else { - printf("r1=NULL\n"); - } + 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) { - table->put(*k2, *v2); - int *r2 = table->get(*k1); - if (r2) { - printf("r2=%d\n", *r2); - } else { - printf("r2=NULL\n"); - } + 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); } - -#ifdef NORMAL -int main(int argc, char *argv[]) { - table = new cliffc_hashtable(); - k1 = new int(3); - k2 = new int(4); - v1 = new int(1); - v2 = new int(2); +int user_main(int argc, char *argv[]) { + thrd_t t1, t2; + table = new cliffc_hashtable(32); + k1 = new IntWrapper(3); + k2 = new IntWrapper(5); + k3 = new IntWrapper(11); + k4 = new IntWrapper(7); + k5 = new IntWrapper(13); + + 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_join(t1); + thrd_join(t2); - table->put(*k1, *v1); - table->put(*k2, *v2); - int *r1 = table->get(*k2); - if (r1) { - printf("r1=%d\n", *r1); - } else { - printf("r1=NULL\n"); - } - return 0; } -#else -int user_main(int argc, char *argv[]) { - table = new cliffc_hashtable(); - k1 = new int(3); - k2 = new int(4); - v1 = new int(1); - v2 = new int(2); - thrd_t A, B, C; - thrd_create(&A, &threadA, NULL); - thrd_create(&B, &threadB, NULL); - thrd_join(A); - thrd_join(B); - - return 0; -} -#endif