Started migrating things to EXT

This commit is contained in:
Leonardo Vencovsky committed 2020-05-29 20:19:47 -03:00
1 parent e39d60ade9
commit 89254ab5db
11 files changed
+1131 -1071

No files matched your search

-21
View File
@@ -361,27 +361,6 @@ _Bool d_equals(struct deque *_deque1_, struct deque *_deque2_)
}
return 1;
}
struct cmc_string d_to_string(struct deque *_deque_)
{
struct cmc_string str;
struct deque *d_ = _deque_;
int n = snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_deque,
"CMC_PARAM_SNAME((d, deque, , , size_t))",
"CMC_PARAM_V((d, deque, , , size_t))", d_, d_->buffer,
d_->capacity, d_->count, d_->front, d_->back, d_->flag,
d_->f_val, d_->alloc, d_->callbacks);
return n >= 0 ? str : (struct cmc_string){ 0 };
}
_Bool d_print(struct deque *_deque_, FILE *fptr)
{
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++)
{
if (!_deque_->f_val->str(fptr, _deque_->buffer[i]))
return 0;
i = (i + 1) % _deque_->capacity;
}
return 1;
}
struct deque_iter d_iter_start(struct deque *target)
{
struct deque_iter iter;
-26
View File
@@ -552,32 +552,6 @@ _Bool hm_equals(struct hashmap *_map1_, struct hashmap *_map2_)
}
return 1;
}
struct cmc_string hm_to_string(struct hashmap *_map_)
{
struct cmc_string str;
struct hashmap *m_ = _map_;
int n = snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_hashmap,
"CMC_PARAM_SNAME((hm, hashmap, , size_t, size_t))",
"CMC_PARAM_K((hm, hashmap, , size_t, size_t))",
"CMC_PARAM_V((hm, hashmap, , size_t, size_t))", m_,
m_->buffer, m_->capacity, m_->count, m_->load, m_->flag,
m_->f_key, m_->f_val, m_->alloc, m_->callbacks);
return n >= 0 ? str : (struct cmc_string){ 0 };
}
_Bool hm_print(struct hashmap *_map_, FILE *fptr)
{
for (size_t i = 0; i < _map_->capacity; i++)
{
struct hashmap_entry *entry = &(_map_->buffer[i]);
if (entry->state == CMC_ES_FILLED)
{
if (!_map_->f_key->str(fptr, entry->key) ||
!_map_->f_val->str(fptr, entry->value))
return 0;
}
}
return 1;
}
struct hashmap_iter hm_iter_start(struct hashmap *target)
{
struct hashmap_iter iter;
-27
View File
@@ -720,33 +720,6 @@ _Bool hmm_equals(struct hashmultimap *_map1_, struct hashmultimap *_map2_)
}
return 1;
}
struct cmc_string hmm_to_string(struct hashmultimap *_map_)
{
struct cmc_string str;
struct hashmultimap *m_ = _map_;
int n = snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_hashmultimap,
"CMC_PARAM_SNAME((hmm, hashmultimap, , size_t, size_t))",
"CMC_PARAM_K((hmm, hashmultimap, , size_t, size_t))",
"CMC_PARAM_V((hmm, hashmultimap, , size_t, size_t))", m_,
m_->buffer, m_->capacity, m_->count, m_->load, m_->flag,
m_->f_key, m_->f_val, m_->alloc, m_->callbacks);
return n >= 0 ? str : (struct cmc_string){ 0 };
}
_Bool hmm_print(struct hashmultimap *_map_, FILE *fptr)
{
for (size_t i = 0; i < _map_->capacity; i++)
{
struct hashmultimap_entry *scan = _map_->buffer[i][0];
while (scan != ((void *)0))
{
if (!_map_->f_key->str(fptr, scan->key) ||
!_map_->f_val->str(fptr, scan->value))
return 0;
scan = scan->next;
}
}
return 1;
}
struct hashmultimap_iter hmm_iter_start(struct hashmultimap *target)
{
struct hashmultimap_iter iter;
+9
View File
@@ -2,6 +2,15 @@
#ifndef CMC_UNIT_TEST_UTL__
#define CMC_UNIT_TEST_UTL__
/**
* TEMPORARY
*/
struct cmc_string
{
char s[400];
};
static const size_t cmc_string_len = 400;
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
+12 -2
View File
@@ -3,8 +3,9 @@
#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))
struct
{
@@ -21,16 +22,22 @@ 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_fkey *)&int_ftab,
(struct hashmultimap_fval *)&int_ftab);
d_to_string(d, stdout);
d_print(d, stdout, "\n[ ", ", ", " ]\n");
hm_to_string(hm, stdout);
hm_print(hm, stdout, "\n[ {", "}, {", "} ]\n", " : ");
hmm_to_string(hmm, stdout);
hmm_print(hmm, 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);
}
fprintf(stdout, "\n");
@@ -39,9 +46,12 @@ int main(void)
d_print(d, stdout, "\n[ ", ", ", " ]\n");
hm_to_string(hm, stdout);
hm_print(hm, stdout, "\n[ {", "}, {", "} ]\n", " : ");
hmm_to_string(hmm, stdout);
hmm_print(hmm, stdout, "\n[ {", "}, {", "} ]\n", " : ");
d_free(d);
hm_free(hm);
hmm_free(hmm);
}
// clang-format on