From 4a69d281def062ea3e31f19809fe8826d56dc1c1 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Sat, 21 Sep 2024 11:55:26 +0900 Subject: [PATCH] Convert "unsigned long long" to "uint64_t" Missed during previous changes using stdint.h . --- src/algorithms/linear_congruential_gen.c | 6 ++---- src/algorithms/linear_congruential_gen.h | 9 +++++---- src/data_structures/hash_map.c | 25 +++++++++++------------- src/data_structures/test.c | 8 ++++---- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/algorithms/linear_congruential_gen.c b/src/algorithms/linear_congruential_gen.c index e5a0705..3bfeb4a 100644 --- a/src/algorithms/linear_congruential_gen.c +++ b/src/algorithms/linear_congruential_gen.c @@ -19,14 +19,12 @@ #include "linear_congruential_gen.h" -unsigned long long simple_archiver_algo_lcg(unsigned long long seed, - unsigned long long a, - unsigned long long c) { +uint64_t simple_archiver_algo_lcg(uint64_t seed, uint64_t a, uint64_t c) { // "m" is implicity 2^64. return seed * a + c; } -unsigned long long simple_archiver_algo_lcg_defaults(unsigned long long seed) { +uint64_t simple_archiver_algo_lcg_defaults(uint64_t seed) { // "m" is implicity 2^64. return seed * SC_ALGO_LCG_DEFAULT_A + SC_ALGO_LCG_DEFAULT_C; } diff --git a/src/algorithms/linear_congruential_gen.h b/src/algorithms/linear_congruential_gen.h index 93714f3..b97111b 100644 --- a/src/algorithms/linear_congruential_gen.h +++ b/src/algorithms/linear_congruential_gen.h @@ -20,13 +20,14 @@ #ifndef SEODISPARATE_COM_ALGORITHMS_LINEAR_CONGRUENTIAL_GEN_H_ #define SEODISPARATE_COM_ALGORITHMS_LINEAR_CONGRUENTIAL_GEN_H_ +// Standard library includes. +#include + #define SC_ALGO_LCG_DEFAULT_A 0x9ABD #define SC_ALGO_LCG_DEFAULT_C 0x2A9A9A9 -unsigned long long simple_archiver_algo_lcg(unsigned long long seed, - unsigned long long a, - unsigned long long c); +uint64_t simple_archiver_algo_lcg(uint64_t seed, uint64_t a, uint64_t c); -unsigned long long simple_archiver_algo_lcg_defaults(unsigned long long seed); +uint64_t simple_archiver_algo_lcg_defaults(uint64_t seed); #endif diff --git a/src/data_structures/hash_map.c b/src/data_structures/hash_map.c index bc91d11..cdbb700 100644 --- a/src/data_structures/hash_map.c +++ b/src/data_structures/hash_map.c @@ -74,13 +74,13 @@ int simple_archiver_hash_map_internal_pick_in_list(void *data, void *ud) { : 0; } -unsigned long long simple_archiver_hash_map_internal_key_to_hash( - const void *key, size_t key_size) { - unsigned long long seed = 0; - unsigned long long temp = 0; +uint64_t simple_archiver_hash_map_internal_key_to_hash(const void *key, + size_t key_size) { + uint64_t seed = 0; + uint64_t temp = 0; size_t count = 0; for (size_t idx = 0; idx < key_size; ++idx) { - temp |= ((unsigned long long)*((uint8_t *)key + idx)) << (8 * count); + temp |= ((uint64_t) * ((uint8_t *)key + idx)) << (8 * count); ++count; if (count >= 8) { count = 0; @@ -193,9 +193,8 @@ int simple_archiver_hash_map_insert(SDArchiverHashMap *hash_map, void *value, data->value_cleanup_fn = value_cleanup_fn; data->key_cleanup_fn = key_cleanup_fn; - unsigned long long hash = - simple_archiver_hash_map_internal_key_to_hash(key, key_size) % - hash_map->buckets_size; + uint64_t hash = simple_archiver_hash_map_internal_key_to_hash(key, key_size) % + hash_map->buckets_size; int result = simple_archiver_list_add_front( hash_map->buckets[hash], data, simple_archiver_hash_map_internal_cleanup_data); @@ -226,9 +225,8 @@ int simple_archiver_hash_map_insert(SDArchiverHashMap *hash_map, void *value, void *simple_archiver_hash_map_get(const SDArchiverHashMap *hash_map, const void *key, size_t key_size) { - unsigned long long hash = - simple_archiver_hash_map_internal_key_to_hash(key, key_size) % - hash_map->buckets_size; + uint64_t hash = simple_archiver_hash_map_internal_key_to_hash(key, key_size) % + hash_map->buckets_size; SDArchiverLLNode *node = hash_map->buckets[hash]->head; while (node) { @@ -246,9 +244,8 @@ void *simple_archiver_hash_map_get(const SDArchiverHashMap *hash_map, int simple_archiver_hash_map_remove(SDArchiverHashMap *hash_map, void *key, size_t key_size) { - unsigned long long hash = - simple_archiver_hash_map_internal_key_to_hash(key, key_size) % - hash_map->buckets_size; + uint64_t hash = simple_archiver_hash_map_internal_key_to_hash(key, key_size) % + hash_map->buckets_size; SDArchiverHashMapKeyData key_data; key_data.key = key; diff --git a/src/data_structures/test.c b/src/data_structures/test.c index 8dfda99..cbd0ae4 100644 --- a/src/data_structures/test.c +++ b/src/data_structures/test.c @@ -286,8 +286,8 @@ int main(void) { // Deterministic randomization. for (uint32_t idx = max - 1; idx-- > 0;) { - uint32_t other_idx = simple_archiver_algo_lcg_defaults(idx) % - (unsigned long long)(idx + 1); + uint32_t other_idx = + simple_archiver_algo_lcg_defaults(idx) % (uint64_t)(idx + 1); if (max - 1 != other_idx) { uint32_t temp = array[max - 1]; array[max - 1] = array[other_idx]; @@ -354,8 +354,8 @@ int main(void) { // Deterministic randomization. for (uint32_t idx = max - 1; idx-- > 0;) { - uint32_t other_idx = simple_archiver_algo_lcg_defaults(idx) % - (unsigned long long)(idx + 1); + uint32_t other_idx = + simple_archiver_algo_lcg_defaults(idx) % (uint64_t)(idx + 1); if (max - 1 != other_idx) { uint32_t temp = array[max - 1]; array[max - 1] = array[other_idx];