Nim/lib/pure
Charles Blake 65ce08f38c Add hcode. Re-factor rawGet. Fix infinite loop.
Replace state enum with a cached hash code which has the same memory overhead
and locality as the enum, but can really speed things up with non-integer-like
keys (keys for which either hash() or == take more than couple cycles, or where
the key data is "indirect" and might incur another cache miss).  To function as
both empty/filled state and a hash code cache, it only needs to be ensured that
hash codes are non-zero for any real key.  That is done at the one place in the
whole file hash() is called.  Keep convention clear via isFilled() & isEmpty().
An isDeleted state will no longer be necessary as per below excl/inf loop fix.

Since some use sites know hc and some do not, re-factor rawGet into two forms -
one with known hash code and one with an unknown HC that returns it. Both forms
still return <0 on missing, but returns the much more informative "-1 - index".
That return can be quickly inverted by -1 - result to recover the index where
insert should happen, provided no modifications are made to the table in the
meantime.  This protocol retains the prior <0 interface and also makes it easy
to avoid unnecessary duplicate search work in procs like containsOrInclImpl
(which formerly searched in the initial get and AGAIN in rawInsert).  Strip the
searching part out of rawInsert to "make it even more raw".  swap(s.data, n) a
bit earlier so rawGet and rawGetKnownHC can have similar parameter lists and
integrate well with rawInsert/code sharing between Set and OrderedSet impls.

This PR also fixes infinite looping upon too many deletes. [ The deleted state
(aka "tombstone") approach is vulnerable to the table filling up with deleted
items which forces giant scans for missing keys which could be anywhere.  In
the version prior to this PR, table wraparound wasn't even detected yielding
infinite loops. ] This PR changes excl() from marking slots as deleted to Knuth
algo 6.4R, "local/incremental moveback rehashing" - adapted from Knuth's h->h-1
to the cache-friendlier h->h+1 probe sequence and adapted from "gotos" to a new
doWhile template.  This method restores the table to a state that would have
resulted from pure inserts (in some order).  Update nextTry accordingly.  Since
linear probing can degrade a little faster, 50% rather than 66% may be a better
default growth threshold, but users should be able to adjust threshold anyway.

Old unit tests all pass.  More extensive testing in this module is probably
warranted before taking similar enhancements over to collections.tables.
2015-02-06 09:24:20 -05:00
..
collections Add hcode. Re-factor rawGet. Fix infinite loop. 2015-02-06 09:24:20 -05:00
concurrency Happy new year! 2015-01-06 15:26:33 +01:00
unidecode big rename 2014-08-27 23:42:51 +02:00
actors.nim Nimrod renamed to Nim 2014-08-28 09:59:26 +02:00
actors.nim.cfg renamed babelcmd to nimblecmd; config files are now nim.cfg; other renamings 2014-08-29 09:03:00 +02:00
algorithm.nim Add nextPermutation and prevPermutation 2015-02-01 18:29:01 +01:00
asyncdispatch.nim Happy new year! 2015-01-06 15:26:33 +01:00
asyncdispatch.nimrod.cfg Fix docgen. 2014-03-29 22:01:20 +00:00
asyncfile.nim Happy new year! 2015-01-06 15:26:33 +01:00
asyncftpclient.nim Happy new year! 2015-01-06 15:26:33 +01:00
asynchttpserver.nim Happy new year! 2015-01-06 15:26:33 +01:00
asyncio.nim Deprecated asyncio module. Fixed old tests. 2014-12-26 19:21:34 +00:00
asyncnet.nim Happy new year! 2015-01-06 15:26:33 +01:00
base64.nim Some docgen fixes. 2014-09-13 15:35:09 +01:00
basic2d.nim updated basic2d, basic3d modules 2014-08-28 01:27:36 +02:00
basic3d.nim updated basic2d, basic3d modules 2014-08-28 01:27:36 +02:00
browsers.nim big rename 2014-08-27 23:42:51 +02:00
cgi.nim renamed URLencode to encodeUrl 2014-09-10 23:25:29 +02:00
colors.nim big rename 2014-08-27 23:42:51 +02:00
complex.nim Added complex conjugate 2015-01-24 22:57:19 -05:00
cookies.nim merged things from devel 2014-09-12 01:37:48 +02:00
dynlib.nim fixed poxix dynlib names for bigbreak 2014-09-04 21:38:45 -07:00
encodings.nim Happy new year! 2015-01-06 15:26:33 +01:00
endians.nim big rename 2014-08-27 23:42:51 +02:00
events.nim minor improvements to the docs 2014-12-14 11:50:10 +01:00
fenv.nim Happy new year! 2015-01-06 15:26:33 +01:00
fsmonitor.nim updated fsmonitor 2014-09-17 23:13:58 +02:00
ftpclient.nim Happy new year! 2015-01-06 15:26:33 +01:00
future.nim Remove unnecessary check in list comprehensions 2015-01-10 22:54:39 +01:00
gentabs.nim make tests green 2014-08-31 15:15:26 +02:00
hashes.nim big rename 2014-08-27 23:42:51 +02:00
htmlgen.nim Happy new year! 2015-01-06 15:26:33 +01:00
htmlparser.nim make tests green 2014-08-31 15:15:26 +02:00
httpclient.nim Added documentation for the new http request procedures. 2015-01-23 22:06:57 -05:00
httpserver.nim Fix some deprecation warnings caused by renames 2014-11-13 21:34:46 +01:00
json.nim Add mitems and mpairs where it makes sense 2015-01-28 02:31:26 +01:00
lexbase.nim more modules updated 2014-08-28 01:41:41 +02:00
logging.nim Logging module is now thread-safe. 2015-01-25 17:02:37 +00:00
marshal.nim Happy new year! 2015-01-06 15:26:33 +01:00
matchers.nim Happy new year! 2015-01-06 15:26:33 +01:00
math.nim Happy new year! 2015-01-06 15:26:33 +01:00
md5.nim Translate md5 module to unsigned numbers 2015-01-03 14:21:26 +01:00
memfiles.nim Happy new year! 2015-01-06 15:26:33 +01:00
mersenne.nim big rename 2014-08-27 23:42:51 +02:00
mimetypes.nim big rename 2014-08-27 23:42:51 +02:00
net.nim fixes the integer conversion regressions 2015-01-13 20:56:31 +01:00
nimprof.nim more modules updated 2014-08-28 02:14:25 +02:00
nimprof.nimrod.cfg made some tests green; implemented 'from module import nil' 2013-05-19 23:17:16 +02:00
numeric.nim big rename 2014-08-27 23:42:51 +02:00
oids.nim Remove extra trailing zero from oid 2014-11-02 17:08:35 -05:00
os.nim nimsuggest: first version 2015-01-27 01:36:19 +01:00
osproc.nim FreeBSD-specific code 2015-01-29 12:51:22 +01:00
parsecfg.nim Nimrod renamed to Nim 2014-08-28 09:50:51 +02:00
parsecsv.nim more stdlib modules work 2014-08-31 15:25:54 +02:00
parseopt.nim Happy new year! 2015-01-06 15:26:33 +01:00
parseopt2.nim Happy new year! 2015-01-06 15:26:33 +01:00
parsesql.nim several modules changed 2014-08-28 02:21:49 +02:00
parseurl.nim Happy new year! 2015-01-06 15:26:33 +01:00
parseutils.nim fixes #2041 2015-01-31 11:49:19 +01:00
parsexml.nim updated xml modules 2014-09-18 09:59:11 +02:00
pegs.nim Get rid of deprecation warnings in pegs 2015-01-16 00:23:33 +01:00
pegs.nimfix Get rid of deprecation warnings in pegs 2015-01-16 00:23:33 +01:00
poly.nim Typo 2015-01-28 02:31:26 +01:00
rawsockets.nim Happy new year! 2015-01-06 15:26:33 +01:00
rawsockets.pretty.nim Happy new year! 2015-01-06 15:26:33 +01:00
redis.nim more stdlib modules work 2014-08-31 15:25:54 +02:00
romans.nim big rename 2014-08-27 23:42:51 +02:00
ropes.nim make tests green 2014-08-31 15:15:26 +02:00
scgi.nim Added warning to scgi module. 2014-12-26 16:37:32 +00:00
selectors.nim Handle EPOLLHUP to avoid chaos/runaways when using certain file descriptors. 2015-01-21 18:15:38 +03:00
smtp.nim Fix some deprecation warnings caused by renames 2014-11-13 21:34:46 +01:00
smtp.nimrod.cfg next steps for closure consistency; fixes #176 2012-07-25 21:59:31 +02:00
sockets.nim Emphasises deprecation warning in sockets module. 2014-12-26 16:26:28 +00:00
streams.nim fixes the integer conversion regressions 2015-01-13 20:56:31 +01:00
strtabs.nim more modules updated 2014-08-28 01:30:12 +02:00
strutils.nim fixes #2041 2015-01-31 11:49:19 +01:00
subexes.nim fixes #1730 2014-12-17 01:43:22 +01:00
terminal.nim Fix #1906 2015-01-22 18:34:33 -05:00
times.nim merged things from devel 2014-09-12 01:37:48 +02:00
typetraits.nim Nimrod renamed to Nim 2014-08-28 09:50:51 +02:00
unicode.nim Optimize unicode.reversed 2015-01-15 23:11:02 +01:00
unittest.nim Try to fix unittest for JS backend, still not working 2015-02-04 21:44:25 +01:00
uri.nim Happy new year! 2015-01-06 15:26:33 +01:00
xmldom.nim xmldom adheres to the new style 2014-09-17 23:12:54 +02:00
xmldomparser.nim updated xml modules 2014-09-18 09:59:11 +02:00
xmlparser.nim more tests green 2014-08-31 17:23:35 +02:00
xmltree.nim Add mitems and mpairs where it makes sense 2015-01-28 02:31:26 +01:00