#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;
}
#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
: 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;
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);
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) {
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;
// 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];
// 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];