Commit graph

440 commits

Author SHA1 Message Date
Araq
10335fd726 fixed minor bugs; cleaned up tests 2015-02-12 14:56:56 +01:00
Charles Blake
49d88cee68 Oops - missed updates to a few later rawGet()s. 2015-02-12 06:44:09 -05:00
Charles Blake
5fbcf93860 Add hcode,rightSize,rawGetKnownHC. Fix inf loop.
Make similar changes to those made in sets.nim, including hcode, rightSize
rawGet/rawGetKnownHC result protocol, nextTry probe sequence to be the cache
friendlier h=h+1 which in turn allows supporting changing deletion to fix the
infinite loop bug with local rehashing which in turn has desirable properties
of graceful table aging when deletes do happen and also making insert-only
usage patterns no longer pay any time/space cost to check deleted status.

Unlike collections.sets, this module has add() for duplicate key inserts and
a 3rd type of table, CountTable.  The first wrinkle is handled by introducing
a rawGetDeep for unconditionally adding entries along collision chains.  This
point of CountTable seems to be space efficiency at 2 items per slot.  These
changes retain that by keeping the val==0 => EMPTY rule and not caching hash
codes.  putImpl is expanded in-place for CountTable since the new putImpl() is
too different. { Depending on table size relative to caches & key expense,
regular Table[A,B] may become faster than CountTable, especially if the basic
count update could be something like inc(mGetOrPut(t, key, 0)). }

Unit tests pass, but in this module those are much more of just a demo than
probing for bugs.  Should exercise/test this a little more before merging.
2015-02-12 05:22:04 -05:00
Charles Blake
1f3ce26421 Address Andreas' complaint about code duplication. 2015-02-07 13:13:03 -05:00
Charles Blake
42f8f1cd1f Fix unnecessarily slow set building from openArray.
The estimation of the initialSize as simply array len + 10 was too small for
for all but the smallest sets.  It would not elide/skip one final enlarge().
That last one is actually always the most expensive enlarge().  Indeed, in a
series where one to start from tiny and build up the table..that last one is
about 50% of all the enlarging time in general.  So, this simple and reasonable
optimization (compared to just starting at 64) was only helping about half as
much as it could.

Introduce a rightSize() proc to be the inverse to mustRehash().  Export it
to clients since pre-sizing is externally useful in set construction and the
current mustRehash rules are opaque and beyond the control of clients.

Also add test module logic to check that rightSize() and mustRehash() are
inverses in the appropriate sense..not really in a block/assertion throwing
unit test since this is a peformance nice-to-have issue rather than about
basic correctness.  (Also, fix a too vs. two typo in doc comment.)
2015-02-07 09:37:17 -05:00
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
Andreas Rumpf
f0cdb49c3b Merge pull request #2027 from dumndummer/patch-1
Update sequtils.nim
2015-02-04 10:38:50 +01:00
dumndummer
07f42fa612 Changed name 'pred' to 'op' in mapIt template 2015-02-02 14:42:00 +00:00
def
11a5a4a9a6 Fix SinglyLinkedRing in lists module
- SinglyLinkedRing's prepend was broken
- needed a tail so that prepend can work properly
- now append works as well, so I added it too
- simple testcase added as well
2015-02-01 03:04:18 +01:00
reactormonk
014be3a29c Merge pull request #2020 from def-/mitems
mitems and mpairs
2015-02-01 05:19:47 +05:00
Araq
fe30ec83e2 nimsuggest improvements 2015-01-30 03:04:45 +01:00
dumndummer
c19fb7b366 Update sequtils.nim
Renamed param name 'pred' to 'op' in mapIt template to better correspond with map proc in system module
2015-01-28 21:44:52 +00:00
Araq
dbe71c715e documented new C++ support 2015-01-28 12:59:04 +01:00
def
46cf40c40d Add mitems and mpairs where it makes sense 2015-01-28 02:31:26 +01:00
dumndummer
16254f49a8 Update sets.nim
corrected misspelled word in doc comment
2015-01-27 13:35:50 +00:00
Guillaume Gelin
3119fe087d Happy new year! 2015-01-06 15:26:33 +01:00
Araq
2990a9224b better CSS; better docs for teh tables module 2014-12-21 15:59:01 +01:00
Araq
7deb8b2e7b fixed typos so docgen works again 2014-12-20 22:39:05 +01:00
Araq
76c3b314dc implemented 'koch pdf' 2014-12-19 13:44:56 +01:00
Araq
280fa9624c fixes #1496 2014-12-18 14:54:26 +01:00
Araq
f7dca91344 fixes #619 2014-11-15 11:10:13 +01:00
def
f52fd8785f Fix some deprecation warnings caused by renames 2014-11-13 21:34:46 +01:00
Araq
595cc93762 recursive tuple types are now invalid (breaking change) 2014-10-02 16:54:05 +02:00
Araq
3ba34f1762 prettified re.nim; make some tests green 2014-08-31 13:46:27 +02:00
Araq
09ab1703e1 fixes #1444 2014-08-31 01:07:58 +02:00
Araq
4523b29d7a Nimrod renamed to Nim 2014-08-28 09:59:26 +02:00
Araq
42f5a838a3 more modules updated 2014-08-28 02:06:11 +02:00
Araq
fc5153e9b0 big rename 2014-08-28 00:37:15 +02:00
Araq
27869b6c7b big rename 2014-08-28 00:36:14 +02:00
Araq
df172806ea big rename 2014-08-28 00:24:52 +02:00
Araq
11b6958755 big rename 2014-08-27 23:42:51 +02:00
Araq
2f43fdb837 renamefest 2014-08-23 01:43:49 +02:00
Araq
abc8447331 fixes #1413 2014-08-13 02:34:08 +02:00
Andreas Rumpf
b1bfd51200 Merge pull request #1403 from def-/newseqwith
Add newSeqWith
2014-08-12 20:00:25 +02:00
def
61a6ecfd94 Move newSeqWith to sequtils 2014-08-11 21:05:21 +02:00
Grzegorz Adam Hankiewicz
e9417b55cf Adds definition of card term to sets module. 2014-07-27 09:42:49 +02:00
Grzegorz Adam Hankiewicz
48a13a76c8 Adds more docstrings to the sets module. 2014-07-27 00:14:55 +02:00
Grzegorz Adam Hankiewicz
0bfe956c05 Adds TSet.init(), wraps initSet around it. 2014-07-26 22:11:27 +02:00
Grzegorz Adam Hankiewicz
d21b682268 Adds TOrderedSet.init(), wraps initOrderedSet around it. 2014-07-26 22:11:27 +02:00
Grzegorz Adam Hankiewicz
6c3b967de3 Adds test cases for remaining TSet procs. 2014-07-26 22:11:26 +02:00
Grzegorz Adam Hankiewicz
dd47fa9037 Moves TSet procs to their code block. 2014-07-26 22:11:26 +02:00
Grzegorz Adam Hankiewicz
cdecac11c2 Adds TOrderedSet.isValid(). 2014-07-26 22:11:22 +02:00
Grzegorz Adam Hankiewicz
90e3c99bae Adds TSet.isValid(). 2014-07-26 22:11:17 +02:00
Clay Sweetser
18003ff196 Added stylistic consistancy. 2014-07-24 18:17:20 -04:00
Clay Sweetser
e5acd9d410 Merge branch 'ptables_fix' of git://github.com/flyx/Nimrod into flyx-ptables_fix 2014-07-24 18:13:14 -04:00
Araq
821fe72ff5 Merge branch 'devel' of https://github.com/Araq/Nimrod into devel 2014-07-22 20:23:28 +02:00
Araq
725cf0e22d '[]' for crit bit trees doesn't need the 'var' parameter 2014-07-22 20:23:19 +02:00
Andreas Rumpf
188df67677 Merge pull request #1377 from sjakobi/patch-1
sequtils: Correct documentation for keepIf proc
2014-07-19 12:49:31 +02:00
Simon Jakobi
78b56bf7dc sequtils: Complete mapIt documentation example 2014-07-19 00:09:47 +02:00
Simon Jakobi
4c4ebc93d7 sequtils: Correct documentation for keepIf proc 2014-07-18 23:51:17 +02:00