fx: implement fx_namemap cleanup
This commit is contained in:
@@ -26,7 +26,10 @@ typedef struct fx_namemap_entry {
|
|||||||
const char *e_name;
|
const char *e_name;
|
||||||
} fx_namemap_entry;
|
} fx_namemap_entry;
|
||||||
|
|
||||||
FX_API fx_status fx_namemap_cleanup(fx_namemap *map);
|
typedef void (*fx_namemap_cleanup_callback)(fx_namemap_entry *);
|
||||||
|
|
||||||
|
FX_API fx_status
|
||||||
|
fx_namemap_cleanup(fx_namemap *map, fx_namemap_cleanup_callback callback);
|
||||||
|
|
||||||
FX_API fx_status
|
FX_API fx_status
|
||||||
fx_namemap_put(fx_namemap *map, const char *name, fx_namemap_entry *entry);
|
fx_namemap_put(fx_namemap *map, const char *name, fx_namemap_entry *entry);
|
||||||
|
|||||||
+63
-29
@@ -45,8 +45,50 @@ static struct map_bucket *map_item_convert_to_bucket(
|
|||||||
return bucket;
|
return bucket;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum fx_status fx_namemap_cleanup(struct fx_namemap *map)
|
static void cleanup_bucket(
|
||||||
|
struct map_bucket *bucket,
|
||||||
|
fx_namemap_cleanup_callback callback)
|
||||||
{
|
{
|
||||||
|
fx_queue_entry *cur = fx_queue_pop_front(&bucket->b_items);
|
||||||
|
while (cur) {
|
||||||
|
struct __fx_namemap_entry *entry
|
||||||
|
= fx_unbox(struct __fx_namemap_entry, cur, e_entry);
|
||||||
|
struct fx_namemap_entry *item
|
||||||
|
= (struct fx_namemap_entry *)entry;
|
||||||
|
if (callback) {
|
||||||
|
callback(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
cur = fx_queue_pop_front(&bucket->b_items);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(bucket);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum fx_status fx_namemap_cleanup(
|
||||||
|
struct fx_namemap *map,
|
||||||
|
fx_namemap_cleanup_callback callback)
|
||||||
|
{
|
||||||
|
fx_bst_node *cur_node = fx_bst_first(&map->m_entries);
|
||||||
|
while (cur_node) {
|
||||||
|
struct __fx_namemap_entry *entry
|
||||||
|
= fx_unbox(struct __fx_namemap_entry, cur_node, e_node);
|
||||||
|
fx_bst_delete(&map->m_entries, cur_node);
|
||||||
|
|
||||||
|
if (entry->e_flags == MAP_ENTRY_BUCKET) {
|
||||||
|
struct map_bucket *bucket = (struct map_bucket *)entry;
|
||||||
|
cleanup_bucket(bucket, callback);
|
||||||
|
} else {
|
||||||
|
struct fx_namemap_entry *item
|
||||||
|
= (struct fx_namemap_entry *)entry;
|
||||||
|
if (callback) {
|
||||||
|
callback(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cur_node = fx_bst_first(&map->m_entries);
|
||||||
|
}
|
||||||
|
|
||||||
return FX_SUCCESS;
|
return FX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,10 +179,8 @@ fx_namemap_entry *fx_namemap_get(const fx_namemap *map, const char *name)
|
|||||||
struct fx_namemap_entry *fx_namemap_first(const struct fx_namemap *map)
|
struct fx_namemap_entry *fx_namemap_first(const struct fx_namemap *map)
|
||||||
{
|
{
|
||||||
struct fx_bst_node *first = fx_bst_first(&map->m_entries);
|
struct fx_bst_node *first = fx_bst_first(&map->m_entries);
|
||||||
struct __fx_namemap_entry *entry = fx_unbox(
|
struct __fx_namemap_entry *entry
|
||||||
struct __fx_namemap_entry,
|
= fx_unbox(struct __fx_namemap_entry, first, e_node);
|
||||||
first,
|
|
||||||
e_node);
|
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -158,10 +198,8 @@ struct fx_namemap_entry *fx_namemap_first(const struct fx_namemap *map)
|
|||||||
struct fx_namemap_entry *fx_namemap_last(const struct fx_namemap *map)
|
struct fx_namemap_entry *fx_namemap_last(const struct fx_namemap *map)
|
||||||
{
|
{
|
||||||
struct fx_bst_node *last = fx_bst_last(&map->m_entries);
|
struct fx_bst_node *last = fx_bst_last(&map->m_entries);
|
||||||
struct __fx_namemap_entry *entry = fx_unbox(
|
struct __fx_namemap_entry *entry
|
||||||
struct __fx_namemap_entry,
|
= fx_unbox(struct __fx_namemap_entry, last, e_node);
|
||||||
last,
|
|
||||||
e_node);
|
|
||||||
if (entry->e_flags == MAP_ENTRY_ITEM) {
|
if (entry->e_flags == MAP_ENTRY_ITEM) {
|
||||||
return (struct fx_namemap_entry *)entry;
|
return (struct fx_namemap_entry *)entry;
|
||||||
}
|
}
|
||||||
@@ -179,11 +217,11 @@ struct fx_namemap_entry *fx_namemap_next(
|
|||||||
struct map_bucket *bucket = entry->e_opaque.e_bucket;
|
struct map_bucket *bucket = entry->e_opaque.e_bucket;
|
||||||
struct __fx_namemap_entry *next_entry = NULL;
|
struct __fx_namemap_entry *next_entry = NULL;
|
||||||
if (bucket) {
|
if (bucket) {
|
||||||
struct fx_queue_entry *q_entry = fx_queue_next(
|
struct fx_queue_entry *q_entry
|
||||||
&entry->e_opaque.e_entry);
|
= fx_queue_next(&entry->e_opaque.e_entry);
|
||||||
if (!q_entry) {
|
if (!q_entry) {
|
||||||
struct fx_bst_node *node = fx_bst_next(
|
struct fx_bst_node *node
|
||||||
&bucket->b_entry.e_node);
|
= fx_bst_next(&bucket->b_entry.e_node);
|
||||||
next_entry = fx_unbox(
|
next_entry = fx_unbox(
|
||||||
struct __fx_namemap_entry,
|
struct __fx_namemap_entry,
|
||||||
node,
|
node,
|
||||||
@@ -205,12 +243,10 @@ struct fx_namemap_entry *fx_namemap_next(
|
|||||||
|
|
||||||
if (next_entry->e_flags == MAP_ENTRY_BUCKET) {
|
if (next_entry->e_flags == MAP_ENTRY_BUCKET) {
|
||||||
bucket = (struct map_bucket *)next_entry;
|
bucket = (struct map_bucket *)next_entry;
|
||||||
struct fx_queue_entry *q_entry = fx_queue_first(
|
struct fx_queue_entry *q_entry
|
||||||
&bucket->b_items);
|
= fx_queue_first(&bucket->b_items);
|
||||||
next_entry = fx_unbox(
|
next_entry
|
||||||
struct __fx_namemap_entry,
|
= fx_unbox(struct __fx_namemap_entry, q_entry, e_entry);
|
||||||
q_entry,
|
|
||||||
e_entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (struct fx_namemap_entry *)next_entry;
|
return (struct fx_namemap_entry *)next_entry;
|
||||||
@@ -223,11 +259,11 @@ struct fx_namemap_entry *fx_namemap_prev(
|
|||||||
struct map_bucket *bucket = entry->e_opaque.e_bucket;
|
struct map_bucket *bucket = entry->e_opaque.e_bucket;
|
||||||
struct __fx_namemap_entry *prev_entry = NULL;
|
struct __fx_namemap_entry *prev_entry = NULL;
|
||||||
if (bucket) {
|
if (bucket) {
|
||||||
struct fx_queue_entry *q_entry = fx_queue_prev(
|
struct fx_queue_entry *q_entry
|
||||||
&entry->e_opaque.e_entry);
|
= fx_queue_prev(&entry->e_opaque.e_entry);
|
||||||
if (!q_entry) {
|
if (!q_entry) {
|
||||||
struct fx_bst_node *node = fx_bst_prev(
|
struct fx_bst_node *node
|
||||||
&bucket->b_entry.e_node);
|
= fx_bst_prev(&bucket->b_entry.e_node);
|
||||||
prev_entry = fx_unbox(
|
prev_entry = fx_unbox(
|
||||||
struct __fx_namemap_entry,
|
struct __fx_namemap_entry,
|
||||||
node,
|
node,
|
||||||
@@ -249,12 +285,10 @@ struct fx_namemap_entry *fx_namemap_prev(
|
|||||||
|
|
||||||
if (prev_entry->e_flags == MAP_ENTRY_BUCKET) {
|
if (prev_entry->e_flags == MAP_ENTRY_BUCKET) {
|
||||||
bucket = (struct map_bucket *)prev_entry;
|
bucket = (struct map_bucket *)prev_entry;
|
||||||
struct fx_queue_entry *q_entry = fx_queue_last(
|
struct fx_queue_entry *q_entry
|
||||||
&bucket->b_items);
|
= fx_queue_last(&bucket->b_items);
|
||||||
prev_entry = fx_unbox(
|
prev_entry
|
||||||
struct __fx_namemap_entry,
|
= fx_unbox(struct __fx_namemap_entry, q_entry, e_entry);
|
||||||
q_entry,
|
|
||||||
e_entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (struct fx_namemap_entry *)prev_entry;
|
return (struct fx_namemap_entry *)prev_entry;
|
||||||
|
|||||||
Reference in New Issue
Block a user