• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/libubox/vlist.h

  1 /*
  2  * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
  3  *
  4  * Permission to use, copy, modify, and/or distribute this software for any
  5  * purpose with or without fee is hereby granted, provided that the above
  6  * copyright notice and this permission notice appear in all copies.
  7  *
  8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 15  */
 16 
 17 #ifndef __LIBUBOX_VLIST_H
 18 #define __LIBUBOX_VLIST_H
 19 
 20 #include "avl.h"
 21 
 22 struct vlist_tree;
 23 struct vlist_node;
 24 
 25 typedef void (*vlist_update_cb)(struct vlist_tree *tree,
 26                                 struct vlist_node *node_new,
 27                                 struct vlist_node *node_old);
 28 
 29 struct vlist_tree {
 30         struct avl_tree avl;
 31 
 32         vlist_update_cb update;
 33         bool keep_old;
 34         bool no_delete;
 35 
 36         int version;
 37 };
 38 
 39 struct vlist_node {
 40         struct avl_node avl;
 41         int version;
 42 };
 43 
 44 #define VLIST_TREE_INIT(_name, _comp, _update, _keep_old, _no_delete)   \
 45         {                                                               \
 46                 .avl = AVL_TREE_INIT(_name.avl, _comp, false, NULL),    \
 47                 .update = _update,                                      \
 48                 .version = 1,                                           \
 49                 .keep_old = _keep_old,                                  \
 50                 .no_delete = _no_delete,                                \
 51         }
 52 
 53 #define VLIST_TREE(_name, ...)                                          \
 54         struct vlist_tree _name =                                       \
 55                 VLIST_TREE_INIT(_name, __VA_ARGS__)
 56 
 57 void vlist_init(struct vlist_tree *tree, avl_tree_comp cmp, vlist_update_cb update);
 58 
 59 #define vlist_find(tree, name, element, node_member) \
 60         avl_find_element(&(tree)->avl, name, element, node_member.avl)
 61 
 62 static inline void vlist_update(struct vlist_tree *tree)
 63 {
 64         tree->version++;
 65 }
 66 
 67 void vlist_add(struct vlist_tree *tree, struct vlist_node *node, const void *key);
 68 void vlist_delete(struct vlist_tree *tree, struct vlist_node *node);
 69 void vlist_flush(struct vlist_tree *tree);
 70 void vlist_flush_all(struct vlist_tree *tree);
 71 
 72 #define vlist_for_each_element(tree, element, node_member) \
 73         avl_for_each_element(&(tree)->avl, element, node_member.avl)
 74 
 75 #define vlist_for_each_element_reverse(tree, element, node_member) \
 76         avl_for_each_element_reverse(&(tree)->avl, element, node_member.avl)
 77 
 78 #define vlist_for_first_to_element(tree, last, element, node_member) \
 79         avl_for_element_range(avl_first_element(&(tree)->avl, element, node_member.avl), last, element, node_member.avl)
 80 
 81 #define vlist_for_first_to_element_reverse(tree, last, element, node_member) \
 82         avl_for_element_range_reverse(avl_first_element(&(tree)->avl, element, node_member.avl), last, element, node_member.avl)
 83 
 84 #define vlist_for_element_to_last(tree, first, element, node_member) \
 85         avl_for_element_range(first, avl_last_element(&(tree)->avl, element, node_member.avl), element, node_member.avl)
 86 
 87 #define vlist_for_element_to_last_reverse(tree, first, element, node_member) \
 88         avl_for_element_range_reverse(first, avl_last_element(&(tree)->avl, element, node_member.avl), element, node_member.avl)
 89 
 90 #endif
 91 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt