diff options
author | Robert James Kaes <rjkaes@users.sourceforge.net> | 2001-08-30 16:52:09 +0000 |
---|---|---|
committer | Robert James Kaes <rjkaes@users.sourceforge.net> | 2001-08-30 16:52:09 +0000 |
commit | a328cefbf067785a867f53df042ca02ec3e6f39d (patch) | |
tree | 80646d0fed90a24ba3d48ef1811b246eb4e09d73 /src/ternary.c | |
parent | 22bdb8123d8c1687bf8ea31c98bdd0c47833aee7 (diff) | |
download | tinyproxy-a328cefbf067785a867f53df042ca02ec3e6f39d.tar.gz tinyproxy-a328cefbf067785a867f53df042ca02ec3e6f39d.zip |
Renamed ternary_insert() to ternary_insert_replace() and added the ability
to replace existing data (without a memory leak.) Added two DEFINES
ternary_insert() and ternary_replace() to aid in coding.
Diffstat (limited to 'src/ternary.c')
-rw-r--r-- | src/ternary.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/ternary.c b/src/ternary.c index df93ead..0a4ee09 100644 --- a/src/ternary.c +++ b/src/ternary.c @@ -1,4 +1,4 @@ -/* $Id: ternary.c,v 1.5 2001-05-23 17:59:53 rjkaes Exp $ +/* $Id: ternary.c,v 1.6 2001-08-30 16:52:09 rjkaes Exp $ * * This module creates a Ternary Search Tree which can store both string * keys, and arbitrary data for each key. It works similar to a hash, and @@ -294,7 +294,8 @@ int ternary_destroy(TERNARY tno, void (*freeptr)(void *)) * TE_TOOFULL tree is full, so no new elements can be added. * Exceptions: none */ -int ternary_insert(TERNARY tno, const char *s, void *data) +int ternary_insert_replace(TERNARY tno, const char *s, void *data, + short int replace) { int cur; /* index of current tree */ Ttree *tree; /* pointer to tree structure */ @@ -314,7 +315,13 @@ int ternary_insert(TERNARY tno, const char *s, void *data) while ((pp = *p)) { if ((d = *s - pp->splitchar) == 0) { if (*s++ == 0) { - return TE_EXISTS; + if (!replace) + return TE_EXISTS; + else { + free(pp->eqkid); + pp->eqkid = (Tnode *)data; + return TE_NONE; + } } p = &(pp->eqkid); } else if (d < 0) |