libubox
C utility functions for OpenWrt.
vlist.c File Reference
#include "vlist.h"

Go to the source code of this file.

Functions

void vlist_init (struct vlist_tree *tree, avl_tree_comp cmp, vlist_update_cb update)
 
void vlist_delete (struct vlist_tree *tree, struct vlist_node *node)
 
void vlist_add (struct vlist_tree *tree, struct vlist_node *node, const void *key)
 
void vlist_flush (struct vlist_tree *tree)
 
void vlist_flush_all (struct vlist_tree *tree)
 

Function Documentation

◆ vlist_add()

void vlist_add ( struct vlist_tree tree,
struct vlist_node node,
const void *  key 
)

Definition at line 36 of file vlist.c.

37 {
38  struct vlist_node *old_node = NULL;
39  struct avl_node *anode;
40 
41  node->avl.key = key;
42  node->version = tree->version;
43 
44  anode = avl_find(&tree->avl, key);
45  if (anode) {
46  old_node = container_of(anode, struct vlist_node, avl);
47  if (tree->keep_old || tree->no_delete) {
48  old_node->version = tree->version;
49  goto update_only;
50  }
51 
52  avl_delete(&tree->avl, anode);
53  }
54 
55  avl_insert(&tree->avl, &node->avl);
56 
57 update_only:
58  tree->update(tree, node, old_node);
59 }
struct avl_node * avl_find(const struct avl_tree *tree, const void *key)
Definition: avl.c:115
int avl_insert(struct avl_tree *tree, struct avl_node *new)
Definition: avl.c:220
void avl_delete(struct avl_tree *tree, struct avl_node *node)
Definition: avl.c:307
#define container_of(ptr, type, member)
Definition: list.h:38
Definition: avl.h:56
const void * key
Definition: avl.h:84
Definition: test-avl.c:13
struct avl_node avl
Definition: test-avl.c:14
int version
Definition: vlist.h:41
vlist_update_cb update
Definition: vlist.h:32
int version
Definition: vlist.h:36
bool keep_old
Definition: vlist.h:33
struct avl_tree avl
Definition: vlist.h:30
bool no_delete
Definition: vlist.h:34
Here is the call graph for this function:

◆ vlist_delete()

void vlist_delete ( struct vlist_tree tree,
struct vlist_node node 
)

Definition at line 28 of file vlist.c.

29 {
30  if (!tree->no_delete)
31  avl_delete(&tree->avl, &node->avl);
32  tree->update(tree, NULL, node);
33 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vlist_flush()

void vlist_flush ( struct vlist_tree tree)

Definition at line 62 of file vlist.c.

63 {
64  struct vlist_node *node, *tmp;
65 
66  avl_for_each_element_safe(&tree->avl, node, avl, tmp) {
67  if ((node->version == tree->version || node->version == -1) &&
68  tree->version != -1)
69  continue;
70 
71  vlist_delete(tree, node);
72  }
73 }
#define avl_for_each_element_safe(tree, element, node_member, ptr)
Definition: avl.h:503
struct avl_node avl
Definition: vlist.h:40
void vlist_delete(struct vlist_tree *tree, struct vlist_node *node)
Definition: vlist.c:28
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vlist_flush_all()

void vlist_flush_all ( struct vlist_tree tree)

Definition at line 76 of file vlist.c.

77 {
78  tree->version = -1;
79  vlist_flush(tree);
80 }
void vlist_flush(struct vlist_tree *tree)
Definition: vlist.c:62
Here is the call graph for this function:

◆ vlist_init()

void vlist_init ( struct vlist_tree tree,
avl_tree_comp  cmp,
vlist_update_cb  update 
)

Definition at line 19 of file vlist.c.

20 {
21  tree->update = update;
22  tree->version = 1;
23 
24  avl_init(&tree->avl, cmp, 0, tree);
25 }
void avl_init(struct avl_tree *tree, avl_tree_comp comp, bool allow_dups, void *ptr)
Definition: avl.c:92
Here is the call graph for this function: