]> git.seodisparate.com - SimpleArchiver/commitdiff
Convert "unsigned long long" to "uint64_t"
authorStephen Seo <seo.disparate@gmail.com>
Sat, 21 Sep 2024 02:55:26 +0000 (11:55 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Sat, 21 Sep 2024 02:55:26 +0000 (11:55 +0900)
Missed during previous changes using stdint.h .

src/algorithms/linear_congruential_gen.c
src/algorithms/linear_congruential_gen.h
src/data_structures/hash_map.c
src/data_structures/test.c

index e5a0705bd0bfb48835a9df5903e874cf8d6b2da1..3bfeb4afc69dd039c8af07c6ac39d15793e9837c 100644 (file)
 
 #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;
 }
index 93714f38613df821f9416c0ade3149a21db7c586..b97111ba35fe0b5b227671299dd8dca01057051c 100644 (file)
 #ifndef SEODISPARATE_COM_ALGORITHMS_LINEAR_CONGRUENTIAL_GEN_H_
 #define SEODISPARATE_COM_ALGORITHMS_LINEAR_CONGRUENTIAL_GEN_H_
 
+// Standard library includes.
+#include <stdint.h>
+
 #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
index bc91d11e38b26e8ccfeec18f862823f230e7ef76..cdbb70009340221d3cb66cdab7c630703ba0e26e 100644 (file)
@@ -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;
index 8dfda99b095af1fb1b99715cd88b5a49bdd51364..cbd0ae4497dca5b54c4f89e8b6d73c36a5ee06bf 100644 (file)
@@ -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];