Fixing things everywhere
Adding necessary if checks for list and linkedlist Fixing hashset new required size Unified max() and min() functions for treemap. Now you get both key and value.
This commit is contained in:
1 parent
f4440d6833
commit
36d75d561e
5 files changed
+50
-66
No files matched your search
+1
-1
@@ -364,7 +364,7 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 193, 389, 769, 1543, 3079,
|
||||
const size_t count = sizeof(cmc_hashtable_primes) / sizeof(cmc_hashtable_primes[0]); \
|
||||
\
|
||||
if (cmc_hashtable_primes[count - 1] < required) \
|
||||
return required * 2; \
|
||||
return required; \
|
||||
\
|
||||
size_t i = 0; \
|
||||
while (cmc_hashtable_primes[i] < required) \
|
||||
|
||||
+4
-1
@@ -47,10 +47,10 @@
|
||||
\
|
||||
struct SNAME##_node_s \
|
||||
{ \
|
||||
V data; \
|
||||
struct SNAME##_s *owner; \
|
||||
struct SNAME##_node_s *next; \
|
||||
struct SNAME##_node_s *prev; \
|
||||
V data; \
|
||||
}; \
|
||||
\
|
||||
struct SNAME##_iter_s \
|
||||
@@ -234,6 +234,9 @@
|
||||
if (PFX##_empty(_list_)) \
|
||||
return false; \
|
||||
\
|
||||
if (index >= _list_->count) \
|
||||
return false; \
|
||||
\
|
||||
if (index == 0) \
|
||||
{ \
|
||||
return PFX##_pop_front(_list_); \
|
||||
|
||||
@@ -216,6 +216,9 @@
|
||||
if (PFX##_empty(_list_)) \
|
||||
return false; \
|
||||
\
|
||||
if (index >= _list_->count) \
|
||||
return false; \
|
||||
\
|
||||
if (index == 0) \
|
||||
{ \
|
||||
return PFX##_pop_front(_list_); \
|
||||
|
||||
+40
-62
@@ -47,12 +47,12 @@
|
||||
\
|
||||
struct SNAME##_node_s \
|
||||
{ \
|
||||
K key; \
|
||||
V value; \
|
||||
unsigned char height; \
|
||||
struct SNAME##_node_s *right; \
|
||||
struct SNAME##_node_s *left; \
|
||||
struct SNAME##_node_s *parent; \
|
||||
unsigned char height; \
|
||||
K key; \
|
||||
V value; \
|
||||
}; \
|
||||
\
|
||||
struct SNAME##_iter_s \
|
||||
@@ -67,34 +67,32 @@
|
||||
}; \
|
||||
\
|
||||
/* HEADER ********************************************************************/
|
||||
#define TREEMAP_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
typedef struct SNAME##_s SNAME; \
|
||||
typedef struct SNAME##_node_s SNAME##_node; \
|
||||
typedef struct SNAME##_iter_s SNAME##_iter; \
|
||||
\
|
||||
FMOD SNAME *PFX##_new(int (*compare)(K, K)); \
|
||||
FMOD void PFX##_free(SNAME *_map_); \
|
||||
FMOD bool PFX##_insert(SNAME *_map_, K key, V value); \
|
||||
FMOD bool PFX##_remove(SNAME *_map_, K key, V *value); \
|
||||
FMOD bool PFX##_insert_if(SNAME *_map_, K key, V value, bool condition); \
|
||||
FMOD bool PFX##_remove_if(SNAME *_map_, K key, V *value, bool condition); \
|
||||
FMOD K PFX##_max_key(SNAME *_map_); \
|
||||
FMOD V PFX##_max_val(SNAME *_map_); \
|
||||
FMOD K PFX##_min_key(SNAME *_map_); \
|
||||
FMOD V PFX##_min_val(SNAME *_map_); \
|
||||
FMOD V PFX##_get(SNAME *_map_, K key); \
|
||||
FMOD bool PFX##_empty(SNAME *_map_); \
|
||||
FMOD size_t PFX##_count(SNAME *_map_); \
|
||||
\
|
||||
FMOD void PFX##_iter_new(SNAME##_iter *iter, SNAME *target); \
|
||||
FMOD bool PFX##_iter_start(SNAME##_iter *iter); \
|
||||
FMOD bool PFX##_iter_end(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_tostart(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_toend(SNAME##_iter *iter); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, K *key, V *result, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, K *key, V *result, size_t *index); \
|
||||
\
|
||||
#define TREEMAP_GENERATE_HEADER(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
typedef struct SNAME##_s SNAME; \
|
||||
typedef struct SNAME##_node_s SNAME##_node; \
|
||||
typedef struct SNAME##_iter_s SNAME##_iter; \
|
||||
\
|
||||
FMOD SNAME *PFX##_new(int (*compare)(K, K)); \
|
||||
FMOD void PFX##_free(SNAME *_map_); \
|
||||
FMOD bool PFX##_insert(SNAME *_map_, K key, V value); \
|
||||
FMOD bool PFX##_remove(SNAME *_map_, K key, V *value); \
|
||||
FMOD bool PFX##_insert_if(SNAME *_map_, K key, V value, bool condition); \
|
||||
FMOD bool PFX##_remove_if(SNAME *_map_, K key, V *value, bool condition); \
|
||||
FMOD bool PFX##_max(SNAME *_map_, K *key, V *value); \
|
||||
FMOD bool PFX##_min(SNAME *_map_, K *key, V *value); \
|
||||
FMOD V PFX##_get(SNAME *_map_, K key); \
|
||||
FMOD bool PFX##_empty(SNAME *_map_); \
|
||||
FMOD size_t PFX##_count(SNAME *_map_); \
|
||||
\
|
||||
FMOD void PFX##_iter_new(SNAME##_iter *iter, SNAME *target); \
|
||||
FMOD bool PFX##_iter_start(SNAME##_iter *iter); \
|
||||
FMOD bool PFX##_iter_end(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_tostart(SNAME##_iter *iter); \
|
||||
FMOD void PFX##_iter_toend(SNAME##_iter *iter); \
|
||||
FMOD bool PFX##_iter_next(SNAME##_iter *iter, K *key, V *value, size_t *index); \
|
||||
FMOD bool PFX##_iter_prev(SNAME##_iter *iter, K *key, V *value, size_t *index); \
|
||||
\
|
||||
/* SOURCE ********************************************************************/
|
||||
#define TREEMAP_GENERATE_SOURCE(PFX, SNAME, FMOD, K, V) \
|
||||
\
|
||||
@@ -368,56 +366,36 @@
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
FMOD K PFX##_max_key(SNAME *_map_) \
|
||||
FMOD bool PFX##_max(SNAME *_map_, K *key, V *value) \
|
||||
{ \
|
||||
if (PFX##_empty(_map_)) \
|
||||
return 0; \
|
||||
return false; \
|
||||
\
|
||||
SNAME##_node *scan = _map_->root; \
|
||||
\
|
||||
while (scan->right != NULL) \
|
||||
scan = scan->right; \
|
||||
\
|
||||
return scan->key; \
|
||||
*key = scan->key; \
|
||||
*value = scan->value; \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD V PFX##_max_val(SNAME *_map_) \
|
||||
FMOD bool PFX##_min(SNAME *_map_, K *key, V *value) \
|
||||
{ \
|
||||
if (PFX##_empty(_map_)) \
|
||||
return 0; \
|
||||
\
|
||||
SNAME##_node *scan = _map_->root; \
|
||||
\
|
||||
while (scan->right != NULL) \
|
||||
scan = scan->right; \
|
||||
\
|
||||
return scan->value; \
|
||||
} \
|
||||
\
|
||||
FMOD K PFX##_min_key(SNAME *_map_) \
|
||||
{ \
|
||||
if (PFX##_empty(_map_)) \
|
||||
return 0; \
|
||||
return false; \
|
||||
\
|
||||
SNAME##_node *scan = _map_->root; \
|
||||
\
|
||||
while (scan->left != NULL) \
|
||||
scan = scan->left; \
|
||||
\
|
||||
return scan->key; \
|
||||
} \
|
||||
*key = scan->key; \
|
||||
*value = scan->value; \
|
||||
\
|
||||
FMOD V PFX##_min_val(SNAME *_map_) \
|
||||
{ \
|
||||
if (PFX##_empty(_map_)) \
|
||||
return 0; \
|
||||
\
|
||||
SNAME##_node *scan = _map_->root; \
|
||||
\
|
||||
while (scan->left != NULL) \
|
||||
scan = scan->left; \
|
||||
\
|
||||
return scan->value; \
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
FMOD V PFX##_get(SNAME *_map_, K key) \
|
||||
|
||||
+2
-2
@@ -47,11 +47,11 @@
|
||||
\
|
||||
struct SNAME##_node_s \
|
||||
{ \
|
||||
V key; \
|
||||
unsigned char height; \
|
||||
struct SNAME##_node_s *right; \
|
||||
struct SNAME##_node_s *left; \
|
||||
struct SNAME##_node_s *parent; \
|
||||
unsigned char height; \
|
||||
V key; \
|
||||
}; \
|
||||
\
|
||||
struct SNAME##_iter_s \
|
||||
|
||||
Reference in new issue
Block a user