Added callbacks to treemap and treeset
This commit is contained in:
1 parent
ee1174d1b5
commit
4c16cae56d
4 files changed
+191
-8
No files matched your search
+34
-5
@@ -375,6 +375,7 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
\
|
||||
_map_->alloc->free(_map_); \
|
||||
} \
|
||||
\
|
||||
void PFX##_customize(struct SNAME *_map_, struct cmc_alloc_node *alloc, \
|
||||
struct cmc_callbacks *callbacks) \
|
||||
{ \
|
||||
@@ -452,6 +453,9 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
_map_->count++; \
|
||||
_map_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_map_->callbacks && _map_->callbacks->create) \
|
||||
_map_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -472,6 +476,9 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
\
|
||||
_map_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_map_->callbacks && _map_->callbacks->update) \
|
||||
_map_->callbacks->update(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -602,11 +609,14 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
if (unbalanced != NULL) \
|
||||
PFX##_impl_rebalance(_map_, unbalanced); \
|
||||
\
|
||||
if (_map_->count == 0) \
|
||||
_map_->root = NULL; \
|
||||
\
|
||||
_map_->count--; \
|
||||
_map_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_map_->count == 0) \
|
||||
_map_->root = NULL; \
|
||||
if (_map_->callbacks && _map_->callbacks->delete) \
|
||||
_map_->callbacks->delete (); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
@@ -631,6 +641,9 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
\
|
||||
_map_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_map_->callbacks && _map_->callbacks->read) \
|
||||
_map_->callbacks->read(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -654,6 +667,9 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
\
|
||||
_map_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_map_->callbacks && _map_->callbacks->read) \
|
||||
_map_->callbacks->read(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -675,6 +691,9 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
\
|
||||
_map_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_map_->callbacks && _map_->callbacks->read) \
|
||||
_map_->callbacks->read(); \
|
||||
\
|
||||
return node->value; \
|
||||
} \
|
||||
\
|
||||
@@ -696,12 +715,20 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
\
|
||||
_map_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_map_->callbacks && _map_->callbacks->read) \
|
||||
_map_->callbacks->read(); \
|
||||
\
|
||||
return &(node->value); \
|
||||
} \
|
||||
\
|
||||
bool PFX##_contains(struct SNAME *_map_, K key) \
|
||||
{ \
|
||||
return PFX##_impl_get_node(_map_, key) != NULL; \
|
||||
bool result = PFX##_impl_get_node(_map_, key) != NULL; \
|
||||
\
|
||||
if (_map_->callbacks && _map_->callbacks->read) \
|
||||
_map_->callbacks->read(); \
|
||||
\
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_empty(struct SNAME *_map_) \
|
||||
@@ -721,8 +748,9 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
\
|
||||
struct SNAME *PFX##_copy_of(struct SNAME *_map_) \
|
||||
{ \
|
||||
struct SNAME *result = PFX##_new_custom( \
|
||||
_map_->f_key, _map_->f_val, _map_->alloc, _map_->callbacks); \
|
||||
/* Callback will be added later */ \
|
||||
struct SNAME *result = \
|
||||
PFX##_new_custom(_map_->f_key, _map_->f_val, _map_->alloc, NULL); \
|
||||
\
|
||||
if (!result) \
|
||||
{ \
|
||||
@@ -749,6 +777,7 @@ static const char *cmc_string_fmt_treemap = "struct %s<%s, %s> "
|
||||
PFX##_insert(result, key, value); \
|
||||
} \
|
||||
\
|
||||
result->callbacks = _map_->callbacks; \
|
||||
_map_->flag = cmc_flags.OK; \
|
||||
\
|
||||
return result; \
|
||||
|
||||
+20
-3
@@ -435,6 +435,9 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
|
||||
_set_->count++; \
|
||||
_set_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_set_->callbacks && _set_->callbacks->create) \
|
||||
_set_->callbacks->create(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -560,11 +563,14 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
|
||||
if (unbalanced != NULL) \
|
||||
PFX##_impl_rebalance(_set_, unbalanced); \
|
||||
\
|
||||
if (_set_->count == 0) \
|
||||
_set_->root = NULL; \
|
||||
\
|
||||
_set_->count--; \
|
||||
_set_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_set_->count == 0) \
|
||||
_set_->root = NULL; \
|
||||
if (_set_->callbacks && _set_->callbacks->delete) \
|
||||
_set_->callbacks->delete (); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
@@ -587,6 +593,9 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
|
||||
\
|
||||
_set_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_set_->callbacks && _set_->callbacks->read) \
|
||||
_set_->callbacks->read(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
@@ -608,12 +617,20 @@ static const char *cmc_string_fmt_treeset = "struct %s<%s> "
|
||||
\
|
||||
_set_->flag = cmc_flags.OK; \
|
||||
\
|
||||
if (_set_->callbacks && _set_->callbacks->read) \
|
||||
_set_->callbacks->read(); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_contains(struct SNAME *_set_, V element) \
|
||||
{ \
|
||||
return PFX##_impl_get_node(_set_, element) != NULL; \
|
||||
bool result = PFX##_impl_get_node(_set_, element) != NULL; \
|
||||
\
|
||||
if (_set_->callbacks && _set_->callbacks->read) \
|
||||
_set_->callbacks->read(); \
|
||||
\
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_empty(struct SNAME *_set_) \
|
||||
|
||||
Reference in new issue
Block a user