Small code clean-up.

This commit is contained in:
LoRd_MuldeR 2022-11-25 13:06:54 +01:00
parent e550528fe8
commit 4dfc5f5279
2 changed files with 39 additions and 32 deletions

View File

@ -276,6 +276,8 @@ static int test_function_3(hash_set_t *const hash_set)
random_t random; random_t random;
random_init(&random); random_init(&random);
for (size_t r = 0U; r < 3U; ++r)
{
for (;;) for (;;)
{ {
const uint64_t rnd = random_next(&random) & UINT64_C(0x3FFFFFFFFFFFFFF); const uint64_t rnd = random_next(&random) & UINT64_C(0x3FFFFFFFFFFFFFF);
@ -312,6 +314,7 @@ static int test_function_3(hash_set_t *const hash_set)
puts("Clear operation has failed!"); puts("Clear operation has failed!");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
}
PRINT_SET_INFO(3); PRINT_SET_INFO(3);
puts("---------"); puts("---------");
@ -323,13 +326,15 @@ static int test_function_3(hash_set_t *const hash_set)
/* TEST #4 */ /* TEST #4 */
/* ========================================================================= */ /* ========================================================================= */
#define LIMIT (UINT64_MAX >> 2)
static int test_function_4(hash_set_t *const hash_set) static int test_function_4(hash_set_t *const hash_set)
{ {
size_t capacity, valid, deleted, limit; size_t capacity, valid, deleted, limit;
uint8_t spinner = 0U; uint8_t spinner = 0U;
clock_t last_update = clock(); clock_t last_update = clock();
for (uint64_t value = 0U; value < ((uint64_t)INT32_MAX); ++value) for (uint64_t value = 0U; value < LIMIT; ++value)
{ {
const errno_t error = hash_set_insert(hash_set, value); const errno_t error = hash_set_insert(hash_set, value);
if (error) if (error)
@ -349,7 +354,7 @@ static int test_function_4(hash_set_t *const hash_set)
} }
} }
for (uint64_t value = 0U; value < ((uint64_t)INT32_MAX); ++value) for (uint64_t value = 0U; value < LIMIT; ++value)
{ {
const errno_t error = hash_set_remove(hash_set, value); const errno_t error = hash_set_remove(hash_set, value);
if (error) if (error)

View File

@ -261,10 +261,12 @@ static INLINE void put_value(struct _hash_set_data *const data, const size_t ind
static size_t INLINE compute_limit(const size_t capacity, const double load_factor) static size_t INLINE compute_limit(const size_t capacity, const double load_factor)
{ {
size_t limit = round_sz(capacity * load_factor); size_t limit = round_sz(capacity * load_factor);
while (capacity && (limit >= capacity)) while (capacity && (limit >= capacity))
{ {
limit = safe_decr(limit); limit = safe_decr(limit);
} }
return limit; return limit;
} }