summaryrefslogtreecommitdiffstats
path: root/lib/typesafe.c
diff options
context:
space:
mode:
authorStephen Worley <sworley@cumulusnetworks.com>2019-07-23 18:23:25 +0200
committerStephen Worley <sworley@cumulusnetworks.com>2019-07-31 17:35:21 +0200
commitda098d78bb6fbdfb62444f0b0a7aac86875bf3c3 (patch)
tree0d8121f06ed024857287880c5c68957184b1b3a7 /lib/typesafe.c
parentMerge pull request #4756 from vincentbernat/fix/doc-aspath (diff)
downloadfrr-da098d78bb6fbdfb62444f0b0a7aac86875bf3c3.tar.xz
frr-da098d78bb6fbdfb62444f0b0a7aac86875bf3c3.zip
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 f2ca67b7c..7e5939d5b 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)