lib/hash.c


Log

Author Commit Date CI Message
Eric Blake 83b1d641 2011-04-27T16:23:45 hash, mgetgroups: drop xalloc dependency Rely on the new xalloc-oversized module to avoid requiring xalloc-die for functions documented as returning NULL on potential allocation overflow. * lib/hash.c (includes): Adjust includes. * lib/mgetgroups.c (includes): Likewise. (xgetgroups): Move... * lib/xgetgroups.c: ...to new file. * modules/xgetgroups: New file, split from... * modules/mgetgroups: ...here. (Depends-on): Add xalloc-oversized. * modules/hash (Depends-on): Likewise. * modules/hash-tests (Depends-on): Drop xalloc. (test_hash_LDADD): Drop unused library. * tests/test-hash.c (main): Break xalloc dependency. (includes): Drop unused include. Signed-off-by: Eric Blake <eblake@redhat.com>
Jim Meyering 6829a6c0 2011-04-25T10:38:33 Revert "use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE" This reverts commit 349d7fe0e307d59d508b3579317ee8d4eacfeb9c. Revert accidentally-pushed patch. Not yet ready.
Jim Meyering 349d7fe0 2011-04-24T19:02:10 use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering d60f3b0c 2011-01-01T20:17:23 maint: update almost all copyright ranges to include 2011 Run the new "make update-copyright" rule.
Paul Eggert 0fd6a77f 2010-09-02T12:51:40 hash: fix safe_hasher const typo * lib/hash.c (safe_hasher): Result is pointer, not pointer to const; otherwise, there is a type error later.
Eric Blake c0ebdfe2 2010-08-31T10:10:32 hash: factor, and guard against misbehaving hasher function * lib/hash.c (safe_hasher): New function, to encapsulate the checking of table->hasher's return value. Also protect against a hash value so large that adding it to table->bucket results in a NULL pointer. (hash_lookup, hash_get_next, hash_find_entry, transfer_entries): Use it in place of open-coded check-and-abort.
Bruno Haible e8504907 2010-08-31T08:43:53 hash: silence spurious clang warning * lib/hash.c (hash_get_next): Remove unnecessary test against NULL. Reported by Eric Blake.
Jim Meyering fbc47512 2010-07-04T10:54:38 hash: once again explicitly disallow insertion of NULL * lib/hash.c (hash_insert0): Reinstate just-removed test: inserting a NULL pointer cannot work with these functions. Add a comment with details. This reverts part of the 2010-07-01 commit, 5bef1a35 "hash: extend module to deal with non-pointer keys".
Jim Meyering 5bef1a35 2010-07-01T23:17:25 hash: extend module to deal with non-pointer keys * lib/hash.c (hash_insert0): New interface, much like hash_insert but that allows insertion of non-pointer entries. Do not disallow an ENTRY value of NULL. (hash_insert): This is now just a thin wrapper. Call hash_insert0. * lib/hash.h (hash_insert0): Declare.
Jim Meyering b2e2010c 2010-01-01T10:31:12 update nearly all FSF copyright year lists to include 2010 Use the same procedure as for 2009, outlined in http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/20081
Jim Meyering 3030c5b5 2009-12-28T10:50:36 update nearly all FSF copyright year lists to include 2009 The files named by the following are exempted: grep -v '^#' config/srclist.txt|grep -v '^$' \ | while read src dst; do test -f "$dst" && { echo "$dst"; continue; } test -d "$dst" || continue echo "$dst"/$(basename "$src") done > exempt git ls-files tests/unictype >> exempt In the remaining files, convert to all-interval notation if - there is already at least one year interval like 2000-2003 - the file is maintained by me - the file is in lib/uni*/, where that style already prevails Otherwise, use update-copyright's default.
Bruno Haible 441aa304 2009-12-10T20:28:30 Use spaces for indentation, not tabs.
Eric Blake ad82c2fb 2009-10-05T13:52:28 hash: allow C89 compilation * lib/hash.c (check_tuning): Move declaration before statement. Reported by Reuben Thomas. Signed-off-by: Eric Blake <ebb9@byu.net>
Jim Meyering 5082839d 2009-06-19T18:49:24 hash: reverse order of src/dst parameters in an internal interface * lib/hash.c (transfer_entries): Reverse order of parameters to put DST before SRC. Adjust callers.
Eric Blake 91fbe865 2009-06-08T05:56:37 hash: avoid memory leak on allocation failure * lib/hash.c: (hash_rehash): Avoid memory leak on allocation failure. Factor repeated algorithm... (transfer_entries): ...into new helper routine. (hash_delete): React to hash_rehash return value. Signed-off-by: Eric Blake <ebb9@byu.net>
Eric Blake b7b7fad1 2009-06-19T06:35:11 hash: reduce memory pressure in hash_rehash no-op case * lib/hash.c (next_prime): Avoid overflow. (hash_initialize): Factor bucket size computation... (compute_bucket_size): ...into new helper function. (hash_rehash): Use new function and open coding to reduce memory pressure, and avoid a memory leak in USE_OBSTACK code. Reported by Jim Meyering. Signed-off-by: Eric Blake <ebb9@byu.net>
Eric Blake 3ea71492 2009-06-18T13:31:11 hash: make rotation more obvious * modules/hash (Depends-on): Add bitrotate and stdint. * lib/bitrotate.h (rotl_sz, rotr_sz): New functions. * lib/hash.c (headers): Drop limits.h. Add stdint.h. (SIZE_MAX): Rely on headers for definition. (hash_string) [USE_DIFF_HASH]: Use rotl_sz. (raw_hasher): Use rotr_sz. Suggested by Jim Meyering. Signed-off-by: Eric Blake <ebb9@byu.net>
Eric Blake eabc7530 2009-06-18T15:24:38 hash: fix memory leak in last patch * lib/hash.c (hash_rehash): Avoid memory leak. Signed-off-by: Eric Blake <ebb9@byu.net>
Eric Blake 86514ea5 2009-06-18T13:18:34 hash: avoid no-op rehashing * lib/hash.c (hash_rehash): Recognize useless rehash attempts. Signed-off-by: Eric Blake <ebb9@byu.net>
Eric Blake af254bfe 2009-06-18T07:11:39 hash: provide default callback functions * lib/hash.c (raw_hasher, raw_comparator): New functions. (hash_initialize): Use them as defaults. * tests/test-hash.c (main): Test this. Signed-off-by: Eric Blake <ebb9@byu.net>
Eric Blake 16908fc8 2009-06-18T06:56:13 hash: minor optimization * lib/hash.c (hash_lookup, hash_find_entry): Avoid function call when possible. (hash_initialize): Document this promise. (hash_do_for_each, hash_clear, hash_free): Use C89 syntax. * tests/test-hash.c (hash_compare_strings): Test this. Signed-off-by: Eric Blake <ebb9@byu.net>
Eric Blake 1d1b2627 2009-06-17T13:01:41 hash: check for resize before insertion * lib/hash.c (hash_insert): Check whether bucket usage exceeds threshold before insertion, so that a pathological hash_rehash that fills every bucket can still trigger another rehash. Signed-off-by: Eric Blake <ebb9@byu.net>
Eric Blake f414a500 2009-06-17T21:04:55 hash: minor cleanups * lib/hash.h (hash_entry): Make opaque, by moving... * lib/hash.c (hash_entry): ...here. (hash_insert): Clarify restrictions on what can be inserted. (hash_get_next): Clarify when it is safe to remove an element during traversal. (check_tuning): Skip verification when tuning is known safe. (hash_initialize): Clarify restrictions on tuning. Signed-off-by: Eric Blake <ebb9@byu.net>
Bruno Haible 57fdfd3f 2007-10-07T19:14:58 Change copyright notice from GPLv2+ to GPLv3+.
Jim Meyering 6bfae955 2007-09-09T14:48:10 * lib/hash.c (hash_initialize): Detect calloc failure. Reported by Bruno Haible.
Paul Eggert 0632e115 2006-09-13T22:38:14 * _fpending.c: Include <config.h> unconditionally, since we no longer worry about uses that don't define HAVE_CONFIG_H. * acl.c, alloca.c, argmatch.c, atexit.c, backupfile.c: * basename.c, c-stack.c, c-strtod.c, calloc.c, canon-host.c: * canonicalize.c, chdir-long.c, chdir-safer.c, chown.c: * cloexec.c, close-stream.c, closeout.c, creat-safer.c: * cycle-check.c, diacrit.c, dirchownmod.c, dirfd.c, dirname.c: * dup-safer.c, dup2.c, error.c, euidaccess.c, exclude.c: * exitfail.c, fchmodat.c, fchown-stub.c, fd-safer.c: * file-type.c, fileblocks.c, filemode.c, filenamecat.c: * fnmatch.c, fopen-safer.c, fprintftime.c, free.c, fsusage.c: * ftruncate.c, fts-cycle.c, fts.c, full-write.c, gai_strerror.c: * getcwd.c, getdate.y, getdomainname.c, getgroups.c: * gethostname.c, gethrxtime.c, getloadavg.c, getlogin_r.c: * getndelim2.c, getnline.c, getopt.c, getopt1.c, getpass.c: * gettime.c, gettimeofday.c, getugroups.c, getusershell.c: * glob.c, group-member.c, hard-locale.c, hash-pjw.c, hash.c: * human.c, idcache.c, inet_ntop.c, inet_pton.c, inttostr.c: * isdir.c, lchown.c, linebuffer.c, long-options.c, lstat.c: * malloc.c, md5.c, memcasecmp.c, memchr.c, memcmp.c, memcoll.c: * memcpy.c, memmove.c, memrchr.c, mkancesdirs.c, mkdir-p.c: * mkdir.c, mkdirat.c, mkstemp-safer.c, mkstemp.c, modechange.c: * mountlist.c, nanosleep.c, obstack.c, open-safer.c: * openat-die.c, openat.c, pagealign_alloc.c, physmem.c: * pipe-safer.c, posixtm.c, posixver.c, putenv.c, quote.c: * quotearg.c, raise.c, readtokens.c, readtokens0.c, readutmp.c: * realloc.c, regex.c, rename.c, rmdir.c, rpmatch.c, safe-read.c: * same.c, save-cwd.c, savedir.c, setenv.c, settime.c, sha1.c: * sig2str.c, snprintf.c, strdup.c, strerror.c, strftime.c: * stripslash.c, strndup.c, strnlen.c, strpbrk.c, strtod.c: * strtoimax.c, strtol.c, strverscmp.c, tempname.c, time_r.c: * timegm.c, tmpfile-safer.c, unlinkdir.c, userspec.c, utime.c: * utimecmp.c, utimens.c, version-etc-fsf.c, version-etc.c: * xalloc-die.c, xgetcwd.c, xgethostname.c, xmalloc.c: * xmemcoll.c, xnanosleep.c, xreadlink.c, xstrtod.c: * xstrtoimax.c, xstrtol.c, xstrtoumax.c, yesno.c: Likewise.
Paul Eggert 222b0486 2005-09-19T17:28:14 Use a consistent style for including <config.h>. * __fpending.c, acl.c, argmatch.c, argp-help.c, argp-parse.c, argp-pvh.c, backupfile.c, basename.c, c-stack.c, calloc.c, check-version.c, cloexec.c, closeout.c, copy-file.c, creat-safer.c, cycle-check.c, dirfd.c, dirname.c, dup-safer.c, dup2.c, euidaccess.c, exclude.c, exitfail.c, fatal-signal.c, fd-safer.c, file-type.c, fileblocks.c, filemode.c, filenamecat.c, findprog.c, fnmatch.c, fopen-safer.c, free.c, fsusage.c, ftruncate.c, full-write.c, fwriteerror.c, getaddrinfo.c, getcwd.c, getdelim.c, getline.c, getlogin_r.c, getndelim2.c, getnline.c, getopt1.c, getpass.c, group-member.c, hard-locale.c, hash-pjw.c, hash.c, human.c, idcache.c, inet_ntop.c, isdir.c, long-options.c, malloc.c, memcasecmp.c, memcmp.c, memcoll.c, memcpy.c, memmove.c, mkdir-p.c, modechange.c, mountlist.c, open-safer.c, physmem.c, pipe-safer.c, pipe.c, poll.c, posixver.c, progname.c, progreloc.c, putenv.c, quote.c, quotearg.c, readline.c, readlink.c, realloc.c, regex.c, rename.c, rmdir.c, rpmatch.c, safe-read.c, same.c, save-cwd.c, savedir.c, sig2str.c, strcspn.c, strerror.c, stripslash.c, strncasecmp.c, strndup.c, strnlen.c, strnlen1.c, strsep.c, strstr.c, strtod.c, strtoimax.c, strtol.c, strverscmp.c, tempname.c, time_r.c, userspec.c, utimecmp.c, version-etc-fsf.c, version-etc.c, wait-process.c, xalloc-die.c, xgetcwd.c, xmalloc.c, xmemcoll.c, xnanosleep.c, xreadlink.c, xsetenv.c, xstrndup.c, xstrtoimax.c, xstrtol.c, xstrtoumax.c, yesno.c: Standardize inclusion of config.h. * __fpending.h, dirfd.h, getdate.h, human.h, inttostr.h: Removed inclusion of config.h from header files. * inttostr.c: Adjusted in-tree users. * timespec.h: Remove superfluous warning to include config.h. * atexit.c, chdir-long.c chown.c, fchown-stub.c, getgroups.c, gettimeofday.c, lchown.c, lstat.c, mkdir.c, mkstemp.c, nanosleep.c, openat.c, raise.c, readtokens0.c, readutmp.c, unlinkdir.c: Guard inclusion of config.h with HAVE_CONFIG_H.
Paul Eggert 267a39ba 2005-05-14T06:03:57 *** empty log message ***
Paul Eggert a62be9f4 2004-08-07T00:09:38 Merge from coreutils.
Jim Meyering e7e59650 2003-10-31T14:06:36 Include "xalloc.h" for use of xalloc_oversized.
Paul Eggert 0c0be7e5 2003-10-30T00:36:03 Simplify the code by using new xalloc.h features.
Paul Eggert c31c5f30 2003-10-26T00:14:40 Fix several address-calculation bugs in the hash modules, plus some minor code cleanup.
Paul Eggert 46474c5a 2003-09-09T19:37:26 Remove K&R cruft.
Paul Eggert 552a680f 2003-05-29T07:21:59 in lib: * addext.c, backupfile.c, fsusage.c, human.c, pathmax.h, rpmatch.c, userspec.c, xreadlink.c, xstrtol.c: Include <limits.h> without checking for HAVE_LIMITS_H. * backupfile.c, fsusage.c, hash.c, human.c, safe-read.c, userspec.c, xstrtol.c (CHAR_BIT) : Don't define, since <limits.h> is guaranteed to do that. * fatal.c: Include <stdarg.h> without checking for __STDC__. * exclude.c: Include <stdbool.h> unconditionally. * tempname.c: Include <stddef.h> unconditionally. * hash.c: Include <limits.h>, since we no longer define CHAR_BIT. * modechange.c, rpmatch.c (NULL): Don't define, since <stddef.h> does that. * quote.c: Dont include <stddef.h> or <sys/types.h>; not needed. * safe-read.c (INT_MAX): Don't define, since <limits.h> does that. * safe-read.c (TYPE_MINIMUM, TYPE_MAXIMUM): Remove; no longer needed. * xstrtol.c: Likewise. * safe-read.c: Remove TYPE_SIGNED; no longer needed. * savedir.c: Include <stddef.h> instead of defining NULL. in m4: * backupfile.m4 (gl_BACKUPFILE): Don't check for limits.h. * fsusage.m4 (gl_PREREQ_FSUSAGE_EXTRA): Likewise. * human.m4 (gl_HUMAN): Likewise. * pathmax.m4 (gl_PATHMAX): Likewise. * rpmatch.m4 (gl_FUNC_RPMATCH): Likewise. * userspec.m4 (gl_USERSPEC): Likewise. * xreadlink.m4 (gl_XREADLINK): Likewise. * m4/xstrtol.m4 (gl_PREREQ_XSTRTOL): Likewise. * quote.m4 (gl_QUOTE): Don't check for stddef.h.
Paul Eggert 0b98d363 2003-03-13T19:44:25 Include <stdbool.h> unconditionally.
Paul Eggert 4a105521 2002-11-28T00:34:24 (hash_lookup, hash_get_first, hash_get_next, hash_find_entry, hash_rehash): Replace `if (limit <= value) abort ();' with `if (! (value < limit)) abort ();', for readability.
Paul Eggert dda6605f 2002-11-23T07:02:40 Avoid use of <assert.h>, as the GNU Coding Standards hint that one should use `if (! x) abort ();' rather than `assert (x);', and anyway it's one less thing to worry about configuring. (hash_lookup, hash_get_first, hash_get_next, hash_find_entry, hash_rehash, hash_insert): Use abort rather than assert.
Jim Meyering 279745ad 2001-11-23T08:09:14 (struct hash_table): Define it here instead.
Jim Meyering 6a0b30c1 2001-11-03T08:23:54 (hash_clear): Fix a bug that could lead to an infloop or e.g., a fault due to an attempt to free a NULL pointer.
Jim Meyering 623af67c 2001-11-01T15:55:53 (hash_print) [TESTING]: Clean up.
Jim Meyering ce64c0b2 2001-08-31T07:49:39 Remove '2001' from copyright notice.
Jim Meyering 6e22c000 2001-01-20T09:36:19 whoops. revert last change
Jim Meyering dabd3d82 2001-01-20T09:34:20 Fix typo: s/false/0/.
Jim Meyering 51f49a8c 2000-12-25T18:51:58 add omitted semicolon
Jim Meyering 71b2adb4 2000-12-24T07:12:21 (is_prime): Return explicit boolean values. (hash_get_first): Return NULL to appease Irix5.6's 89.
Jim Meyering a0a18dea 2000-11-04T21:38:55 (hash_get_next): Fix a thinko: when ENTRY is the last one in a bucket, advance to the next bucket. From Alexandre Duret-Lutz.
Jim Meyering 9a884a50 2000-05-18T11:06:39 (hash_rehash): Fix a nasty bug: copy the free entry list back, too, since it may have been modified by allocate_entry. (hash_delete): Rewrite not to use both(!) the assignment operator and the comma operator in an if-expression.
Jim Meyering de1b0c61 2000-02-27T17:54:25 use double quotes, not single quotes around syntax-error-evoking string
Jim Meyering 92065733 2000-02-27T17:40:53 Arrange for cpp to fail if the configure-time declaration check was not run.
Jim Meyering b19c419e 2000-01-11T07:48:23 (hash_initialize): Fix typo in comment.
Jim Meyering b6044c6a 1999-03-17T14:07:34 (is_prime): Return bool rather than int.
Jim Meyering 9166d49f 1999-03-15T16:52:22 tweak comments add curlies use assert(0) in place of abort
Jim Meyering 6ad0acb4 1999-03-15T15:50:31 Revamp to allow fine-tuning to control when and by how much the table grows and shrinks. (next_prime): Don't assert. (hash_reset_tuning): New function. (check_tuning): New function. (hash_initialize): Accept and use new tuning parameter. (hash_rehash): Rewrite, updating for tuning. (hash_insert): Honor tuning semantics. (hash_delete): Likewise. From François Pinard.
Jim Meyering 21382cf3 1999-03-15T15:33:01 (hash_insert): Remove last parameter and change semantics. (hash_insert): Don't increment n_entries unconditionally -- otherwise, we'd do so even when the insertion failed. From François Pinard.
Jim Meyering bc44d402 1998-05-16T04:39:24 (is_prime): Ansideclify. (next_prime): Ansideclify. Add an assertion.
Jim Meyering 0e9de31e 1998-04-11T15:37:35 split a couple long lines
Jim Meyering 6845df70 1998-04-11T15:35:06 Add curly braces around statements in if/else/while/do/etc. that span more than a line -- even around multiline simple statements or single-line simple statements preceded by a comment line.
Jim Meyering ecdc5485 1998-04-06T08:09:11 Lots of minor spec and name changes, and new comments. (hash_rehash): Rewritten to be easier on the allocator. From François Pinard.
Jim Meyering 076487dd 1997-09-21T04:41:19 (hash_free_0): Remove prototype. Move function to precede first use.
Jim Meyering c3666f54 1997-09-20T19:38:29 (ZALLOC): Take Ht parameter instead of relying on one being in scope.
Jim Meyering 22a37aa3 1997-09-20T19:33:46 *** empty log message ***
Jim Meyering de081c65 1997-09-20T19:33:05 *** empty log message ***
Jim Meyering 188544a4 1997-09-20T18:32:40 *** empty log message ***
Jim Meyering 25e82030 1997-09-17T17:06:26 use malloc, not xmalloc in obstack #define use Uli's prime code, not near-prime (hash_initialize): don't require prime table size as input (hash_insert_if_absent): When rehashing, choose new size that is 2N+1, not 2N.
Jim Meyering 553bf6a0 1997-09-17T16:03:32 from ti/hdlsv