Adding more things to EXT and some changes to heap
This commit is contained in:
1 parent
69eed72838
commit
546ac80030
13 files changed
+534
-470
No files matched your search
+2
-23
@@ -74,7 +74,7 @@ struct heap *h_new(size_t capacity, enum cmc_heap_order HO,
|
||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default;
|
||||
if (capacity < 1)
|
||||
return ((void *)0);
|
||||
if (HO != cmc_min_heap && HO != cmc_max_heap)
|
||||
if (HO != CMC_MIN_HEAP && HO != CMC_MAX_HEAP)
|
||||
return ((void *)0);
|
||||
if (!f_val)
|
||||
return ((void *)0);
|
||||
@@ -102,7 +102,7 @@ struct heap *h_new_custom(size_t capacity, enum cmc_heap_order HO,
|
||||
{
|
||||
if (capacity < 1)
|
||||
return ((void *)0);
|
||||
if (HO != cmc_min_heap && HO != cmc_max_heap)
|
||||
if (HO != CMC_MIN_HEAP && HO != CMC_MAX_HEAP)
|
||||
return ((void *)0);
|
||||
if (!f_val)
|
||||
return ((void *)0);
|
||||
@@ -300,27 +300,6 @@ _Bool h_equals(struct heap *_heap1_, struct heap *_heap2_)
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
struct cmc_string h_to_string(struct heap *_heap_)
|
||||
{
|
||||
struct cmc_string str;
|
||||
struct heap *h_ = _heap_;
|
||||
const char *t = h_->HO == 1 ? "MaxHeap" : "MinHeap";
|
||||
int n = snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_heap,
|
||||
"CMC_PARAM_SNAME((h, heap, , , size_t))",
|
||||
"CMC_PARAM_V((h, heap, , , size_t))", h_, h_->buffer,
|
||||
h_->capacity, h_->count, t, h_->flag, h_->f_val, h_->alloc,
|
||||
h_->callbacks);
|
||||
return n >= 0 ? str : (struct cmc_string){ 0 };
|
||||
}
|
||||
_Bool h_print(struct heap *_heap_, FILE *fptr)
|
||||
{
|
||||
for (size_t i = 0; i < _heap_->count; i++)
|
||||
{
|
||||
if (!_heap_->f_val->str(fptr, _heap_->buffer[i]))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
struct heap_iter h_iter_start(struct heap *target)
|
||||
{
|
||||
struct heap_iter iter;
|
||||
|
||||
@@ -231,7 +231,7 @@ CMC_CREATE_UNIT(ForEach, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(CMC<Heap>, {
|
||||
struct heap *h = h_new(10000, cmc_max_heap,
|
||||
struct heap *h = h_new(10000, CMC_MAX_HEAP,
|
||||
&(struct heap_fval){ .cmp = cmc_size_cmp,
|
||||
.cpy = NULL,
|
||||
.str = cmc_size_str,
|
||||
|
||||
+27
-27
@@ -13,7 +13,7 @@ struct heap_fval *h_fval = &(struct heap_fval){ .cmp = cmc_size_cmp,
|
||||
|
||||
CMC_CREATE_UNIT(Heap, true, {
|
||||
CMC_CREATE_TEST(new, {
|
||||
struct heap *h = h_new(1000000, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(1000000, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
cmc_assert_not_equals(ptr, NULL, h->buffer);
|
||||
@@ -24,19 +24,19 @@ CMC_CREATE_UNIT(Heap, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(new[edge_case capacity = 0], {
|
||||
struct heap *h = h_new(0, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(0, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_equals(ptr, NULL, h);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(new[edge_case capacity = UINT64_MAX], {
|
||||
struct heap *h = h_new(UINT64_MAX, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(UINT64_MAX, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_equals(ptr, NULL, h);
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(clear[count capacity], {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -54,7 +54,7 @@ CMC_CREATE_UNIT(Heap, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(buffer_growth[edge_case capacity = 1], {
|
||||
struct heap *h = h_new(1, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(1, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -67,7 +67,7 @@ CMC_CREATE_UNIT(Heap, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(insert, {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -77,7 +77,7 @@ CMC_CREATE_UNIT(Heap, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(insert[item preservation], {
|
||||
struct heap *h = h_new(50, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(50, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -94,7 +94,7 @@ CMC_CREATE_UNIT(Heap, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(remove, {
|
||||
struct heap *h = h_new(50, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(50, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -109,7 +109,7 @@ CMC_CREATE_UNIT(Heap, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(remove[count = 0], {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -119,7 +119,7 @@ CMC_CREATE_UNIT(Heap, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(remove[sorted], {
|
||||
struct heap *h = h_new(100, cmc_min_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MIN_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -141,7 +141,7 @@ CMC_CREATE_UNIT(Heap, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(peek, {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -154,7 +154,7 @@ CMC_CREATE_UNIT(Heap, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(peek[count = 0], {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -164,7 +164,7 @@ CMC_CREATE_UNIT(Heap, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(flags, {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
cmc_assert_equals(int32_t, CMC_FLAG_OK, h_flag(h));
|
||||
@@ -223,7 +223,7 @@ CMC_CREATE_UNIT(Heap, true, {
|
||||
|
||||
CMC_CREATE_TEST(callbacks, {
|
||||
struct heap *h =
|
||||
h_new_custom(100, cmc_max_heap, h_fval, NULL, callbacks);
|
||||
h_new_custom(100, CMC_MAX_HEAP, h_fval, NULL, callbacks);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -293,7 +293,7 @@ CMC_CREATE_UNIT(Heap, true, {
|
||||
|
||||
CMC_CREATE_UNIT(HeapIter, true, {
|
||||
CMC_CREATE_TEST(PFX##_iter_start(), {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -319,7 +319,7 @@ CMC_CREATE_UNIT(HeapIter, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(PFX##_iter_end(), {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -346,7 +346,7 @@ CMC_CREATE_UNIT(HeapIter, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(PFX##_iter_at_start(), {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -368,7 +368,7 @@ CMC_CREATE_UNIT(HeapIter, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(PFX##_iter_at_end(), {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -390,7 +390,7 @@ CMC_CREATE_UNIT(HeapIter, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(PFX##_iter_to_start(), {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -422,7 +422,7 @@ CMC_CREATE_UNIT(HeapIter, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(PFX##_iter_to_end(), {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -450,7 +450,7 @@ CMC_CREATE_UNIT(HeapIter, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(PFX##_iter_next(), {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -488,7 +488,7 @@ CMC_CREATE_UNIT(HeapIter, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(PFX##_iter_prev(), {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -526,7 +526,7 @@ CMC_CREATE_UNIT(HeapIter, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(PFX##_iter_advance(), {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -577,7 +577,7 @@ CMC_CREATE_UNIT(HeapIter, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(PFX##_iter_rewind(), {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -628,7 +628,7 @@ CMC_CREATE_UNIT(HeapIter, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(PFX##_iter_go_to(), {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -669,7 +669,7 @@ CMC_CREATE_UNIT(HeapIter, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(PFX##_iter_value(), {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
@@ -689,7 +689,7 @@ CMC_CREATE_UNIT(HeapIter, true, {
|
||||
});
|
||||
|
||||
CMC_CREATE_TEST(PFX##_iter_index(), {
|
||||
struct heap *h = h_new(100, cmc_max_heap, h_fval);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval);
|
||||
|
||||
cmc_assert_not_equals(ptr, NULL, h);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ 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))
|
||||
C_MACRO_COLLECTIONS_ALL(CMC, HASHSET, ( hs, hashset, , , int))
|
||||
C_MACRO_COLLECTIONS_ALL(CMC, HEAP, ( h, heap, , , int))
|
||||
|
||||
struct
|
||||
{
|
||||
@@ -31,6 +32,7 @@ int main(void)
|
||||
(struct hashmultiset_fval *)&int_ftab);
|
||||
struct hashset *hs = hs_new(100, 0.6,
|
||||
(struct hashset_fval *)&int_ftab);
|
||||
struct heap *h = h_new(100, CMC_MAX_HEAP, (struct heap_fval *)&int_ftab);
|
||||
|
||||
d_to_string(d, stdout);
|
||||
d_print(d, stdout, "\n[ ", ", ", " ]\n");
|
||||
@@ -42,6 +44,8 @@ int main(void)
|
||||
hms_print(hms, stdout, "\n[ {", "}, {", "} ]\n", " : ");
|
||||
hs_to_string(hs, stdout);
|
||||
hs_print(hs, stdout, "\n[ ", ", ", " ]\n");
|
||||
h_to_string(h, stdout);
|
||||
h_print(h, stdout, "\n[ ", ", ", " ]\n");
|
||||
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
@@ -50,6 +54,7 @@ int main(void)
|
||||
hmm_insert(hmm, i, i);
|
||||
hms_insert(hms, i);
|
||||
hs_insert(hs, i);
|
||||
h_insert(h, i);
|
||||
}
|
||||
|
||||
fprintf(stdout, "\n");
|
||||
@@ -64,6 +69,8 @@ int main(void)
|
||||
hms_print(hms, stdout, "\n[ {", "}, {", "} ]\n", " : ");
|
||||
hs_to_string(hs, stdout);
|
||||
hs_print(hs, stdout, "\n[ ", ", ", " ]\n");
|
||||
h_to_string(h, stdout);
|
||||
h_print(h, stdout, "\n[ ", ", ", " ]\n");
|
||||
|
||||
d_free(d);
|
||||
hm_free(hm);
|
||||
|
||||
Reference in new issue
Block a user