diff options
author | Larry Wall <larry@wall.org> | 1988-06-05 00:00:00 +0000 |
---|---|---|
committer | Larry Wall <larry@wall.org> | 1988-06-05 00:00:00 +0000 |
commit | 378cc40b38293ffc7298c6a7ed3cd740ad79be52 (patch) | |
tree | 87bedf9adc5c88847a2e2d85963df5f94435aaf5 /hash.c | |
parent | a4de7c03d0bdc29d9d3a18abad4ac2628182ed7b (diff) | |
download | perl-2.0.tar.gz |
perl 2.0 (no announcement message available)perl-2.0
Some of the enhancements from Perl1 included:
* New regexp routines derived from Henry Spencer's.
o Support for /(foo|bar)/.
o Support for /(foo)*/ and /(foo)+/.
o \s for whitespace, \S for non-, \d for digit, \D nondigit
* Local variables in blocks, subroutines and evals.
* Recursive subroutine calls are now supported.
* Array values may now be interpolated into lists: unlink 'foo', 'bar', @trashcan, 'tmp';
* File globbing.
* Use of <> in array contexts returns the whole file or glob list.
* New iterator for normal arrays, foreach, that allows both read and write.
* Ability to open pipe to a forked off script for secure pipes in setuid scripts.
* File inclusion via do 'foo.pl';
* More file tests, including -t to see if, for instance, stdin is a terminal. File tests now behave in a more correct manner. You can do file tests on filehandles as well as filenames. The special filetests -T and -B test a file to see if it's text or binary.
* An eof can now be used on each file of the <> input for such purposes as resetting the line numbers or appending to each file of an inplace edit.
* Assignments can now function as lvalues, so you can say things like ($HOST = $host) =~ tr/a-z/A-Z/; ($obj = $src) =~ s/\.c$/.o/;
* You can now do certain file operations with a variable which holds the name of a filehandle, e.g. open(++$incl,$includefilename); $foo = <$incl>;
* Warnings are now available (with -w) on use of uninitialized variables and on identifiers that are mentioned only once, and on reference to various undefined things.
* There is now a wait operator.
* There is now a sort operator.
* The manual is now not lying when it says that perl is generally faster than sed. I hope.
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 82 |
1 files changed, 62 insertions, 20 deletions
@@ -1,16 +1,12 @@ -/* $Header: hash.c,v 1.0 87/12/18 13:05:17 root Exp $ +/* $Header: hash.c,v 2.0 88/06/05 00:09:06 root Exp $ * * $Log: hash.c,v $ - * Revision 1.0 87/12/18 13:05:17 root - * Initial revision + * Revision 2.0 88/06/05 00:09:06 root + * Baseline version 2.0. * */ -#include <stdio.h> #include "EXTERN.h" -#include "handy.h" -#include "util.h" -#include "search.h" #include "perl.h" STR * @@ -26,7 +22,7 @@ char *key; if (!tb) return Nullstr; for (s=key, i=0, hash = 0; - /* while */ *s; + /* while */ *s && i < COEFFSIZE; s++, i++, hash *= 5) { hash += *s * coeff[i]; } @@ -56,7 +52,7 @@ STR *val; if (!tb) return FALSE; for (s=key, i=0, hash = 0; - /* while */ *s; + /* while */ *s && i < COEFFSIZE; s++, i++, hash *= 5) { hash += *s * coeff[i]; } @@ -90,8 +86,7 @@ STR *val; return FALSE; } -#ifdef NOTUSED -bool +STR * hdelete(tb,key) register HASH *tb; char *key; @@ -101,11 +96,12 @@ char *key; register int hash; register HENT *entry; register HENT **oentry; + STR *str; if (!tb) - return FALSE; + return Nullstr; for (s=key, i=0, hash = 0; - /* while */ *s; + /* while */ *s && i < COEFFSIZE; s++, i++, hash *= 5) { hash += *s * coeff[i]; } @@ -113,22 +109,20 @@ char *key; oentry = &(tb->tbl_array[hash & tb->tbl_max]); entry = *oentry; i = 1; - for (; entry; i=0, oentry = &entry->hent_next, entry = entry->hent_next) { + for (; entry; i=0, oentry = &entry->hent_next, entry = *oentry) { 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); + str = str_static(entry->hent_val); + hentfree(entry); if (i) tb->tbl_fill--; - return TRUE; + return str; } - return FALSE; + return Nullstr; } -#endif hsplit(tb) HASH *tb; @@ -180,6 +174,54 @@ hnew() return tb; } +void +hentfree(hent) +register HENT *hent; +{ + if (!hent) + return; + str_free(hent->hent_val); + safefree(hent->hent_key); + safefree((char*)hent); +} + +void +hclear(tb) +register HASH *tb; +{ + register HENT *hent; + register HENT *ohent = Null(HENT*); + + if (!tb) + return; + hiterinit(tb); + while (hent = hiternext(tb)) { /* concise but not very efficient */ + hentfree(ohent); + ohent = hent; + } + hentfree(ohent); + tb->tbl_fill = 0; + bzero((char*)tb->tbl_array, (tb->tbl_max + 1) * sizeof(HENT*)); +} + +#ifdef NOTUSED +void +hfree(tb) +HASH *tb; +{ + if (!tb) + return + hiterinit(tb); + while (hent = hiternext(tb)) { + hentfree(ohent); + ohent = hent; + } + hentfree(ohent); + safefree((char*)tb->tbl_array); + safefree((char*)tb); +} +#endif + #ifdef NOTUSED hshow(tb) register HASH *tb; |