add another testcase for dekker-fences
[model-checker-benchmarks.git] / concurrent-hashmap / main.cc
index fcb1186ca2b22a112db356b4ec186ce6f37cb65c..084230eb3045e0cebc2efee4872258ce9218a613 100644 (file)
@@ -4,8 +4,6 @@
 
 HashMap *table;
 
-Key *k1, *k2;
-Value *r1, *r2, *r3, *r4, *v1, *v2;
 
 void printKey(Key *key) {
        if (key)
@@ -21,32 +19,51 @@ void printValue(Value *value) {
                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) are hashed to the same slot -> 5
+
+
 void threadA(void *arg) {
-       k1 = new Key(1, 1, 1);
-       k2 = new Key(3, 4, 5);
-       v1 = new Value(10, 10, 10);
-       r1 = table->put(k1, v1);
+       Key *k1 = new Key(3, 2, 6);
+       Key *k2 = new Key(1, 1, 1);
+       Value *v1 = new Value(10, 10, 10);
+       Value *r1 = table->put(k1, v1);
        //printValue(r1);
-       r2 = table->get(k2);
-       printf("Thrd A:\n");
+       Value *r2 = table->get(k2);
+       //printf("Thrd A:\n");
        printValue(r2);
 }
 
 void threadB(void *arg) {
-       k1 = new Key(1, 1, 1);
-       k2 = new Key(3, 4, 5);
-       v2 = new Value(30, 40, 50);
-       r3 = table->put(k2, v2);
+       Key *k1 = new Key(3, 2, 6);
+       Key *k2 = new Key(1, 1, 1);
+       Value *v2 = new Value(30, 40, 50);
+       Value *r3 = table->put(k2, v2);
        //printValue(r3);
-       r4 = table->get(k1);
+       Value *r4 = table->get(k1);
        printf("Thrd B:\n");
        printValue(r4);
 }
 
 int user_main(int argc, char *argv[]) {
        thrd_t t1, t2;
+
+       Key *k1 = new Key(1, 3, 3);
+       Key *k1_prime = new Key(3, 2, 6);
+       Key *k2 = new Key(3, 2, 2);
+       Key *k2_prime = new Key(1, 1, 1);
+       Value *v1 = new Value(111, 111, 111);
+       Value *v2 = new Value(222, 222, 222);
+
        table = new HashMap;
 
+       printf("Key1: %d\n", table->hashKey(k1) % table->capacity);
+       printf("Key1': %d\n", table->hashKey(k1_prime) % table->capacity);
+       printf("Key2: %d\n", table->hashKey(k2) % table->capacity);
+       printf("Key2': %d\n", table->hashKey(k2_prime) % table->capacity);
+
        thrd_create(&t1, threadA, NULL);
        thrd_create(&t2, threadB, NULL);
        thrd_join(t1);