0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 23:14:13 +01:00

ircd: radixtree: allow irc_radixtree_elem_find() to find a fuzzy match instead of an exact match

This commit is contained in:
William Pitcock 2016-01-20 22:10:35 -05:00
parent 0d9a72de21
commit 704697b6b6
2 changed files with 7 additions and 6 deletions

View file

@ -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);

View file

@ -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;