Adding functions table to treemap and treeset and some fixes to to_string

This commit is contained in:
Leonardo committed 2020-02-11 15:58:39 -03:00
1 parent 7efc0e26e0
commit 5ed65668e0
7 files changed
+1125 -1012

No files matched your search

+21 -5
View File
@@ -7,17 +7,33 @@
CMC_GENERATE_TREEMAP(tm, treemap, size_t, size_t)
struct treemap_ftab_key *tm_ftab_key =
&(struct treemap_ftab_key){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
struct treemap_ftab_val *tm_ftab_val =
&(struct treemap_ftab_val){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
CMC_CREATE_UNIT(treemap_test, true, {
CMC_CREATE_TEST(new, {
struct treemap *map = tm_new(cmp);
struct treemap *map = tm_new(tm_ftab_key, tm_ftab_val);
cmc_assert_not_equals(ptr, NULL, map);
tm_free(map, NULL);
tm_free(map);
});
CMC_CREATE_TEST(clear[count], {
struct treemap *map = tm_new(cmp);
struct treemap *map = tm_new(tm_ftab_key, tm_ftab_val);
cmc_assert_not_equals(ptr, NULL, map);
@@ -26,11 +42,11 @@ CMC_CREATE_UNIT(treemap_test, true, {
cmc_assert_equals(size_t, 50, tm_count(map));
tm_clear(map, NULL);
tm_clear(map);
cmc_assert_equals(size_t, 0, tm_count(map));
cmc_assert_equals(ptr, NULL, map->root);
tm_free(map, NULL);
tm_free(map);
});
});
+13 -5
View File
@@ -7,17 +7,25 @@
CMC_GENERATE_TREESET(ts, treeset, size_t)
struct treeset_ftab_val *ts_ftab_val =
&(struct treeset_ftab_val){ .cmp = cmp,
.cpy = copy,
.str = str,
.free = custom_free,
.hash = hash,
.pri = pri };
CMC_CREATE_UNIT(treeset_test, true, {
CMC_CREATE_TEST(new, {
struct treeset *set = ts_new(cmp);
struct treeset *set = ts_new(ts_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
ts_free(set, NULL);
ts_free(set);
});
CMC_CREATE_TEST(clear[count], {
struct treeset *set = ts_new(cmp);
struct treeset *set = ts_new(ts_ftab_val);
cmc_assert_not_equals(ptr, NULL, set);
@@ -26,11 +34,11 @@ CMC_CREATE_UNIT(treeset_test, true, {
cmc_assert_equals(size_t, 50, ts_count(set));
ts_clear(set, NULL);
ts_clear(set);
cmc_assert_equals(size_t, 0, ts_count(set));
cmc_assert_equals(ptr, NULL, set->root);
ts_free(set, NULL);
ts_free(set);
});
});
+32 -22
View File
@@ -28,17 +28,27 @@ int main(void)
&(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);
struct list *l = l_new_custom(100, NULL, NULL);
struct mmap *mm = mm_new_custom(100, 0.8, NULL, NULL, NULL, NULL);
struct mset *ms = ms_new_custom(100, 0.6, NULL, NULL, NULL, NULL);
struct queue *q = q_new_custom(100, NULL, NULL);
struct slist *sl = sl_new_custom(100, NULL, NULL, NULL);
struct stack *s = s_new_custom(100, NULL, NULL);
struct tmap *tm = tm_new_custom(NULL, NULL, NULL);
struct tset *ts = ts_new_custom(NULL, 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);
printf("%s\n", bm_to_string(bm).s);
printf("%s\n", d_to_string(d).s);
@@ -60,15 +70,15 @@ int main(void)
d_free(d);
hm_free(hm);
hs_free(hs);
h_free(h, NULL);
ih_free(ih, NULL);
ll_free(ll, NULL);
l_free(l, NULL);
mm_free(mm, NULL);
ms_free(ms, NULL);
q_free(q, NULL);
sl_free(sl, NULL);
s_free(s, NULL);
tm_free(tm, NULL);
ts_free(ts, NULL);
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);
}