diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2015-09-06 16:01:56 +0000 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2015-09-06 16:01:56 +0000 |
commit | 8731a130e0eee35b2fb4e7db3c4f9c328ca1712c (patch) | |
tree | ac995f95bb8ba9950ace7b1f718555878f66d5eb /src/microhttpd/tsearch.c | |
parent | 9d25d25ed3eae4a58cdfca4ed80dcee30468f843 (diff) | |
download | libmicrohttpd-8731a130e0eee35b2fb4e7db3c4f9c328ca1712c.tar.gz libmicrohttpd-8731a130e0eee35b2fb4e7db3c4f9c328ca1712c.zip |
Update built-in tsearch replacement
Diffstat (limited to 'src/microhttpd/tsearch.c')
-rw-r--r-- | src/microhttpd/tsearch.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/microhttpd/tsearch.c b/src/microhttpd/tsearch.c index d4418f18..0c4d3e37 100644 --- a/src/microhttpd/tsearch.c +++ b/src/microhttpd/tsearch.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: tsearch.c,v 1.3 1999/09/16 11:45:37 lukem Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Tree search generalized from Knuth (6.2.2) Algorithm T just like | 2 | * Tree search generalized from Knuth (6.2.2) Algorithm T just like |
5 | * the AT&T man page says. | 3 | * the AT&T man page says. |
@@ -11,19 +9,20 @@ | |||
11 | * Totally public domain. | 9 | * Totally public domain. |
12 | */ | 10 | */ |
13 | 11 | ||
14 | #ifndef _MSC_FULL_VER | ||
15 | #include <sys/cdefs.h> | ||
16 | #endif /*! _MSC_FULL_VER */ | ||
17 | #define _SEARCH_PRIVATE | ||
18 | #include "tsearch.h" | 12 | #include "tsearch.h" |
19 | #include <stdlib.h> | 13 | #include <stdlib.h> |
20 | 14 | ||
15 | typedef struct node { | ||
16 | const void *key; | ||
17 | struct node *llink, *rlink; | ||
18 | } node_t; | ||
19 | |||
20 | /* $NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $ */ | ||
21 | /* find or insert datum into search tree */ | 21 | /* find or insert datum into search tree */ |
22 | void * | 22 | void * |
23 | tsearch(vkey, vrootp, compar) | 23 | tsearch(const void *vkey, /* key to be located */ |
24 | const void *vkey; /* key to be located */ | 24 | void **vrootp, /* address of tree root */ |
25 | void **vrootp; /* address of tree root */ | 25 | int (*compar)(const void *, const void *)) |
26 | int (*compar)(const void *, const void *); | ||
27 | { | 26 | { |
28 | node_t *q; | 27 | node_t *q; |
29 | node_t **rootp = (node_t **)vrootp; | 28 | node_t **rootp = (node_t **)vrootp; |
@@ -43,23 +42,22 @@ tsearch(vkey, vrootp, compar) | |||
43 | } | 42 | } |
44 | 43 | ||
45 | q = malloc(sizeof(node_t)); /* T5: key not found */ | 44 | q = malloc(sizeof(node_t)); /* T5: key not found */ |
46 | if (q != 0) { /* make new node */ | 45 | if (q) { /* make new node */ |
47 | *rootp = q; /* link new node to old */ | 46 | *rootp = q; /* link new node to old */ |
48 | /* LINTED const castaway ok */ | 47 | q->key = vkey; /* initialize new node */ |
49 | q->key = (void *)vkey; /* initialize new node */ | ||
50 | q->llink = q->rlink = NULL; | 48 | q->llink = q->rlink = NULL; |
51 | } | 49 | } |
52 | return q; | 50 | return q; |
53 | } | 51 | } |
54 | 52 | ||
55 | /* find a node, or return 0 */ | 53 | /* $NetBSD: tfind.c,v 1.5 2005/03/23 08:16:53 kleink Exp $ */ |
54 | /* find a node, or return NULL */ | ||
56 | void * | 55 | void * |
57 | tfind(vkey, vrootp, compar) | 56 | tfind(const void *vkey, /* key to be found */ |
58 | const void *vkey; /* key to be found */ | 57 | void * const *vrootp, /* address of the tree root */ |
59 | void * const *vrootp; /* address of the tree root */ | 58 | int (*compar)(const void *, const void *)) |
60 | int (*compar)(const void *, const void *); | ||
61 | { | 59 | { |
62 | node_t **rootp = (node_t **)vrootp; | 60 | node_t * const *rootp = (node_t * const*)vrootp; |
63 | 61 | ||
64 | if (rootp == NULL) | 62 | if (rootp == NULL) |
65 | return NULL; | 63 | return NULL; |
@@ -76,6 +74,7 @@ tfind(vkey, vrootp, compar) | |||
76 | return NULL; | 74 | return NULL; |
77 | } | 75 | } |
78 | 76 | ||
77 | /* $NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */ | ||
79 | /* | 78 | /* |
80 | * delete node with given key | 79 | * delete node with given key |
81 | * | 80 | * |