diff options
author | Neal H. Walfield <neal@gnu.org> | 2008-11-11 18:16:56 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@gnu.org> | 2008-11-11 18:16:56 +0100 |
commit | a33a7a7a9f0ac4a090226a602b6c647870faeb90 (patch) | |
tree | 4d042e7ae16605e81e75c6ce6e5c004d3f27d1ec /libhurd-btree | |
parent | 634e04c67250e8b6c21c4b190252dca687a1653e (diff) |
Remove dead code inherited from reference implementation.
2008-11-11 Neal H. Walfield <neal@gnu.org>
* btree.c: Remove dead code.
Diffstat (limited to 'libhurd-btree')
-rw-r--r-- | libhurd-btree/ChangeLog | 4 | ||||
-rw-r--r-- | libhurd-btree/btree.c | 244 |
2 files changed, 4 insertions, 244 deletions
diff --git a/libhurd-btree/ChangeLog b/libhurd-btree/ChangeLog index 16def15..caa5035 100644 --- a/libhurd-btree/ChangeLog +++ b/libhurd-btree/ChangeLog @@ -1,3 +1,7 @@ +2008-11-11 Neal H. Walfield <neal@gnu.org> + + * btree.c: Remove dead code. + 2008-11-03 Neal H. Walfield <neal@gnu.org> * headers.m4: Don't create an empty diff --git a/libhurd-btree/btree.c b/libhurd-btree/btree.c index 740cc39..ae284d5 100644 --- a/libhurd-btree/btree.c +++ b/libhurd-btree/btree.c @@ -126,20 +126,6 @@ #include <stdlib.h> #include <string.h> #include <stdint.h> -#if 0 -#include <search.h> - -typedef struct node_t -{ - /* Callers expect this to be the first element in the structure - do not - move! */ - const void *key; - struct node_t *left; - struct node_t *right; - unsigned int red:1; -} *node; -typedef const struct node_t *const_node; -#endif #define BTREE_EXTERN_INLINE #include "btree.h" @@ -619,156 +605,6 @@ BTREE_(maybe_split2_internal) (BTREE_(t) *btree, node root, int mode) } } -#if 0 - -/* Find or insert datum into search tree. - KEY is the key to be located, ROOTP is the address of tree root, - COMPAR the ordering function. */ -void * -__tsearch (const void *key, void **vrootp, __compar_fn_t compar) -{ - node q; - node *parentp = NULL, *gparentp = NULL; - node *rootp = (node *) vrootp; - node *nextp; - int r = 0, p_r = 0, gp_r = 0; /* No they might not, Mr Compiler. */ - - if (rootp == NULL) - return NULL; - - /* This saves some additional tests below. */ - if (*rootp != NULL) - (*rootp)->red = 0; - - CHECK_TREE (*rootp); - - nextp = rootp; - while (*nextp != NULL) - { - node root = *rootp; - r = (*compar) (key, root->key); - if (r == 0) - return root; - - maybe_split_for_insert (rootp, parentp, gparentp, p_r, gp_r, 0); - /* If that did any rotations, parentp and gparentp are now garbage. - That doesn't matter, because the values they contain are never - used again in that case. */ - - nextp = r < 0 ? &root->left : &root->right; - if (*nextp == NULL) - break; - - gparentp = parentp; - parentp = rootp; - rootp = nextp; - - gp_r = p_r; - p_r = r; - } - - q = (struct node_t *) malloc (sizeof (struct node_t)); - if (q != NULL) - { - *nextp = q; /* link new node to old */ - q->key = key; /* initialize new node */ - q->red = 1; - q->left = q->right = NULL; - } - if (nextp != rootp) - /* There may be two red edges in a row now, which we must avoid by - rotating the tree. */ - maybe_split_for_insert (nextp, rootp, parentp, r, p_r, 1); - - return q; -} -weak_alias (__tsearch, tsearch) - - -/* Find datum in search tree. - KEY is the key to be located, ROOTP is the address of tree root, - COMPAR the ordering function. */ -void * -__tfind (key, vrootp, compar) - const void *key; - void *const *vrootp; - __compar_fn_t compar; -{ - node *rootp = (node *) vrootp; - - if (rootp == NULL) - return NULL; - - CHECK_TREE (*rootp); - - while (*rootp != NULL) - { - node root = *rootp; - int r; - - r = (*compar) (key, root->key); - if (r == 0) - return root; - - rootp = r < 0 ? &root->left : &root->right; - } - return NULL; -} -weak_alias (__tfind, tfind) - - -/* Delete node with given key. - KEY is the key to be deleted, ROOTP is the address of the root of tree, - COMPAR the comparison function. */ -void * -__tdelete (const void *key, void **vrootp, __compar_fn_t compar) -{ - node p, q, r, retval; - int cmp; - node *rootp = (node *) vrootp; - node root, unchained; - /* Stack of nodes so we remember the parents without recursion. It's - _very_ unlikely that there are paths longer than 40 nodes. The tree - would need to have around 250.000 nodes. */ - int stacksize = 40; - int sp = 0; - node **nodestack = alloca (sizeof (node *) * stacksize); - - if (rootp == NULL) - return NULL; - p = *rootp; - if (p == NULL) - return NULL; - - CHECK_TREE (p); - - while ((cmp = (*compar) (key, (*rootp)->key)) != 0) - { - if (sp == stacksize) - { - node **newstack; - stacksize += 20; - newstack = alloca (sizeof (node *) * stacksize); - nodestack = memcpy (newstack, nodestack, sp * sizeof (node *)); - } - - nodestack[sp++] = rootp; - p = *rootp; - rootp = ((cmp < 0) - ? &(*rootp)->left - : &(*rootp)->right); - if (*rootp == NULL) - return NULL; - } - - /* This is bogus if the node to be deleted is the root... this routine - really should return an integer with 0 for success, -1 for failure - and errno = ESRCH or something. */ - retval = p; - ... -} -#endif - /* Detach node ROOT from the tree BTREE. */ void BTREE_(detach) (BTREE_(t) *btree, BTREE_(node_t) *root) @@ -1193,83 +1029,3 @@ BTREE_(detach) (BTREE_(t) *btree, BTREE_(node_t) *root) root->right.raw = 0; #endif } - -#if 0 -{ - ... - free (unchained); - return retval; -} -weak_alias (__tdelete, tdelete) - - -/* Walk the nodes of a tree. - ROOT is the root of the tree to be walked, ACTION the function to be - called at each node. LEVEL is the level of ROOT in the whole tree. */ -static void -internal_function -trecurse (const void *vroot, __action_fn_t action, int level) -{ - const_node root = (const_node) vroot; - - if (root->left == NULL && root->right == NULL) - (*action) (root, leaf, level); - else - { - (*action) (root, preorder, level); - if (root->left != NULL) - trecurse (root->left, action, level + 1); - (*action) (root, postorder, level); - if (root->right != NULL) - trecurse (root->right, action, level + 1); - (*action) (root, endorder, level); - } -} - - -/* Walk the nodes of a tree. - ROOT is the root of the tree to be walked, ACTION the function to be - called at each node. */ -void -__twalk (const void *vroot, __action_fn_t action) -{ - const_node root = (const_node) vroot; - - CHECK_TREE (root); - - if (root != NULL && action != NULL) - trecurse (root, action, 0); -} -weak_alias (__twalk, twalk) - - - -/* The standardized functions miss an important functionality: the - tree cannot be removed easily. We provide a function to do this. */ -static void -internal_function -tdestroy_recurse (node root, __free_fn_t freefct) -{ - if (root->left != NULL) - tdestroy_recurse (root->left, freefct); - if (root->right != NULL) - tdestroy_recurse (root->right, freefct); - (*freefct) ((void *) root->key); - /* Free the node itself. */ - free (root); -} - -void -__tdestroy (void *vroot, __free_fn_t freefct) -{ - node root = (node) vroot; - - CHECK_TREE (root); - - if (root != NULL) - tdestroy_recurse (root, freefct); -} -weak_alias (__tdestroy, tdestroy) - - -#endif |