Added to_string to intervalheap and multimap
This commit is contained in:
1 parent
7de3ce5c0c
commit
e470021d13
3 files changed
+37
-4
No files matched your search
+18
-3
@@ -21,9 +21,11 @@
|
|||||||
#ifndef CMC_INTERVALHEAP_H
|
#ifndef CMC_INTERVALHEAP_H
|
||||||
#define CMC_INTERVALHEAP_H
|
#define CMC_INTERVALHEAP_H
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "../utl/cmc_string.h"
|
||||||
|
|
||||||
#define INTERVALHEAP_GENERATE(PFX, SNAME, FMOD, V) \
|
#define INTERVALHEAP_GENERATE(PFX, SNAME, FMOD, V) \
|
||||||
INTERVALHEAP_GENERATE_HEADER(PFX, SNAME, FMOD, V) \
|
INTERVALHEAP_GENERATE_HEADER(PFX, SNAME, FMOD, V) \
|
||||||
@@ -115,6 +117,8 @@
|
|||||||
FMOD bool PFX##_full(SNAME *_heap_); \
|
FMOD bool PFX##_full(SNAME *_heap_); \
|
||||||
FMOD size_t PFX##_count(SNAME *_heap_); \
|
FMOD size_t PFX##_count(SNAME *_heap_); \
|
||||||
FMOD size_t PFX##_capacity(SNAME *_heap_); \
|
FMOD size_t PFX##_capacity(SNAME *_heap_); \
|
||||||
|
/* Collection Utility */ \
|
||||||
|
FMOD cmc_string PFX##_to_string(SNAME *_heap_); \
|
||||||
\
|
\
|
||||||
/* Iterator Functions */ \
|
/* Iterator Functions */ \
|
||||||
/* Iterator Allocation and Deallocation */ \
|
/* Iterator Allocation and Deallocation */ \
|
||||||
@@ -478,8 +482,19 @@
|
|||||||
\
|
\
|
||||||
FMOD size_t PFX##_capacity(SNAME *_heap_) \
|
FMOD size_t PFX##_capacity(SNAME *_heap_) \
|
||||||
{ \
|
{ \
|
||||||
/* Multiply by 2 since each node can store two elements */ \
|
return _heap_->capacity; \
|
||||||
return _heap_->capacity * 2; \
|
} \
|
||||||
|
\
|
||||||
|
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) \
|
FMOD SNAME##_iter *PFX##_iter_new(SNAME *target) \
|
||||||
|
|||||||
+17
-1
@@ -43,9 +43,11 @@
|
|||||||
#ifndef CMC_MULTIMAP_H
|
#ifndef CMC_MULTIMAP_H
|
||||||
#define CMC_MULTIMAP_H
|
#define CMC_MULTIMAP_H
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "../utl/cmc_string.h"
|
||||||
|
|
||||||
#ifndef CMC_HASH_TABLE_SETUP
|
#ifndef CMC_HASH_TABLE_SETUP
|
||||||
#define 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 bool PFX##_empty(SNAME *_map_); \
|
||||||
FMOD size_t PFX##_count(SNAME *_map_); \
|
FMOD size_t PFX##_count(SNAME *_map_); \
|
||||||
FMOD size_t PFX##_capacity(SNAME *_map_); \
|
FMOD size_t PFX##_capacity(SNAME *_map_); \
|
||||||
|
/* Collection Utility */ \
|
||||||
|
FMOD cmc_string PFX##_to_string(SNAME *_map_); \
|
||||||
\
|
\
|
||||||
/* Iterator Functions */ \
|
/* Iterator Functions */ \
|
||||||
/* Iterator Allocation and Deallocation */ \
|
/* Iterator Allocation and Deallocation */ \
|
||||||
@@ -579,6 +583,18 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531,
|
|||||||
return _map_->capacity; \
|
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) \
|
FMOD SNAME##_iter *PFX##_iter_new(SNAME *target) \
|
||||||
{ \
|
{ \
|
||||||
SNAME##_iter *iter = malloc(sizeof(SNAME##_iter)); \
|
SNAME##_iter *iter = malloc(sizeof(SNAME##_iter)); \
|
||||||
|
|||||||
@@ -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_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_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 }";;
|
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 */
|
#endif /* CMC_STRING_H */
|
||||||
Reference in new issue
Block a user