1.1 --- a/test/test_map.cpp Fri May 27 17:40:27 2022 +0200 1.2 +++ b/test/test_map.cpp Wed Jun 08 21:33:31 2022 +0200 1.3 @@ -72,9 +72,9 @@ 1.4 { 1.5 auto keyiter = cxMapIteratorKeys(map); 1.6 std::unordered_set<std::string> keys; 1.7 - cx_foreach(CxDataPtr*, elem, keyiter) { 1.8 + cx_foreach(CxHashKey*, elem, keyiter) { 1.9 // we use that our test keys contain NULL-terminated strings 1.10 - keys.insert(std::string(reinterpret_cast<const char *>(elem->data))); 1.11 + keys.insert(std::string(elem->data.cstr)); 1.12 } 1.13 EXPECT_EQ(keyiter.index, map->size); 1.14 ASSERT_EQ(keys.size(), map->size); 1.15 @@ -103,7 +103,7 @@ 1.16 auto pairiter = cxMapIterator(map); 1.17 std::unordered_map<std::string, std::string> pairs; 1.18 cx_foreach(CxMapEntry*, entry, pairiter) { 1.19 - pairs[std::string((char const *) entry->key->data)] = std::string((char *) entry->value); 1.20 + pairs[std::string(entry->key->data.cstr)] = std::string((char *) entry->value); 1.21 } 1.22 EXPECT_EQ(pairiter.index, map->size); 1.23 ASSERT_EQ(pairs.size(), refmap.size()); 1.24 @@ -144,7 +144,8 @@ 1.25 1.26 // execute operations and verify results 1.27 for (auto &&op: ops) { 1.28 - CxDataPtr key = cxMapKeyStr(op.key); 1.29 + CxHashKey key = cx_hash_key_str(op.key); 1.30 + key.hash = 0; // force the hash map to compute the hash 1.31 if (op.op == map_operation::put) { 1.32 // execute a put operation and verify that the exact value can be read back 1.33 refmap[std::string(op.key)] = std::string(op.value); 1.34 @@ -176,26 +177,26 @@ 1.35 CxTestingAllocator allocator; 1.36 auto map = cxHashMapCreate(&allocator, 4); 1.37 1.38 - cxMapPut(map, cxMapKeyStr("key 1"), (void *) "val 1"); 1.39 - cxMapPut(map, cxMapKeyStr("key 2"), (void *) "val 2"); 1.40 - cxMapPut(map, cxMapKeyStr("key 3"), (void *) "val 3"); 1.41 - cxMapPut(map, cxMapKeyStr("key 4"), (void *) "val 4"); 1.42 - cxMapPut(map, cxMapKeyStr("key 5"), (void *) "val 5"); 1.43 - cxMapPut(map, cxMapKeyStr("key 6"), (void *) "val 6"); 1.44 + cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1"); 1.45 + cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2"); 1.46 + cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3"); 1.47 + cxMapPut(map, cx_hash_key_str("key 4"), (void *) "val 4"); 1.48 + cxMapPut(map, cx_hash_key_str("key 5"), (void *) "val 5"); 1.49 + cxMapPut(map, cx_hash_key_str("key 6"), (void *) "val 6"); 1.50 1.51 auto iter = cxMapIterator(map); 1.52 cx_foreach(CxMapEntry*, entry, iter) { 1.53 - if (entry->key->data[4] % 2 == 1) iter.remove = true; 1.54 + if (entry->key->data.cstr[4] % 2 == 1) iter.remove = true; 1.55 } 1.56 EXPECT_EQ(map->size, 3); 1.57 EXPECT_EQ(iter.index, map->size); 1.58 1.59 - EXPECT_EQ(cxMapGet(map, cxMapKeyStr("key 1")), nullptr); 1.60 - EXPECT_NE(cxMapGet(map, cxMapKeyStr("key 2")), nullptr); 1.61 - EXPECT_EQ(cxMapGet(map, cxMapKeyStr("key 3")), nullptr); 1.62 - EXPECT_NE(cxMapGet(map, cxMapKeyStr("key 4")), nullptr); 1.63 - EXPECT_EQ(cxMapGet(map, cxMapKeyStr("key 5")), nullptr); 1.64 - EXPECT_NE(cxMapGet(map, cxMapKeyStr("key 6")), nullptr); 1.65 + EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 1")), nullptr); 1.66 + EXPECT_NE(cxMapGet(map, cx_hash_key_str("key 2")), nullptr); 1.67 + EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 3")), nullptr); 1.68 + EXPECT_NE(cxMapGet(map, cx_hash_key_str("key 4")), nullptr); 1.69 + EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 5")), nullptr); 1.70 + EXPECT_NE(cxMapGet(map, cx_hash_key_str("key 6")), nullptr); 1.71 1.72 cxMapDestroy(map); 1.73 EXPECT_TRUE(allocator.verify()); 1.74 @@ -205,12 +206,12 @@ 1.75 CxTestingAllocator allocator; 1.76 auto map = cxHashMapCreate(&allocator, 8); 1.77 1.78 - cxMapPut(map, cxMapKeyStr("key 1"), (void *) "val 1"); 1.79 - cxMapPut(map, cxMapKeyStr("key 2"), (void *) "val 2"); 1.80 - cxMapPut(map, cxMapKeyStr("key 3"), (void *) "val 3"); 1.81 - cxMapPut(map, cxMapKeyStr("key 4"), (void *) "val 4"); 1.82 - cxMapPut(map, cxMapKeyStr("key 5"), (void *) "val 5"); 1.83 - cxMapPut(map, cxMapKeyStr("key 6"), (void *) "val 6"); 1.84 + cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1"); 1.85 + cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2"); 1.86 + cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3"); 1.87 + cxMapPut(map, cx_hash_key_str("key 4"), (void *) "val 4"); 1.88 + cxMapPut(map, cx_hash_key_str("key 5"), (void *) "val 5"); 1.89 + cxMapPut(map, cx_hash_key_str("key 6"), (void *) "val 6"); 1.90 1.91 // 6/8 does not exceed 0.75, therefore the function should not rehash 1.92 int result = cxMapRehash(map); 1.93 @@ -225,26 +226,26 @@ 1.94 CxTestingAllocator allocator; 1.95 auto map = cxHashMapCreate(&allocator, 8); 1.96 1.97 - cxMapPut(map, cxMapKeyStr("key 1"), (void *) "val 1"); 1.98 - cxMapPut(map, cxMapKeyStr("key 2"), (void *) "val 2"); 1.99 - cxMapPut(map, cxMapKeyStr("key 3"), (void *) "val 3"); 1.100 - cxMapPut(map, cxMapKeyStr("key 4"), (void *) "val 4"); 1.101 - cxMapPut(map, cxMapKeyStr("key 5"), (void *) "val 5"); 1.102 - cxMapPut(map, cxMapKeyStr("key 6"), (void *) "val 6"); 1.103 - cxMapPut(map, cxMapKeyStr("key 7"), (void *) "val 7"); 1.104 + cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1"); 1.105 + cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2"); 1.106 + cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3"); 1.107 + cxMapPut(map, cx_hash_key_str("key 4"), (void *) "val 4"); 1.108 + cxMapPut(map, cx_hash_key_str("key 5"), (void *) "val 5"); 1.109 + cxMapPut(map, cx_hash_key_str("key 6"), (void *) "val 6"); 1.110 + cxMapPut(map, cx_hash_key_str("key 7"), (void *) "val 7"); 1.111 1.112 int result = cxMapRehash(map); 1.113 EXPECT_EQ(result, 0); 1.114 EXPECT_EQ(reinterpret_cast<struct cx_hash_map_s *>(map)->bucket_count, 17); 1.115 EXPECT_EQ(map->size, 7); 1.116 1.117 - EXPECT_EQ(strcmp((char *) cxMapGet(map, cxMapKeyStr("key 1")), "val 1"), 0); 1.118 - EXPECT_EQ(strcmp((char *) cxMapGet(map, cxMapKeyStr("key 2")), "val 2"), 0); 1.119 - EXPECT_EQ(strcmp((char *) cxMapGet(map, cxMapKeyStr("key 3")), "val 3"), 0); 1.120 - EXPECT_EQ(strcmp((char *) cxMapGet(map, cxMapKeyStr("key 4")), "val 4"), 0); 1.121 - EXPECT_EQ(strcmp((char *) cxMapGet(map, cxMapKeyStr("key 5")), "val 5"), 0); 1.122 - EXPECT_EQ(strcmp((char *) cxMapGet(map, cxMapKeyStr("key 6")), "val 6"), 0); 1.123 - EXPECT_EQ(strcmp((char *) cxMapGet(map, cxMapKeyStr("key 7")), "val 7"), 0); 1.124 + EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 1")), "val 1"), 0); 1.125 + EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 2")), "val 2"), 0); 1.126 + EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 3")), "val 3"), 0); 1.127 + EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 4")), "val 4"), 0); 1.128 + EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 5")), "val 5"), 0); 1.129 + EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 6")), "val 6"), 0); 1.130 + EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 7")), "val 7"), 0); 1.131 1.132 cxMapDestroy(map); 1.133 EXPECT_TRUE(allocator.verify());