OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [search/] [tfind.c] - Diff between revs 207 and 345

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
/*      $NetBSD: tfind.c,v 1.2 1999/09/16 11:45:37 lukem Exp $  */
/*      $NetBSD: tfind.c,v 1.2 1999/09/16 11:45:37 lukem Exp $  */
 
 
/*
/*
 * Tree search generalized from Knuth (6.2.2) Algorithm T just like
 * Tree search generalized from Knuth (6.2.2) Algorithm T just like
 * the AT&T man page says.
 * the AT&T man page says.
 *
 *
 * The node_t structure is for internal use only, lint doesn't grok it.
 * The node_t structure is for internal use only, lint doesn't grok it.
 *
 *
 * Written by reading the System V Interface Definition, not the code.
 * Written by reading the System V Interface Definition, not the code.
 *
 *
 * Totally public domain.
 * Totally public domain.
 */
 */
 
 
#include <sys/cdefs.h>
#include <sys/cdefs.h>
#if 0
#if 0
#if defined(LIBC_SCCS) && !defined(lint)
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: tfind.c,v 1.2 1999/09/16 11:45:37 lukem Exp $");
__RCSID("$NetBSD: tfind.c,v 1.2 1999/09/16 11:45:37 lukem Exp $");
#endif /* LIBC_SCCS and not lint */
#endif /* LIBC_SCCS and not lint */
#endif
#endif
 
 
#include <assert.h>
#include <assert.h>
#define _SEARCH_PRIVATE
#define _SEARCH_PRIVATE
#include <stdlib.h>
#include <stdlib.h>
#include <search.h>
#include <search.h>
 
 
/* find a node, or return 0 */
/* find a node, or return 0 */
void *
void *
_DEFUN(tfind, (vkey, vrootp, compar),
_DEFUN(tfind, (vkey, vrootp, compar),
        const void *vkey _AND           /* key to be found */
        const void *vkey _AND           /* key to be found */
        void **vrootp _AND              /* address of the tree root */
        void **vrootp _AND              /* address of the tree root */
        int (*compar)(const void *, const void *))
        int (*compar)(const void *, const void *))
{
{
        node_t **rootp = (node_t **)vrootp;
        node_t **rootp = (node_t **)vrootp;
 
 
        if (rootp == NULL)
        if (rootp == NULL)
                return NULL;
                return NULL;
 
 
        while (*rootp != NULL) {                /* T1: */
        while (*rootp != NULL) {                /* T1: */
                int r;
                int r;
 
 
                if ((r = (*compar)(vkey, (*rootp)->key)) == 0)   /* T2: */
                if ((r = (*compar)(vkey, (*rootp)->key)) == 0)   /* T2: */
                        return *rootp;          /* key found */
                        return *rootp;          /* key found */
                rootp = (r < 0) ?
                rootp = (r < 0) ?
                    &(*rootp)->llink :          /* T3: follow left branch */
                    &(*rootp)->llink :          /* T3: follow left branch */
                    &(*rootp)->rlink;           /* T4: follow right branch */
                    &(*rootp)->rlink;           /* T4: follow right branch */
        }
        }
        return NULL;
        return NULL;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.