Adding functions table to hashset and fixing root makefile

This commit is contained in:
Leonardo committed 2020-02-06 14:10:12 -03:00
1 parent 7dd6218017
commit fa49fddd8f
5 files changed
+190 -124

No files matched your search

+1 -1
View File
@@ -14,7 +14,7 @@ sac: FORCE
clang-format --style=file -i ./src/sac/*.h
utl: FORCE
clang-format --style=file -i ./utl/sac/*.h
clang-format --style=file -i ./src/utl/*.h
tests: FORCE
clang-format --style=file -i ./tests/main/unt/*.c ./tests/*.c
+86 -67
View File
@@ -148,8 +148,8 @@ static const char *cmc_string_fmt_hashset = "struct %s<%s> "
"capacity:%" PRIuMAX ", "
"count:%" PRIuMAX ", "
"load:%lf, "
"cmp:%p, "
"hash:%p, "
"flag:%d, "
"f_val:%p, "
"alloc:%p, "
"callbacks: %p }";
@@ -198,23 +198,23 @@ struct cmc_callbacks_hashset
/* Load factor in range (0.0, 1.0) */ \
double load; \
\
/* Element comparison function */ \
int (*cmp)(V, V); \
/* Flags indicating errors or success */ \
int flag; \
\
/* Element hash function */ \
size_t (*hash)(V); \
\
/* Function that returns an iterator to the start of the hashset */ \
struct SNAME##_iter (*it_start)(struct SNAME *); \
\
/* Function that returns an iterator to the end of the hashset */ \
struct SNAME##_iter (*it_end)(struct SNAME *); \
/* Value function table */ \
struct SNAME##_ftab_val *f_val; \
\
/* Custom allocation functions */ \
struct cmc_alloc_node *alloc; \
\
/* Custom callback functions */ \
struct cmc_callbacks_hashset *callbacks; \
\
/* Function that returns an iterator to the start of the hashset */ \
struct SNAME##_iter (*it_start)(struct SNAME *); \
\
/* Function that returns an iterator to the end of the hashset */ \
struct SNAME##_iter (*it_end)(struct SNAME *); \
}; \
\
struct SNAME##_entry \
@@ -222,14 +222,36 @@ struct cmc_callbacks_hashset
/* Entry element */ \
V value; \
\
/* The distance of this node to its original position, used by \
* robin-hood hashing */ \
/* The distance of this node to its original position, used by */ \
/* robin-hood hashing */ \
size_t dist; \
\
/* The sate of this node (DELETED, EMPTY, FILLED) */ \
enum cmc_entry_state state; \
}; \
\
/* Value struct function table */ \
struct SNAME##_ftab_val \
{ \
/* Comparator function */ \
int (*cmp)(V, V); \
\
/* Copy function */ \
V (*cpy)(V); \
\
/* To string function */ \
bool (*str)(FILE *, V); \
\
/* Free from memory function */ \
void (*free)(V); \
\
/* Hash function */ \
size_t (*hash)(V); \
\
/* Priority function */ \
int (*pri)(V, V); \
}; \
\
/* Hashset Iterator */ \
struct SNAME##_iter \
{ \
@@ -258,13 +280,13 @@ struct cmc_callbacks_hashset
/* Collection Functions */ \
/* Collection Allocation and Deallocation */ \
struct SNAME *PFX##_new(size_t capacity, double load, \
int (*compare)(V, V), size_t (*hash)(V)); \
struct SNAME##_ftab_val *f_val); \
struct SNAME *PFX##_new_custom(size_t capacity, double load, \
int (*compare)(V, V), size_t (*hash)(V), \
struct SNAME##_ftab_val *f_val, \
struct cmc_alloc_node *alloc, \
struct cmc_callbacks_hashset *callbacks); \
void PFX##_clear(struct SNAME *_set_, void (*deallocator)(V)); \
void PFX##_free(struct SNAME *_set_, void (*deallocator)(V)); \
void PFX##_clear(struct SNAME *_set_); \
void PFX##_free(struct SNAME *_set_); \
/* Customization of Allocation and Callbacks */ \
void PFX##_customize(struct SNAME *_set_, struct cmc_alloc_node *alloc, \
struct cmc_callbacks_hashset *callbacks); \
@@ -283,7 +305,7 @@ struct cmc_callbacks_hashset
double PFX##_load(struct SNAME *_set_); \
/* Collection Utility */ \
bool PFX##_resize(struct SNAME *_set_, size_t capacity); \
struct SNAME *PFX##_copy_of(struct SNAME *_set_, V (*copy_func)(V)); \
struct SNAME *PFX##_copy_of(struct SNAME *_set_); \
bool PFX##_equals(struct SNAME *_set1_, struct SNAME *_set2_); \
struct cmc_string PFX##_to_string(struct SNAME *_set_); \
\
@@ -335,7 +357,7 @@ struct cmc_callbacks_hashset
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_set_); \
\
struct SNAME *PFX##_new(size_t capacity, double load, \
int (*compare)(V, V), size_t (*hash)(V)) \
struct SNAME##_ftab_val *f_val) \
{ \
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
\
@@ -346,6 +368,9 @@ struct cmc_callbacks_hashset
if (capacity >= UINTMAX_MAX * load) \
return NULL; \
\
if (!f_val) \
return NULL; \
\
size_t real_capacity = PFX##_impl_calculate_size(capacity / load); \
\
struct SNAME *_set_ = alloc->malloc(sizeof(struct SNAME)); \
@@ -365,20 +390,18 @@ struct cmc_callbacks_hashset
_set_->count = 0; \
_set_->capacity = real_capacity; \
_set_->load = load; \
_set_->cmp = compare; \
_set_->hash = hash; \
\
_set_->it_start = PFX##_impl_it_start; \
_set_->it_end = PFX##_impl_it_end; \
\
_set_->flag = cmc_flags.OK; \
_set_->f_val = f_val; \
_set_->alloc = alloc; \
_set_->callbacks = NULL; \
_set_->it_start = PFX##_impl_it_start; \
_set_->it_end = PFX##_impl_it_end; \
\
return _set_; \
} \
\
struct SNAME *PFX##_new_custom( \
size_t capacity, double load, int (*compare)(V, V), size_t (*hash)(V), \
size_t capacity, double load, struct SNAME##_ftab_val *f_val, \
struct cmc_alloc_node *alloc, struct cmc_callbacks_hashset *callbacks) \
{ \
if (capacity == 0 || load <= 0 || load >= 1) \
@@ -388,6 +411,9 @@ struct cmc_callbacks_hashset
if (capacity >= UINTMAX_MAX * load) \
return NULL; \
\
if (!f_val) \
return NULL; \
\
size_t real_capacity = PFX##_impl_calculate_size(capacity / load); \
\
if (!alloc) \
@@ -410,21 +436,19 @@ struct cmc_callbacks_hashset
_set_->count = 0; \
_set_->capacity = real_capacity; \
_set_->load = load; \
_set_->cmp = compare; \
_set_->hash = hash; \
\
_set_->it_start = PFX##_impl_it_start; \
_set_->it_end = PFX##_impl_it_end; \
\
_set_->flag = cmc_flags.OK; \
_set_->f_val = f_val; \
_set_->alloc = alloc; \
_set_->callbacks = callbacks; \
_set_->it_start = PFX##_impl_it_start; \
_set_->it_end = PFX##_impl_it_end; \
\
return _set_; \
} \
\
void PFX##_clear(struct SNAME *_set_, void (*deallocator)(V)) \
void PFX##_clear(struct SNAME *_set_) \
{ \
if (deallocator) \
if (_set_->f_val->free) \
{ \
for (size_t i = 0; i < _set_->capacity; i++) \
{ \
@@ -432,7 +456,7 @@ struct cmc_callbacks_hashset
\
if (entry->state == CMC_ES_FILLED) \
{ \
deallocator(entry->value); \
_set_->f_val->free(entry->value); \
} \
} \
} \
@@ -443,9 +467,9 @@ struct cmc_callbacks_hashset
_set_->count = 0; \
} \
\
void PFX##_free(struct SNAME *_set_, void (*deallocator)(V)) \
void PFX##_free(struct SNAME *_set_) \
{ \
if (deallocator) \
if (_set_->f_val->free) \
{ \
for (size_t i = 0; i < _set_->capacity; i++) \
{ \
@@ -453,7 +477,7 @@ struct cmc_callbacks_hashset
\
if (entry->state == CMC_ES_FILLED) \
{ \
deallocator(entry->value); \
_set_->f_val->free(entry->value); \
} \
} \
} \
@@ -480,7 +504,7 @@ struct cmc_callbacks_hashset
return false; \
} \
\
size_t hash = _set_->hash(element); \
size_t hash = _set_->f_val->hash(element); \
size_t original_pos = hash % _set_->capacity; \
size_t pos = original_pos; \
\
@@ -561,7 +585,7 @@ struct cmc_callbacks_hashset
\
if (index == 0) \
*value = result; \
else if (_set_->cmp(result, *value) > 0) \
else if (_set_->f_val->cmp(result, *value) > 0) \
*value = result; \
} \
\
@@ -583,7 +607,7 @@ struct cmc_callbacks_hashset
\
if (index == 0) \
*value = result; \
else if (_set_->cmp(result, *value) < 0) \
else if (_set_->f_val->cmp(result, *value) < 0) \
*value = result; \
} \
\
@@ -641,7 +665,7 @@ struct cmc_callbacks_hashset
return false; \
\
struct SNAME *_new_set_ = \
PFX##_new_custom(capacity, _set_->load, _set_->cmp, _set_->hash, \
PFX##_new_custom(capacity, _set_->load, _set_->f_val, \
_set_->alloc, _set_->callbacks); \
\
if (!_new_set_) \
@@ -659,7 +683,7 @@ struct cmc_callbacks_hashset
\
if (PFX##_count(_set_) != PFX##_count(_new_set_)) \
{ \
PFX##_free(_new_set_, NULL); \
PFX##_free(_new_set_); \
return false; \
} \
\
@@ -671,21 +695,21 @@ struct cmc_callbacks_hashset
_set_->capacity = _new_set_->capacity; \
_new_set_->capacity = tmp_c; \
\
PFX##_free(_new_set_, NULL); \
PFX##_free(_new_set_); \
\
return true; \
} \
\
struct SNAME *PFX##_copy_of(struct SNAME *_set_, V (*copy_func)(V)) \
struct SNAME *PFX##_copy_of(struct SNAME *_set_) \
{ \
struct SNAME *result = \
PFX##_new_custom(_set_->capacity, _set_->load, _set_->cmp, \
_set_->hash, _set_->alloc, _set_->callbacks); \
PFX##_new_custom(_set_->capacity, _set_->load, _set_->f_val, \
_set_->alloc, _set_->callbacks); \
\
if (!result) \
return NULL; \
\
if (copy_func) \
if (_set_->f_val->cpy) \
{ \
for (size_t i = 0; i < _set_->capacity; i++) \
{ \
@@ -702,7 +726,7 @@ struct cmc_callbacks_hashset
target->state = scan->state; \
target->dist = scan->dist; \
\
target->value = copy_func(scan->value); \
target->value = _set_->f_val->cpy(scan->value); \
} \
} \
} \
@@ -745,21 +769,16 @@ struct cmc_callbacks_hashset
int n = \
snprintf(str.s, cmc_string_len, cmc_string_fmt_hashset, #SNAME, \
#V, s_, s_->buffer, s_->capacity, s_->count, s_->load, \
s_->cmp, s_->hash, s_->alloc, s_->callbacks); \
s_->flag, s_->f_val, s_->alloc, s_->callbacks); \
\
if (n < 0 || n == (int)cmc_string_len) \
return (struct cmc_string){ 0 }; \
\
str.s[n] = '\0'; \
\
return str; \
return n >= 0 ? str : (struct cmc_string){ 0 }; \
} \
\
struct SNAME *PFX##_union(struct SNAME *_set1_, struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->cmp, \
_set1_->hash, _set1_->alloc, _set1_->callbacks); \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val, \
_set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -787,8 +806,8 @@ struct cmc_callbacks_hashset
struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->cmp, \
_set1_->hash, _set1_->alloc, _set1_->callbacks); \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val, \
_set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -815,8 +834,8 @@ struct cmc_callbacks_hashset
struct SNAME *PFX##_difference(struct SNAME *_set1_, struct SNAME *_set2_) \
{ \
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->cmp, \
_set1_->hash, _set1_->alloc, _set1_->callbacks); \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val, \
_set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -842,8 +861,8 @@ struct cmc_callbacks_hashset
struct SNAME##_iter iter1, iter2; \
\
struct SNAME *_set_r_ = \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->cmp, \
_set1_->hash, _set1_->alloc, _set1_->callbacks); \
PFX##_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val, \
_set1_->alloc, _set1_->callbacks); \
\
if (!_set_r_) \
return NULL; \
@@ -1195,7 +1214,7 @@ struct cmc_callbacks_hashset
static struct SNAME##_entry *PFX##_impl_get_entry(struct SNAME *_set_, \
V element) \
{ \
size_t hash = _set_->hash(element); \
size_t hash = _set_->f_val->hash(element); \
size_t pos = hash % _set_->capacity; \
\
struct SNAME##_entry *target = &(_set_->buffer[pos]); \
@@ -1203,7 +1222,7 @@ struct cmc_callbacks_hashset
while (target->state == CMC_ES_FILLED || \
target->state == CMC_ES_DELETED) \
{ \
if (_set_->cmp(target->value, element) == 0) \
if (_set_->f_val->cmp(target->value, element) == 0) \
return target; \
\
pos++; \
+2 -1
View File
@@ -42,7 +42,8 @@ CMC_CREATE_UNIT(hashmap_test, true, {
});
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
struct hashmap *map = hm_new(UINT64_MAX, 0.99, hm_ftab_key, hm_ftab_val);
struct hashmap *map =
hm_new(UINT64_MAX, 0.99, hm_ftab_key, hm_ftab_val);
cmc_assert_equals(ptr, NULL, map);
});
+95 -51
View File
@@ -7,32 +7,40 @@
CMC_GENERATE_HASHSET(hs, hashset, size_t)
struct hashset_ftab_val *hs_ftab_val =
&(struct hashset_ftab_val){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
CMC_CREATE_UNIT(hashset_test, true, {
CMC_CREATE_TEST(new, {
struct hashset *set = hs_new(943722, 0.6, cmp, hash);
struct hashset *set = hs_new(943722, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_not_equals(ptr, NULL, set->buffer);
cmc_assert_equals(size_t, 0, hs_count(set));
cmc_assert_greater_equals(size_t, (943722 / 0.6), hs_capacity(set));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(new[capacity = 0], {
struct hashset *set = hs_new(0, 0.6, cmp, hash);
struct hashset *set = hs_new(0, 0.6, hs_ftab_val);
cmc_assert_equals(ptr, NULL, set);
});
CMC_CREATE_TEST(new[capacity = UINT64_MAX], {
struct hashset *set = hs_new(UINT64_MAX, 0.99, cmp, hash);
struct hashset *set = hs_new(UINT64_MAX, 0.99, hs_ftab_val);
cmc_assert_equals(ptr, NULL, set);
});
CMC_CREATE_TEST(clear[count capacity], {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
@@ -41,38 +49,41 @@ CMC_CREATE_UNIT(hashset_test, true, {
cmc_assert_equals(size_t, 50, hs_count(set));
hs_clear(set, NULL);
hs_clear(set);
cmc_assert_equals(size_t, 0, hs_count(set));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(insert, {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert(hs_insert(set, 1));
cmc_assert_equals(size_t, 1, hs_count(set));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(insert[smallest capacity], {
struct hashset *set = hs_new(1, 0.99, cmp, hash);
struct hashset *set = hs_new(1, 0.99, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_equals(size_t, cmc_hashtable_primes[0], hs_capacity(set));
cmc_assert(hs_insert(set, 1));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(insert[element position], {
struct hashset *set = hs_new(1, 0.99, hs_ftab_val);
// Temporary change
// Using the numhash the key is the hash itself
struct hashset *set = hs_new(1, 0.99, cmp, numhash);
hs_ftab_val->hash = numhash;
cmc_assert_not_equals(ptr, NULL, set);
@@ -87,11 +98,16 @@ CMC_CREATE_UNIT(hashset_test, true, {
set->buffer[capacity - 1].value);
cmc_assert_equals(size_t, capacity, set->buffer[0].value);
hs_free(set, NULL);
hs_ftab_val->hash = hash;
hs_free(set);
});
CMC_CREATE_TEST(insert[distance], {
struct hashset *set = hs_new(500, 0.6, cmp, hash0);
struct hashset *set = hs_new(500, 0.6, hs_ftab_val);
// Temporary change
hs_ftab_val->hash = hash0;
cmc_assert_not_equals(ptr, NULL, set);
@@ -103,11 +119,16 @@ CMC_CREATE_UNIT(hashset_test, true, {
for (size_t i = 0; i < 200; i++)
cmc_assert_equals(size_t, i, set->buffer[i].dist);
hs_free(set, NULL);
hs_ftab_val->hash = hash;
hs_free(set);
});
CMC_CREATE_TEST(insert[distance wrap], {
struct hashset *set = hs_new(1, 0.99, cmp, hashcapminus1);
struct hashset *set = hs_new(1, 0.99, hs_ftab_val);
// Temporary change
hs_ftab_val->hash = hashcapminus1;
cmc_assert_not_equals(ptr, NULL, set);
@@ -124,11 +145,34 @@ CMC_CREATE_UNIT(hashset_test, true, {
cmc_assert_equals(size_t, 0, set->buffer[capacity - 1].dist);
cmc_assert_equals(size_t, 1, set->buffer[0].dist);
hs_free(set, NULL);
hs_ftab_val->hash = hash;
hs_free(set);
});
CMC_CREATE_TEST(insert[distances], {
struct hashset *set = hs_new(1, 0.99, hs_ftab_val);
// Temporary change
hs_ftab_val->hash = hashcapminus4;
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_equals(size_t, cmc_hashtable_primes[0], hs_capacity(set));
for (size_t i = 0; i < 6; i++)
cmc_assert(hs_insert(set, i));
for (size_t i = 0; i < 6; i++)
cmc_assert_equals(size_t, i, hs_impl_get_entry(set, i)->dist);
hs_ftab_val->hash = hash;
hs_free(set);
});
CMC_CREATE_TEST(insert[buffer growth and item preservation], {
struct hashset *set = hs_new(1, 0.99, cmp, hash);
struct hashset *set = hs_new(1, 0.99, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
@@ -148,11 +192,11 @@ CMC_CREATE_UNIT(hashset_test, true, {
for (size_t i = 0; i < 100000; i++)
cmc_assert(hs_contains(set, i));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(remove, {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
@@ -162,22 +206,22 @@ CMC_CREATE_UNIT(hashset_test, true, {
for (size_t i = 0; i < 100; i++)
cmc_assert(hs_remove(set, i));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(remove[count = 0], {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
for (size_t i = 100; i < 200; i++)
cmc_assert(!hs_remove(set, i));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(remove[key not found], {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
@@ -187,11 +231,11 @@ CMC_CREATE_UNIT(hashset_test, true, {
for (size_t i = 100; i < 200; i++)
cmc_assert(!hs_remove(set, i));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(max, {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
@@ -203,21 +247,21 @@ CMC_CREATE_UNIT(hashset_test, true, {
cmc_assert_equals(size_t, 100, val);
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(max[count = 0], {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert(!hs_min(set, NULL));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(min, {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
@@ -229,21 +273,21 @@ CMC_CREATE_UNIT(hashset_test, true, {
cmc_assert_equals(size_t, 1, val);
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(min[count = 0], {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert(!hs_min(set, NULL));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(contains, {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
@@ -251,21 +295,21 @@ CMC_CREATE_UNIT(hashset_test, true, {
cmc_assert(hs_contains(set, 987654321));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(contains[count = 0], {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert(!hs_contains(set, 987654321));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(contains[sum], {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
@@ -279,11 +323,11 @@ CMC_CREATE_UNIT(hashset_test, true, {
cmc_assert_equals(size_t, 15050, sum);
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(empty, {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
@@ -293,12 +337,12 @@ CMC_CREATE_UNIT(hashset_test, true, {
cmc_assert(!hs_empty(set));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(full, {
struct hashset *set =
hs_new(cmc_hashtable_primes[0], 0.99999, cmp, hash);
hs_new(cmc_hashtable_primes[0], 0.99999, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
@@ -315,11 +359,11 @@ CMC_CREATE_UNIT(hashset_test, true, {
cmc_assert(!hs_full(set));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(count, {
struct hashset *set = hs_new(100, 0.6, cmp, hash);
struct hashset *set = hs_new(100, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
@@ -329,37 +373,37 @@ CMC_CREATE_UNIT(hashset_test, true, {
cmc_assert_equals(size_t, i, hs_count(set));
}
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(capacity, {
struct hashset *set = hs_new(2500, 0.6, cmp, hash);
struct hashset *set = hs_new(2500, 0.6, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_greater_equals(size_t, (size_t)(2500 / 0.6),
hs_capacity(set));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(capacity[small], {
struct hashset *set = hs_new(1, 0.99, cmp, hash);
struct hashset *set = hs_new(1, 0.99, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_equals(size_t, cmc_hashtable_primes[0], hs_capacity(set));
hs_free(set, NULL);
hs_free(set);
});
CMC_CREATE_TEST(load, {
struct hashset *set = hs_new(1, 0.99, cmp, hash);
struct hashset *set = hs_new(1, 0.99, hs_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
cmc_assert_in_range(double, 0.99 - 0.0001, 0.99 + 0.0001, hs_load(set));
hs_free(set, NULL);
hs_free(set);
});
});
+6 -4
View File
@@ -24,8 +24,10 @@ int main(void)
&(struct bmap_ftab_val){ 0 }, NULL, NULL);
struct deque *d =
d_new_custom(100, &(struct deque_ftab_val){ 0 }, NULL, NULL);
struct hmap *hm = hm_new_custom(100, 0.6, NULL, NULL, NULL, NULL);
struct hset *hs = hs_new_custom(100, 0.6, NULL, NULL, NULL, NULL);
struct hmap *hm = hm_new_custom(100, 0.6, &(struct hmap_ftab_key){ 0 },
&(struct hmap_ftab_val){ 0 }, NULL, NULL);
struct hset *hs =
hs_new_custom(100, 0.6, &(struct hset_ftab_val){ 0 }, NULL, NULL);
struct heap *h = h_new_custom(100, cmc_max_heap, NULL, NULL, NULL);
struct iheap *ih = ih_new_custom(100, NULL, NULL, NULL);
struct linked *ll = ll_new_custom(NULL, NULL);
@@ -56,8 +58,8 @@ int main(void)
bm_free(bm);
d_free(d);
hm_free(hm, NULL);
hs_free(hs, NULL);
hm_free(hm);
hs_free(hs);
h_free(h, NULL);
ih_free(ih, NULL);
ll_free(ll, NULL);