]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/typerb.h
Merge pull request #13659 from donaldsharp/increase_mgmt_time
[mirror_frr.git] / lib / typerb.h
index 75a1de77b32f2956f74f6168c44ef55335409852..b020a665f6240024c02b2d7a02cfef4294264d20 100644 (file)
@@ -1,20 +1,9 @@
+// SPDX-License-Identifier: ISC
 /*
  * The following Red-Black tree implementation is based off code with
  * original copyright:
  *
  * Copyright (c) 2016 David Gwynne <dlg@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
 #ifndef _FRR_TYPERB_H
@@ -62,6 +51,8 @@ const struct typed_rb_entry *typed_rb_find_lt(const struct typed_rb_root *rbt,
                        const struct typed_rb_entry *a,
                        const struct typed_rb_entry *b));
 struct typed_rb_entry *typed_rb_min(const struct typed_rb_root *rbt);
+struct typed_rb_entry *typed_rb_max(const struct typed_rb_root *rbt);
+struct typed_rb_entry *typed_rb_prev(const struct typed_rb_entry *rbe);
 struct typed_rb_entry *typed_rb_next(const struct typed_rb_entry *rbe);
 bool typed_rb_member(const struct typed_rb_root *rbt,
                     const struct typed_rb_entry *rbe);
@@ -135,12 +126,32 @@ macro_pure const type *prefix ## _const_next(const struct prefix##_head *h,    \
        return container_of_null(re, type, field.re);                          \
 }                                                                              \
 TYPESAFE_FIRST_NEXT(prefix, type)                                              \
+macro_pure const type *prefix ## _const_last(const struct prefix##_head *h)    \
+{                                                                              \
+       const struct typed_rb_entry *re;                                       \
+       re = typed_rb_max(&h->rr);                                             \
+       return container_of_null(re, type, field.re);                          \
+}                                                                              \
+macro_pure const type *prefix ## _const_prev(const struct prefix##_head *h,    \
+                                            const type *item)                 \
+{                                                                              \
+       const struct typed_rb_entry *re;                                       \
+       re = typed_rb_prev(&item->field.re);                                   \
+       return container_of_null(re, type, field.re);                          \
+}                                                                              \
+TYPESAFE_LAST_PREV(prefix, type)                                               \
 macro_pure type *prefix ## _next_safe(struct prefix##_head *h, type *item)     \
 {                                                                              \
        struct typed_rb_entry *re;                                             \
        re = item ? typed_rb_next(&item->field.re) : NULL;                     \
        return container_of_null(re, type, field.re);                          \
 }                                                                              \
+macro_pure type *prefix ## _prev_safe(struct prefix##_head *h, type *item)     \
+{                                                                              \
+       struct typed_rb_entry *re;                                             \
+       re = item ? typed_rb_prev(&item->field.re) : NULL;                     \
+       return container_of_null(re, type, field.re);                          \
+}                                                                              \
 macro_pure size_t prefix ## _count(const struct prefix##_head *h)              \
 {                                                                              \
        return h->rr.count;                                                    \