summaryrefslogtreecommitdiff
path: root/lib/typesafe.c
diff options
context:
space:
mode:
authorMark Stapp <mjs@voltanet.io>2021-10-20 08:13:17 -0400
committerGitHub <noreply@github.com>2021-10-20 08:13:17 -0400
commit52e458d922157f21d97ae2ee40938db560ddba6b (patch)
tree453874e079d2ae1e2d7f7a62a77c4d9a0cc520d8 /lib/typesafe.c
parentbf4af4ffb5e2ffa0b34c5bd67b5b7d4aa912747f (diff)
parent7c1803d0a0aa068a1b2e7256df48b0a36f46f14a (diff)
Merge pull request #9766 from opensourcerouting/typesafe-member-nhrp-zap
lib: add typesafe membership-test functions
Diffstat (limited to 'lib/typesafe.c')
-rw-r--r--lib/typesafe.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/typesafe.c b/lib/typesafe.c
index 76705fad0d..f90b59daf0 100644
--- a/lib/typesafe.c
+++ b/lib/typesafe.c
@@ -29,6 +29,46 @@ DEFINE_MTYPE_STATIC(LIB, TYPEDHASH_BUCKET, "Typed-hash bucket");
DEFINE_MTYPE_STATIC(LIB, SKIPLIST_OFLOW, "Skiplist overflow");
DEFINE_MTYPE_STATIC(LIB, HEAP_ARRAY, "Typed-heap array");
+struct slist_item typesafe_slist_sentinel = { NULL };
+
+bool typesafe_list_member(const struct slist_head *head,
+ const struct slist_item *item)
+{
+ struct slist_item *fromhead = head->first;
+ struct slist_item **fromnext = (struct slist_item **)&item->next;
+
+ while (fromhead != _SLIST_LAST) {
+ if (fromhead == item || fromnext == head->last_next)
+ return true;
+
+ fromhead = fromhead->next;
+ if (!*fromnext || *fromnext == _SLIST_LAST)
+ break;
+ fromnext = &(*fromnext)->next;
+ }
+
+ return false;
+}
+
+bool typesafe_dlist_member(const struct dlist_head *head,
+ const struct dlist_item *item)
+{
+ const struct dlist_item *fromhead = head->hitem.next;
+ const struct dlist_item *fromitem = item->next;
+
+ if (!item->prev || !item->next)
+ return false;
+
+ while (fromhead != &head->hitem && fromitem != item) {
+ if (fromitem == &head->hitem || fromhead == item)
+ return true;
+ fromhead = fromhead->next;
+ fromitem = fromitem->next;
+ }
+
+ return false;
+}
+
#if 0
static void hash_consistency_check(struct thash_head *head)
{