X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/fe14fcc35f78a371a174a1d14256c2f35ae4262b..8665f9e443dd7c1aaeda99d470ddf0b6fe056f80:/x2p/hash.c diff --git a/x2p/hash.c b/x2p/hash.c index fd92045..8c218b6 100644 --- a/x2p/hash.c +++ b/x2p/hash.c @@ -1,26 +1,23 @@ -/* $Header: hash.c,v 4.0 91/03/20 01:57:49 lwall Locked $ +/* hash.c * - * Copyright (c) 1989, Larry Wall + * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001, 2002, + * 2005 by Larry Wall and others * - * You may distribute under the terms of the GNU General Public License - * as specified in the README file that comes with the perl 3.0 kit. - * - * $Log: hash.c,v $ - * Revision 4.0 91/03/20 01:57:49 lwall - * 4.0 baseline. - * + * You may distribute under the terms of either the GNU General Public + * License or the Artistic License, as specified in the README file. */ #include #include "EXTERN.h" -#include "handy.h" -#include "util.h" #include "a2p.h" +#include "util.h" + +#ifdef NETWARE +char *savestr(char *str); +#endif STR * -hfetch(tb,key) -register HASH *tb; -char *key; +hfetch(register HASH *tb, char *key) { register char *s; register int i; @@ -46,10 +43,7 @@ char *key; } bool -hstore(tb,key,val) -register HASH *tb; -char *key; -STR *val; +hstore(register HASH *tb, char *key, STR *val) { register char *s; register int i; @@ -74,7 +68,7 @@ STR *val; if (strNE(entry->hent_key,key)) /* is this it? */ continue; /*NOSTRICT*/ - safefree((char*)entry->hent_val); + safefree(entry->hent_val); entry->hent_val = val; return TRUE; } @@ -96,50 +90,10 @@ STR *val; return FALSE; } -#ifdef NOTUSED -bool -hdelete(tb,key) -register HASH *tb; -char *key; +void +hsplit(HASH *tb) { - register char *s; - register int i; - register int hash; - register HENT *entry; - register HENT **oentry; - - if (!tb) - return FALSE; - for (s=key, i=0, hash = 0; - /* while */ *s; - s++, i++, hash *= 5) { - hash += *s * coeff[i]; - } - - oentry = &(tb->tbl_array[hash & tb->tbl_max]); - entry = *oentry; - i = 1; - for (; entry; i=0, oentry = &entry->hent_next, entry = entry->hent_next) { - if (entry->hent_hash != hash) /* strings can't be equal */ - continue; - if (strNE(entry->hent_key,key)) /* is this it? */ - continue; - safefree((char*)entry->hent_val); - safefree(entry->hent_key); - *oentry = entry->hent_next; - safefree((char*)entry); - if (i) - tb->tbl_fill--; - return TRUE; - } - return FALSE; -} -#endif - -hsplit(tb) -HASH *tb; -{ - int oldsize = tb->tbl_max + 1; + const int oldsize = tb->tbl_max + 1; register int newsize = oldsize * 2; register int i; register HENT **a; @@ -148,7 +102,7 @@ HASH *tb; register HENT **oentry; a = (HENT**) saferealloc((char*)tb->tbl_array, newsize * sizeof(HENT*)); - bzero((char*)&a[oldsize], oldsize * sizeof(HENT*)); /* zero second half */ + memset(&a[oldsize], 0, oldsize * sizeof(HENT*)); /* zero second half */ tb->tbl_max = --newsize; tb->tbl_array = a; @@ -174,7 +128,7 @@ HASH *tb; } HASH * -hnew() +hnew(void) { register HASH *tb = (HASH*)safemalloc(sizeof(HASH)); @@ -182,63 +136,14 @@ hnew() tb->tbl_fill = 0; tb->tbl_max = 7; hiterinit(tb); /* so each() will start off right */ - bzero((char*)tb->tbl_array, 8 * sizeof(HENT*)); + memset(tb->tbl_array, 0, 8 * sizeof(HENT*)); return tb; } -#ifdef NOTUSED -hshow(tb) -register HASH *tb; -{ - fprintf(stderr,"%5d %4d (%2d%%)\n", - tb->tbl_max+1, - tb->tbl_fill, - tb->tbl_fill * 100 / (tb->tbl_max+1)); -} -#endif - -hiterinit(tb) -register HASH *tb; +int +hiterinit(register HASH *tb) { tb->tbl_riter = -1; tb->tbl_eiter = Null(HENT*); return tb->tbl_fill; } - -HENT * -hiternext(tb) -register HASH *tb; -{ - register HENT *entry; - - entry = tb->tbl_eiter; - do { - if (entry) - entry = entry->hent_next; - if (!entry) { - tb->tbl_riter++; - if (tb->tbl_riter > tb->tbl_max) { - tb->tbl_riter = -1; - break; - } - entry = tb->tbl_array[tb->tbl_riter]; - } - } while (!entry); - - tb->tbl_eiter = entry; - return entry; -} - -char * -hiterkey(entry) -register HENT *entry; -{ - return entry->hent_key; -} - -STR * -hiterval(entry) -register HENT *entry; -{ - return entry->hent_val; -}