Some refactoring and moving more stuff to EXT

This commit is contained in:
Leonardo Vencovsky committed 2020-05-30 00:05:46 -03:00
1 parent 89254ab5db
commit b85f3d1f81
9 files changed
+477 -387

No files matched your search

-24
View File
@@ -553,30 +553,6 @@ _Bool hms_equals(struct hashmultiset *_set1_, struct hashmultiset *_set2_)
}
return 1;
}
struct cmc_string hms_to_string(struct hashmultiset *_set_)
{
struct cmc_string str;
struct hashmultiset *s_ = _set_;
int n = snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_hashmultiset,
"CMC_PARAM_SNAME((hms, hashmultiset, , , size_t))",
"CMC_PARAM_V((hms, hashmultiset, , , size_t))", s_,
s_->buffer, s_->capacity, s_->count, s_->cardinality,
s_->load, s_->flag, s_->f_val, s_->alloc, s_->callbacks);
return n >= 0 ? str : (struct cmc_string){ 0 };
}
_Bool hms_print(struct hashmultiset *_set_, FILE *fptr)
{
for (size_t i = 0; i < _set_->capacity; i++)
{
struct hashmultiset_entry *entry = &(_set_->buffer[i]);
if (entry->state == CMC_ES_FILLED)
{
if (!_set_->f_val->str(fptr, entry->value))
return 0;
}
}
return 1;
}
struct hashmultiset *hms_union(struct hashmultiset *_set1_,
struct hashmultiset *_set2_)
{
+11 -3
View File
@@ -3,9 +3,10 @@
#include "macro_collections.h"
// clang-format off
C_MACRO_COLLECTIONS_ALL(CMC, DEQUE, ( d, deque, , , int))
C_MACRO_COLLECTIONS_ALL(CMC, HASHMAP, ( hm, hashmap, , int, int))
C_MACRO_COLLECTIONS_ALL(CMC, DEQUE, ( d, deque, , , int))
C_MACRO_COLLECTIONS_ALL(CMC, HASHMAP, ( hm, hashmap, , int, int))
C_MACRO_COLLECTIONS_ALL(CMC, HASHMULTIMAP, (hmm, hashmultimap, , int, int))
C_MACRO_COLLECTIONS_ALL(CMC, HASHMULTISET, (hms, hashmultiset, , , int))
struct
{
@@ -22,9 +23,10 @@ int main(void)
struct deque *d = d_new(100, (struct deque_fval *)&int_ftab);
struct hashmap *hm = hm_new(100, 0.6, (struct hashmap_fkey *)&int_ftab,
(struct hashmap_fval *)&int_ftab);
struct hashmultimap *hmm = hmm_new(100, 0.6,
struct hashmultimap *hmm = hmm_new(100, 0.8,
(struct hashmultimap_fkey *)&int_ftab,
(struct hashmultimap_fval *)&int_ftab);
struct hashmultiset *hms = hms_new(100, 0.6, (struct hashmultiset_fval *)&int_ftab);
d_to_string(d, stdout);
d_print(d, stdout, "\n[ ", ", ", " ]\n");
@@ -32,12 +34,15 @@ int main(void)
hm_print(hm, stdout, "\n[ {", "}, {", "} ]\n", " : ");
hmm_to_string(hmm, stdout);
hmm_print(hmm, stdout, "\n[ {", "}, {", "} ]\n", " : ");
hms_to_string(hms, stdout);
hms_print(hms, stdout, "\n[ {", "}, {", "} ]\n", " : ");
for (int i = 0; i < 20; i++)
{
d_push_back(d, i);
hm_insert(hm, i, i);
hmm_insert(hmm, i, i);
hms_insert(hms, i);
}
fprintf(stdout, "\n");
@@ -48,10 +53,13 @@ int main(void)
hm_print(hm, stdout, "\n[ {", "}, {", "} ]\n", " : ");
hmm_to_string(hmm, stdout);
hmm_print(hmm, stdout, "\n[ {", "}, {", "} ]\n", " : ");
hms_to_string(hms, stdout);
hms_print(hms, stdout, "\n[ {", "}, {", "} ]\n", " : ");
d_free(d);
hm_free(hm);
hmm_free(hmm);
hms_free(hms);
}
// clang-format on