freebsd-nq/lib/libc/stdlib
Ed Schouten 2747eff128 Replace implementation of hsearch() by one that scales.
Traditionally the hcreate() function creates a hash table that uses
chaining, using a fixed user-provided size. The problem with this
approach is that this often either wastes memory (table too big) or
yields bad performance (table too small). For applications it may not
always be easy to estimate the right hash table size. A fixed number
only increases performance compared to a linked list by a constant
factor.

This problem can be solved easily by dynamically resizing the hash
table. If the size of the hash table is at least doubled, this has no
negative on the running time complexity. If a dynamically sized hash
table is used, we can also switch to using open addressing instead of
chaining, which has the advantage of just using a single allocation for
the entire table, instead of allocating many small objects.

Finally, a problem with the existing implementation is that its
deterministic algorithm for hashing makes it possible to come up with
fixed patterns to trigger an excessive number of collisions. We can
easily solve this by using FNV-1a as a hashing algorithm in combination
with a randomly generated offset basis.

Measurements have shown that this implementation is about 20-25% faster
than the existing implementation (even if the existing implementation is
given an excessive number of buckets). Though it allocates more memory
through malloc() than the old implementation (between 4-8 pointers per
used entry instead of 3), process memory use is similar to the old
implementation as if the estimated size was underestimated by a factor
10. This is due to the fact that malloc() needs to perform less
bookkeeping.

Reviewed by:	jilles, pfg
Obtained from:	https://github.com/NuxiNL/cloudlibc
Differential Revision:	https://reviews.freebsd.org/D4644
2015-12-27 07:50:11 +00:00
..
jemalloc META MODE: Don't create .meta files when symlinking sources into the obj directory. 2015-11-25 19:44:43 +00:00
_Exit.c
a64l.3 use .Mt to mark up email addresses consistently (part4) 2014-06-23 08:25:03 +00:00
a64l.c
abort.3 Renumber clauses to reduce diffs to other versions 2013-05-28 20:57:40 +00:00
abort.c Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-20 20:24:28 +00:00
abs.3 Renumber clauses to reduce diffs to other versions 2013-05-28 20:57:40 +00:00
abs.c Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-20 20:24:28 +00:00
alloca.3 Renumber clauses to reduce diffs to other versions 2013-05-28 20:57:40 +00:00
at_quick_exit.3 Update the 'C1x draft' reference to '.St -isoC-2011' mdoc macro. 2012-07-26 12:04:11 +00:00
atexit.3 Various mdoc fixes and a few EOL whitespace removals. 2014-12-21 12:36:36 +00:00
atexit.c Remove names from prototypes 2015-09-20 20:15:44 +00:00
atexit.h Renumber clauses to reduce diffs to other versions 2013-05-28 20:57:40 +00:00
atof.3 Renumber clauses to reduce diffs to other versions 2013-05-28 20:57:40 +00:00
atof.c Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-20 20:24:28 +00:00
atoi.3 Renumber clauses to reduce diffs to other versions 2013-05-28 20:57:40 +00:00
atoi.c Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-20 20:24:28 +00:00
atol.3 Renumber clauses to reduce diffs to other versions 2013-05-28 20:57:40 +00:00
atol.c Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-20 20:24:28 +00:00
atoll.c Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-20 20:24:28 +00:00
bsearch_b.c Add support for some block functions that come from OS X. These are 2014-04-02 16:07:48 +00:00
bsearch.3 Renumber clauses to reduce diffs to other versions 2013-05-28 20:57:40 +00:00
bsearch.c Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-20 20:24:28 +00:00
div.3 Renumber clauses to reduce diffs to other versions 2013-05-28 20:57:40 +00:00
div.c Renumber clauses to reduce diffs to other versions 2013-05-28 20:57:40 +00:00
exit.3 Various mdoc fixes and a few EOL whitespace removals. 2014-12-21 12:36:36 +00:00
exit.c Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-20 20:24:28 +00:00
getenv.3 Renumber clauses to reduce diffs to other versions 2013-05-28 20:57:40 +00:00
getenv.c [fix to r253380] __setenv: be explicit about placing '=' after name 2013-07-17 08:45:27 +00:00
getopt_long.3 getopt_long.3: wording quibbles 2013-12-13 21:50:03 +00:00
getopt_long.c Merge intermediate OpenBSD v1.25 changes (almost identical to ours) 2014-06-22 21:54:57 +00:00
getopt.3 [mdoc] Fix previous change. 2014-07-08 12:19:34 +00:00
getopt.c getopt(3): recognize option:: as GNU extension for "optional options". 2014-06-22 20:13:57 +00:00
getsubopt.3 Renumber clauses to reduce diffs to other versions 2013-05-28 20:57:40 +00:00
getsubopt.c ANSI-fy prototype. 2014-01-14 01:52:34 +00:00
hcreate_r.c Replace implementation of hsearch() by one that scales. 2015-12-27 07:50:11 +00:00
hcreate.3 Replace implementation of hsearch() by one that scales. 2015-12-27 07:50:11 +00:00
hcreate.c Replace implementation of hsearch() by one that scales. 2015-12-27 07:50:11 +00:00
hdestroy_r.c Replace implementation of hsearch() by one that scales. 2015-12-27 07:50:11 +00:00
heapsort_b.c Add support for some block functions that come from OS X. These are 2014-04-02 16:07:48 +00:00
heapsort.c Remove names from prototypes 2015-09-20 20:15:44 +00:00
hsearch_r.c Replace implementation of hsearch() by one that scales. 2015-12-27 07:50:11 +00:00
hsearch.h Replace implementation of hsearch() by one that scales. 2015-12-27 07:50:11 +00:00
imaxabs.3
imaxabs.c
imaxdiv.3
imaxdiv.c
insque.3
insque.c
l64a.c
labs.3 Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
labs.c Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-20 20:24:28 +00:00
ldiv.3 Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
ldiv.c Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
llabs.3
llabs.c
lldiv.3
lldiv.c
lsearch.3 Add example. 2013-04-21 10:30:19 +00:00
lsearch.c Use the __DECONST macro rather than hand rolling the same thing. 2014-10-24 23:25:44 +00:00
Makefile.inc Replace implementation of hsearch() by one that scales. 2015-12-27 07:50:11 +00:00
memory.3 Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
merge.c Remove names from prototypes 2015-09-20 20:15:44 +00:00
mergesort_b.c Add support for some block functions that come from OS X. These are 2014-04-02 16:07:48 +00:00
ptsname.3 According to a clarification at http://austingroupbugs.net/view.php?id=503 2012-09-12 17:54:09 +00:00
ptsname.c According to a clarification at http://austingroupbugs.net/view.php?id=503 2012-09-12 17:54:09 +00:00
qsort_r.c Silence a warning with GCC that was breaking the build with Juniper's GCC. 2014-04-05 08:17:48 +00:00
qsort.3 Add support for some block functions that come from OS X. These are 2014-04-02 16:07:48 +00:00
qsort.c Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-20 20:24:28 +00:00
quick_exit.3 Fix quick_exit(3) manual page to match reality - the status was missing. 2014-12-13 21:13:28 +00:00
quick_exit.c Small style(9) improvements. 2011-12-15 11:16:41 +00:00
radixsort.3 Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
radixsort.c Use ANSI C prototypes. 2015-09-14 18:44:13 +00:00
rand.3 Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
rand.c Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-20 20:24:28 +00:00
random.3 Adjust wording slightly to emphasize that random(3) should not be used for 2015-02-25 07:49:15 +00:00
random.c Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
reallocarray.3 Fix major copy/paste and other style errors. 2015-05-05 10:44:17 +00:00
reallocarray.c Import reallocarray(3) from OpenBSD 2015-05-01 18:32:16 +00:00
reallocf.3 Import jemalloc 9ef7f5dc34ff02f50d401e41c8d9a4a928e7c2aa (dev branch, 2012-04-17 07:22:14 +00:00
reallocf.c
realpath.3 Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
realpath.c realpath(): Properly fail "." or ".." components after non-directories. 2014-04-13 19:48:28 +00:00
remque.c
strfmon.3 use .Mt to mark up email addresses consistently (part4) 2014-06-23 08:25:03 +00:00
strfmon.c strfmon: reduce unnecessary snprintf. 2014-07-12 15:19:30 +00:00
strtod.3 Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
strtoimax.c Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
strtol.3 Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
strtol.c Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
strtoll.c Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
strtonum.3 Make example more correct (errstr is a pointer, not boolean). 2013-08-18 10:33:46 +00:00
strtonum.c Minor style tweaks. 2014-08-13 03:44:30 +00:00
strtoq.c Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
strtoul.3 Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
strtoul.c Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
strtoull.c Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
strtoumax.c Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
strtouq.c Renumber clauses to reduce diffs to other versions 2013-06-13 00:19:30 +00:00
Symbol.map Import reallocarray(3) from OpenBSD 2015-05-01 18:32:16 +00:00
system.3 Document the fact that system(3) can easily be misused due to shell meta 2015-07-25 00:21:29 +00:00
system.c Switch libc from using _sig{procmask,action,suspend} symbols, which 2015-08-29 14:25:01 +00:00
tdelete.c Let tsearch()/tdelete() use an AVL tree. 2015-12-22 18:12:11 +00:00
tfind.c Use ANSI C prototypes. Eliminates -Wold-style-definition warnings. 2015-09-20 20:24:28 +00:00
tsearch_path.h Let tsearch()/tdelete() use an AVL tree. 2015-12-22 18:12:11 +00:00
tsearch.3 Let tsearch()/tdelete() use an AVL tree. 2015-12-22 18:12:11 +00:00
tsearch.c Let tsearch()/tdelete() use an AVL tree. 2015-12-22 18:12:11 +00:00
twalk.c libc/stdlib: Minor cleanups to code originating in NetBSD 2014-07-15 03:28:37 +00:00