# HG changeset patch # User Mike Becker # Date 1761331930 -7200 # Node ID 244fb8bc358439353422be8d4e63c404ee51d8a6 # Parent 78ec3e2243e4873ee683ea63218e0b41a5b505ce fix hash map not being able to deal with 64-bit hashes diff -r 78ec3e2243e4 -r 244fb8bc3584 src/hash_map.c --- a/src/hash_map.c Thu Oct 23 17:54:17 2025 +0200 +++ b/src/hash_map.c Fri Oct 24 20:52:10 2025 +0200 @@ -86,7 +86,7 @@ struct cx_hash_map_s *hash_map = (struct cx_hash_map_s *) map; const CxAllocator *allocator = map->collection.allocator; - unsigned hash = key.hash; + uint64_t hash = key.hash; if (hash == 0) { cx_hash_murmur(&key); hash = key.hash; @@ -203,7 +203,7 @@ ) { struct cx_hash_map_s *hash_map = (struct cx_hash_map_s *) map; - unsigned hash = key.hash; + uint64_t hash = key.hash; if (hash == 0) { cx_hash_murmur(&key); hash = key.hash; diff -r 78ec3e2243e4 -r 244fb8bc3584 tests/test_hash_map.c --- a/tests/test_hash_map.c Thu Oct 23 17:54:17 2025 +0200 +++ b/tests/test_hash_map.c Fri Oct 24 20:52:10 2025 +0200 @@ -287,6 +287,21 @@ cx_testing_allocator_destroy(&talloc); } +CX_TEST(test_hash_map_integer_keys) { + CxMap *map = cxHashMapCreateSimple(sizeof(cxstring)); + CX_TEST_DO { + cxstring s1 = CX_STR("hello"); + cxstring s2 = CX_STR("world"); + + cxMapPut(map, UINT32_C(70875), &s1); + cxMapPut(map, UINT64_C(5785133750), &s2); + + CX_TEST_ASSERT(cx_strcmp_p(&s1, cxMapGet(map, UINT32_C(70875))) == 0); + CX_TEST_ASSERT(cx_strcmp_p(&s2, cxMapGet(map, UINT64_C(5785133750))) == 0); + } + cxMapFree(map); +} + CX_TEST(test_hash_map_remove_via_iterator) { CxTestingAllocator talloc; cx_testing_allocator_init(&talloc); @@ -916,6 +931,7 @@ cx_test_register(suite, test_hash_map_rehash_not_required); cx_test_register(suite, test_hash_map_clear); cx_test_register(suite, test_hash_map_store_ucx_strings); + cx_test_register(suite, test_hash_map_integer_keys); cx_test_register(suite, test_hash_map_remove_via_iterator); cx_test_register(suite, test_hash_map_simple_destructor_objects); cx_test_register(suite, test_hash_map_advanced_destructor_objects);