summaryrefslogtreecommitdiffhomepage
path: root/utils.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-10-02 19:22:08 +0200
committerFelix Fietkau <nbd@openwrt.org>2011-10-02 19:22:08 +0200
commit05e910cec691f8333383a746876015e99ff088db (patch)
tree439f0e6d9c3a6d629aa4fd11319f3b53ca697c2b /utils.c
parentaab5615166efb78d793eccd1a5d5ac7aab6324f5 (diff)
make versioned lists more flexible by using an external comparator
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/utils.c b/utils.c
index 15f0525..42d3176 100644
--- a/utils.c
+++ b/utils.c
@@ -7,22 +7,15 @@ avl_strcmp(const void *k1, const void *k2, void *ptr)
return strcmp(k1, k2);
}
-static int
-vlist_cmp(const void *k1, const void *k2, void *ptr)
-{
- struct vlist_tree *vl = ptr;
- return memcmp(k1, k2, vl->data_len);
-}
-
void
-__vlist_init(struct vlist_tree *tree, vlist_update_cb update, int offset, int len)
+__vlist_init(struct vlist_tree *tree, avl_tree_comp cmp,
+ vlist_update_cb update, int offset)
{
- tree->data_offset = offset;
- tree->data_len = len;
+ tree->node_offset = offset;
tree->update = update;
tree->version = 1;
- avl_init(&tree->avl, vlist_cmp, 0, tree);
+ avl_init(&tree->avl, cmp, 0, tree);
}
void
@@ -37,11 +30,12 @@ vlist_add(struct vlist_tree *tree, struct vlist_node *node)
{
struct vlist_node *old_node = NULL;
struct avl_node *anode;
+ void *key = (char *) node - tree->node_offset;
- node->avl.key = (char *) node + tree->data_offset;
+ node->avl.key = key;
node->version = tree->version;
- anode = avl_find(&tree->avl, (char *) node + tree->data_offset);
+ anode = avl_find(&tree->avl, key);
if (anode) {
old_node = container_of(anode, struct vlist_node, avl);
avl_delete(&tree->avl, anode);