From 704697b6b68acb5cba873a4f594598e3360a340d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 20 Jan 2016 22:10:35 -0500 Subject: [PATCH] ircd: radixtree: allow irc_radixtree_elem_find() to find a fuzzy match instead of an exact match --- include/irc_radixtree.h | 2 +- ircd/irc_radixtree.c | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/irc_radixtree.h b/include/irc_radixtree.h index 3d504e01..dc7c4b6a 100644 --- a/include/irc_radixtree.h +++ b/include/irc_radixtree.h @@ -140,7 +140,7 @@ extern void *irc_radixtree_delete(struct irc_radixtree *dtree, const char *key); /* Low-level functions */ struct irc_radixtree_leaf *irc_radixtree_elem_add(struct irc_radixtree *dtree, const char *key, void *data); -struct irc_radixtree_leaf *irc_radixtree_elem_find(struct irc_radixtree *dtree, const char *key); +struct irc_radixtree_leaf *irc_radixtree_elem_find(struct irc_radixtree *dtree, const char *key, int fuzzy); void irc_radixtree_elem_delete(struct irc_radixtree *dtree, struct irc_radixtree_leaf *elem); const char *irc_radixtree_elem_get_key(struct irc_radixtree_leaf *elem); void irc_radixtree_elem_set_data(struct irc_radixtree_leaf *elem, void *data); diff --git a/ircd/irc_radixtree.c b/ircd/irc_radixtree.c index 008e2335..8b57d7d7 100644 --- a/ircd/irc_radixtree.c +++ b/ircd/irc_radixtree.c @@ -543,6 +543,7 @@ irc_radixtree_foreach_next(struct irc_radixtree *dtree, struct irc_radixtree_ite * Inputs: * - patricia tree object * - name of node to lookup + * - whether to do a direct or fuzzy match * * Outputs: * - on success, the dtree node requested @@ -552,7 +553,7 @@ irc_radixtree_foreach_next(struct irc_radixtree *dtree, struct irc_radixtree_ite * - none */ struct irc_radixtree_leaf * -irc_radixtree_elem_find(struct irc_radixtree *dict, const char *key) +irc_radixtree_elem_find(struct irc_radixtree *dict, const char *key, int fuzzy) { char ckey_store[256]; @@ -600,7 +601,7 @@ irc_radixtree_elem_find(struct irc_radixtree *dict, const char *key) } /* Now, if the key is in the tree, delem contains it. */ - if ((delem != NULL) && strcmp(delem->leaf.key, ckey)) + if ((delem != NULL) && !fuzzy && strcmp(delem->leaf.key, ckey)) delem = NULL; if (ckey_buf != NULL) @@ -634,7 +635,7 @@ irc_radixtree_foreach_start_from(struct irc_radixtree *dtree, struct irc_radixtr if (key != NULL) { STATE_CUR(state) = NULL; - STATE_NEXT(state) = irc_radixtree_elem_find(dtree, key); + STATE_NEXT(state) = irc_radixtree_elem_find(dtree, key, 1); /* make STATE_CUR point to selected item and STATE_NEXT point to * next item in the tree */ @@ -840,7 +841,7 @@ irc_radixtree_delete(struct irc_radixtree *dict, const char *key) void *data; struct irc_radixtree_leaf *leaf; - leaf = irc_radixtree_elem_find(dict, key); + leaf = irc_radixtree_elem_find(dict, key, 0); if (leaf == NULL) return NULL; @@ -940,7 +941,7 @@ irc_radixtree_elem_delete(struct irc_radixtree *dict, struct irc_radixtree_leaf void * irc_radixtree_retrieve(struct irc_radixtree *dtree, const char *key) { - struct irc_radixtree_leaf *delem = irc_radixtree_elem_find(dtree, key); + struct irc_radixtree_leaf *delem = irc_radixtree_elem_find(dtree, key, 0); if (delem != NULL) return delem->data;