summaryrefslogtreecommitdiff
path: root/lib/typesafe.c
diff options
context:
space:
mode:
authorStephen Worley <sworley@cumulusnetworks.com>2019-07-23 12:23:25 -0400
committerStephen Worley <sworley@cumulusnetworks.com>2019-07-31 11:35:21 -0400
commitda098d78bb6fbdfb62444f0b0a7aac86875bf3c3 (patch)
tree0d8121f06ed024857287880c5c68957184b1b3a7 /lib/typesafe.c
parent2e6f2d6bc7edb7a75e24d1f8eb15a769d091f64e (diff)
lib: Impelement the `*_del` list API.
The new list api did not implement the `*_del` endpoint as it was described in the docs here: http://docs.frrouting.org/projects/dev-guide/en/latest/lists.html#c.Z_del This patch implements the endpoints to return the object deleted if found, otherwise NULL for all but the atomic lists. The atomic list `*_del` code is marked as TODO and will remain undefined for now. Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
Diffstat (limited to 'lib/typesafe.c')
-rw-r--r--lib/typesafe.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/typesafe.c b/lib/typesafe.c
index f2ca67b7c6..7e5939d5b3 100644
--- a/lib/typesafe.c
+++ b/lib/typesafe.c
@@ -341,13 +341,14 @@ struct sskip_item *typesafe_skiplist_find_lt(struct sskip_head *head,
return best;
}
-void typesafe_skiplist_del(struct sskip_head *head, struct sskip_item *item,
- int (*cmpfn)(const struct sskip_item *a,
- const struct sskip_item *b))
+struct sskip_item *typesafe_skiplist_del(
+ struct sskip_head *head, struct sskip_item *item,
+ int (*cmpfn)(const struct sskip_item *a, const struct sskip_item *b))
{
size_t level = SKIPLIST_MAXDEPTH;
struct sskip_item *prev = &head->hitem, *next;
int cmpval;
+ bool found = false;
while (level) {
next = sl_level_get(prev, level - 1);
@@ -359,6 +360,7 @@ void typesafe_skiplist_del(struct sskip_head *head, struct sskip_item *item,
sl_level_set(prev, level - 1,
sl_level_get(item, level - 1));
level--;
+ found = true;
continue;
}
cmpval = cmpfn(next, item);
@@ -369,6 +371,9 @@ void typesafe_skiplist_del(struct sskip_head *head, struct sskip_item *item,
level--;
}
+ if (!found)
+ return NULL;
+
/* TBD: assert when trying to remove non-existing item? */
head->count--;
@@ -379,6 +384,8 @@ void typesafe_skiplist_del(struct sskip_head *head, struct sskip_item *item,
XFREE(MTYPE_SKIPLIST_OFLOW, oflow);
}
memset(item, 0, sizeof(*item));
+
+ return item;
}
struct sskip_item *typesafe_skiplist_pop(struct sskip_head *head)