Moving components to ext and updating tests/to_string.c for reference
This commit is contained in:
1 parent
77a7178857
commit
e39d60ade9
6 files changed
+183
-215
No files matched your search
+36
-73
@@ -1,84 +1,47 @@
|
||||
// A visual check for to_string methods
|
||||
|
||||
#include "../src/macro_collections.h"
|
||||
#include "macro_collections.h"
|
||||
|
||||
CMC_COLLECTION_GENERATE(BIDIMAP, bm, bmap, int, int)
|
||||
CMC_COLLECTION_GENERATE(DEQUE, d, deque, /* K */, int)
|
||||
CMC_COLLECTION_GENERATE(HASHMAP, hm, hmap, int, int)
|
||||
CMC_COLLECTION_GENERATE(HASHSET, hs, hset, /* K */, int)
|
||||
CMC_COLLECTION_GENERATE(HEAP, h, heap, /* K */, int)
|
||||
CMC_COLLECTION_GENERATE(INTERVALHEAP, ih, iheap, /* K */, int)
|
||||
CMC_COLLECTION_GENERATE(LINKEDLIST, ll, linked, /* K */, int)
|
||||
CMC_COLLECTION_GENERATE(LIST, l, list, /* K */, int)
|
||||
CMC_COLLECTION_GENERATE(MULTIMAP, mm, mmap, int, int)
|
||||
CMC_COLLECTION_GENERATE(MULTISET, ms, mset, /* K */, int)
|
||||
CMC_COLLECTION_GENERATE(QUEUE, q, queue, /* K */, int)
|
||||
CMC_COLLECTION_GENERATE(SORTEDLIST, sl, slist, /* K */, int)
|
||||
CMC_COLLECTION_GENERATE(STACK, s, stack, /* K */, int)
|
||||
CMC_COLLECTION_GENERATE(TREESET, ts, tset, /* K */, int)
|
||||
CMC_COLLECTION_GENERATE(TREEMAP, tm, tmap, int, int)
|
||||
// clang-format off
|
||||
C_MACRO_COLLECTIONS_ALL(CMC, DEQUE, ( d, deque, , , int))
|
||||
C_MACRO_COLLECTIONS_ALL(CMC, HASHMAP, ( hm, hashmap, , int, int))
|
||||
|
||||
struct
|
||||
{
|
||||
CMC_DEF_FTAB_CMP(int);
|
||||
CMC_DEF_FTAB_CPY(int);
|
||||
CMC_DEF_FTAB_STR(int);
|
||||
CMC_DEF_FTAB_FREE(int);
|
||||
CMC_DEF_FTAB_HASH(int);
|
||||
CMC_DEF_FTAB_PRI(int);
|
||||
} int_ftab = {cmc_i32_cmp, NULL, cmc_i32_str, NULL, cmc_i32_hash, cmc_i32_cmp};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct bmap *bm = bm_new_custom(100, 0.7, &(struct bmap_ftab_key){ 0 },
|
||||
&(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, &(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,
|
||||
&(struct heap_ftab_val){ 0 }, NULL, NULL);
|
||||
struct iheap *ih =
|
||||
ih_new_custom(100, &(struct iheap_ftab_val){ 0 }, NULL, NULL);
|
||||
struct linked *ll =
|
||||
ll_new_custom(&(struct linked_ftab_val){ 0 }, NULL, NULL);
|
||||
struct list *l =
|
||||
l_new_custom(100, &(struct list_ftab_val){ 0 }, NULL, NULL);
|
||||
struct mmap *mm = mm_new_custom(100, 0.8, &(struct mmap_ftab_key){ 0 },
|
||||
&(struct mmap_ftab_val){ 0 }, NULL, NULL);
|
||||
struct mset *ms =
|
||||
ms_new_custom(100, 0.6, &(struct mset_ftab_val){ 0 }, NULL, NULL);
|
||||
struct queue *q =
|
||||
q_new_custom(100, &(struct queue_ftab_val){ 0 }, NULL, NULL);
|
||||
struct slist *sl =
|
||||
sl_new_custom(100, &(struct slist_ftab_val){ 0 }, NULL, NULL);
|
||||
struct stack *s =
|
||||
s_new_custom(100, &(struct stack_ftab_val){ 0 }, NULL, NULL);
|
||||
struct tmap *tm = tm_new_custom(&(struct tmap_ftab_key){ 0 },
|
||||
&(struct tmap_ftab_val){ 0 }, NULL, NULL);
|
||||
struct tset *ts = ts_new_custom(&(struct tset_ftab_val){ 0 }, NULL, NULL);
|
||||
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);
|
||||
|
||||
printf("%s\n", bm_to_string(bm).s);
|
||||
printf("%s\n", d_to_string(d).s);
|
||||
printf("%s\n", hm_to_string(hm).s);
|
||||
printf("%s\n", hs_to_string(hs).s);
|
||||
printf("%s\n", h_to_string(h).s);
|
||||
printf("%s\n", ih_to_string(ih).s);
|
||||
printf("%s\n", ll_to_string(ll).s);
|
||||
printf("%s\n", l_to_string(l).s);
|
||||
printf("%s\n", mm_to_string(mm).s);
|
||||
printf("%s\n", ms_to_string(ms).s);
|
||||
printf("%s\n", q_to_string(q).s);
|
||||
printf("%s\n", sl_to_string(sl).s);
|
||||
printf("%s\n", s_to_string(s).s);
|
||||
printf("%s\n", tm_to_string(tm).s);
|
||||
printf("%s\n", ts_to_string(ts).s);
|
||||
d_to_string(d, stdout);
|
||||
d_print(d, stdout, "\n[ ", ", ", " ]\n");
|
||||
hm_to_string(hm, stdout);
|
||||
hm_print(hm, stdout, "\n[ {", "}, {", "} ]\n", " : ");
|
||||
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
d_push_back(d, i);
|
||||
hm_insert(hm, i, i);
|
||||
}
|
||||
|
||||
fprintf(stdout, "\n");
|
||||
|
||||
d_to_string(d, stdout);
|
||||
d_print(d, stdout, "\n[ ", ", ", " ]\n");
|
||||
hm_to_string(hm, stdout);
|
||||
hm_print(hm, stdout, "\n[ {", "}, {", "} ]\n", " : ");
|
||||
|
||||
bm_free(bm);
|
||||
d_free(d);
|
||||
hm_free(hm);
|
||||
hs_free(hs);
|
||||
h_free(h);
|
||||
ih_free(ih);
|
||||
ll_free(ll);
|
||||
l_free(l);
|
||||
mm_free(mm);
|
||||
ms_free(ms);
|
||||
q_free(q);
|
||||
sl_free(sl);
|
||||
s_free(s);
|
||||
tm_free(tm);
|
||||
ts_free(ts);
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
Reference in new issue
Block a user