diff options
author | Felix Fietkau <nbd@openwrt.org> | 2011-10-02 19:22:08 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2011-10-02 19:22:08 +0200 |
commit | 05e910cec691f8333383a746876015e99ff088db (patch) | |
tree | 439f0e6d9c3a6d629aa4fd11319f3b53ca697c2b /utils.c | |
parent | aab5615166efb78d793eccd1a5d5ac7aab6324f5 (diff) |
make versioned lists more flexible by using an external comparator
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 20 |
1 files changed, 7 insertions, 13 deletions
@@ -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); |