diff --git a/src/ext/intervalheap.h b/src/ext/intervalheap.h index 8b46636..553605e 100644 --- a/src/ext/intervalheap.h +++ b/src/ext/intervalheap.h @@ -21,9 +21,11 @@ #ifndef CMC_INTERVALHEAP_H #define CMC_INTERVALHEAP_H -#include #include +#include +#include #include +#include "../utl/cmc_string.h" #define INTERVALHEAP_GENERATE(PFX, SNAME, FMOD, V) \ INTERVALHEAP_GENERATE_HEADER(PFX, SNAME, FMOD, V) \ @@ -115,6 +117,8 @@ FMOD bool PFX##_full(SNAME *_heap_); \ FMOD size_t PFX##_count(SNAME *_heap_); \ FMOD size_t PFX##_capacity(SNAME *_heap_); \ + /* Collection Utility */ \ + FMOD cmc_string PFX##_to_string(SNAME *_heap_); \ \ /* Iterator Functions */ \ /* Iterator Allocation and Deallocation */ \ @@ -478,8 +482,19 @@ \ FMOD size_t PFX##_capacity(SNAME *_heap_) \ { \ - /* Multiply by 2 since each node can store two elements */ \ - return _heap_->capacity * 2; \ + return _heap_->capacity; \ + } \ + \ + FMOD cmc_string PFX##_to_string(SNAME *_heap_) \ + { \ + cmc_string str; \ + SNAME *h_ = _heap_; \ + const char *name = #SNAME; \ + \ + snprintf(str.s, cmc_string_len, cmc_string_fmt_intervalheap, \ + name, h_, h_->buffer, h_->capacity, h_->size, h_->count, h_->cmp); \ + \ + return str; \ } \ \ FMOD SNAME##_iter *PFX##_iter_new(SNAME *target) \ diff --git a/src/ext/multimap.h b/src/ext/multimap.h index abac290..4d2b30a 100644 --- a/src/ext/multimap.h +++ b/src/ext/multimap.h @@ -43,9 +43,11 @@ #ifndef CMC_MULTIMAP_H #define CMC_MULTIMAP_H -#include #include +#include +#include #include +#include "../utl/cmc_string.h" #ifndef CMC_HASH_TABLE_SETUP #define CMC_HASH_TABLE_SETUP @@ -192,6 +194,8 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531, FMOD bool PFX##_empty(SNAME *_map_); \ FMOD size_t PFX##_count(SNAME *_map_); \ FMOD size_t PFX##_capacity(SNAME *_map_); \ + /* Collection Utility */ \ + FMOD cmc_string PFX##_to_string(SNAME *_map_); \ \ /* Iterator Functions */ \ /* Iterator Allocation and Deallocation */ \ @@ -579,6 +583,18 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531, return _map_->capacity; \ } \ \ + FMOD cmc_string PFX##_to_string(SNAME *_map_) \ + { \ + cmc_string str; \ + SNAME *m_ = _map_; \ + const char *name = #SNAME; \ + \ + snprintf(str.s, cmc_string_len, cmc_string_fmt_hashmap, \ + name, m_, m_->buffer, m_->capacity, m_->count, m_->load, m_->cmp, m_->hash); \ + \ + return str; \ + } \ + \ FMOD SNAME##_iter *PFX##_iter_new(SNAME *target) \ { \ SNAME##_iter *iter = malloc(sizeof(SNAME##_iter)); \ diff --git a/src/utl/cmc_string.h b/src/utl/cmc_string.h index 7169330..ecf726c 100644 --- a/src/utl/cmc_string.h +++ b/src/utl/cmc_string.h @@ -35,6 +35,8 @@ static const char *cmc_string_fmt_stack = "%s at %p { buffer:%p, capacity:%" PRI static const char *cmc_string_fmt_treemap = "%s at %p { root:%p, count:%" PRIuMAX ", cmp:%p }"; static const char *cmc_string_fmt_treeset = "%s at %p { root:%p, count:%" PRIuMAX ", cmp:%p }"; +static const char *cmc_string_fmt_intervalheap = "%s at %p { buffer:%p, capacity:%" PRIuMAX ", size:%" PRIuMAX ", count:%" PRIuMAX ", cmp:%p }"; +static const char *cmc_string_fmt_multimap = "%s at %p { buffer:%p, capacity:%" PRIuMAX ", count:%" PRIuMAX ", load:%lf, cmp:%p, hash:%p }"; static const char *cmc_string_fmt_multiset = "%s at %p { buffer:%p, capacity:%" PRIuMAX ", count:%" PRIuMAX ", cardinality:%" PRIuMAX ", load:%lf, cmp:%p, hash:%p }";; #endif /* CMC_STRING_H */