X-Git-Url: http://demsky.eecs.uci.edu/git/?p=model-checker-benchmarks.git;a=blobdiff_plain;f=concurrent-hashmap%2Ftestcase3.cc;fp=concurrent-hashmap%2Ftestcase3.cc;h=5b54a16206641b138abcb5bb4c92974ae82f611e;hp=0000000000000000000000000000000000000000;hb=3cb559e8fea6c3839ed20d6a10a636d728cf8695;hpb=c046bae812a0dd4d54be2236487c112d36641538 diff --git a/concurrent-hashmap/testcase3.cc b/concurrent-hashmap/testcase3.cc new file mode 100644 index 0000000..5b54a16 --- /dev/null +++ b/concurrent-hashmap/testcase3.cc @@ -0,0 +1,81 @@ +#include + +#ifdef WILDCARD +#include "hashmap_wildcard.h" +#else +#include "hashmap.h" +#endif + +HashMap *table; + +void printKey(Key *key) { + if (key) + printf("pos = (%d, %d, %d)\n", key->x, key->y, key->z); + else + printf("pos = NULL\n"); +} + +void printValue(Value *value) { + if (value) + printf("velocity = (%d, %d, %d)\n", value->vX, value->vY, value->vZ); + else + printf("velocity = NULL\n"); +} + +// Key(3, 2, 6) & Key(1, 3, 3) are hashed to the same slot -> 4 +// Key(1, 1, 1) & Key(3, 2, 2) are hashed to the same slot -> 0 +// Key(2, 4, 1) & Key(3, 4, 2) are hashed to the same slot -> 3 +// Key(3, 4, 5) & Key(1, 4, 3) & Key(1, 1, 6) are hashed to the same slot -> 5 +// Key(2, 4, 8) & Key(1, 3, 8) -> 9 +// Key(1, 4, 8) -> 10 +// Key(1, 3, 7) -> 8 +// Key(1, 2, 7) -> 7 +// Key(1, 2, 6) -> 6 + +void threadA(void *arg) { + Key *k1 = new Key(3, 4, 5); + Key *k2 = new Key(1, 4, 3); + Key *k3 = new Key(1, 1, 6); + Value *v2 = new Value(10, 10, 10); + Value *r1 = table->put(k2, v2); + //printValue(r1); + Value *r2 = table->get(k3); + printf("k1 -> %d:\n", table->hashKey(k1) % table->capacity); + printf("k2 -> %d:\n", table->hashKey(k2) % table->capacity); + printf("k3 -> %d:\n", table->hashKey(k3) % table->capacity); + //printValue(r2); +} + +void threadB(void *arg) { + Key *k1 = new Key(3, 4, 5); + Key *k2 = new Key(1, 4, 3); + Key *k3 = new Key(1, 1, 6); + Value *v3 = new Value(30, 40, 50); + Value *r3 = table->put(k3, v3); + //printValue(r3); + //Value *r4 = table->get(k1); + //printf("Thrd B:\n"); + //printValue(r4); +} + +int user_main(int argc, char *argv[]) { + Key *k1 = new Key(3, 4, 5); + Key *k2 = new Key(1, 4, 3); + Key *k3 = new Key(1, 1, 6); + //Key *k2 = new Key(1, 3, 3); + Value *v1 = new Value(111, 111, 111); + //Value *v2 = new Value(222, 222, 222); + thrd_t t1, t2; + table = new HashMap; + table->put(k1, v1); + //table->put(k2, v2); + + thrd_create(&t1, threadA, NULL); + thrd_create(&t2, threadB, NULL); + thrd_join(t1); + thrd_join(t2); + + return 0; +} + +