X-Git-Url: http://demsky.eecs.uci.edu/git/?p=model-checker-benchmarks.git;a=blobdiff_plain;f=cliffc-hashtable%2Fmain.cc;fp=cliffc-hashtable%2Fmain.cc;h=997703c630849cdb8b07b6ff56f52125996d8c1b;hp=0000000000000000000000000000000000000000;hb=a757e79cb775f910bae08e1522029639d8a1ea91;hpb=5ff38985cb34f816fd84685cb00b46f44d0b63d5 diff --git a/cliffc-hashtable/main.cc b/cliffc-hashtable/main.cc new file mode 100644 index 0000000..997703c --- /dev/null +++ b/cliffc-hashtable/main.cc @@ -0,0 +1,104 @@ +#include + +#include "cliffc_hashtable.h" + +#ifndef NORMAL +#include "threads.h" +#endif + +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::TOMBPRIME = new slot(true, NULL); + +template +slot* const cliffc_hashtable::TOMBSTONE = new slot(false, NULL); + +template +Hash cliffc_hashtable::hashFunc; + +template +KeyEqualsTo cliffc_hashtable::keyEqualsTo; + +template +ValEqualsTo cliffc_hashtable::valEqualsTo; + +class HashInt { + public: + int operator()(const int &val) const { + return val; + } +}; + +class EqualsToInt { + public: + bool operator()(const int &val1, const int &val2) const { + return val1 == val2; + } +}; + +int *k1, *k2, *v1, *v2; +cliffc_hashtable *table; + +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"); + } +} + +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"); + } +} + + +#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); + + 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