Commit graph

46 commits

Author SHA1 Message Date
pdw
192ba3bbc0 lib/pure/a-c - Dropped 'T' from types 2015-06-04 13:17:11 +02:00
Oleh Prypin
32109a7867 Don't run non-test code when defined(testing) 2015-04-21 14:37:29 +03:00
def
22b4e4c2f2 Use more Natural and Positive numbers in proc parameters
- Didn't go through all modules, only the main ones I thought of
- Building the compiler and tests still work
2015-04-06 02:24:17 +02:00
ReneSac
e41a3e9661 Fix warning about sets.testModule() not used. 2015-04-04 15:28:38 -03:00
Charles Blake
5068a5aa01 assignment -> shallowCopy for efficiency. 2015-02-13 14:10:09 -05:00
Charles Blake
d129e8f6c6 Update doc comments to mention rightSize. 2015-02-13 08:28:58 -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
Araq
dbe71c715e documented new C++ support 2015-01-28 12:59:04 +01:00
dumndummer
16254f49a8 Update sets.nim
corrected misspelled word in doc comment
2015-01-27 13:35:50 +00:00
Araq
09ab1703e1 fixes #1444 2014-08-31 01:07:58 +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
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
def
68c3c8ebfa More effificent TSet difference 2014-07-14 17:56:19 +02:00
def
5bfea58ffb Add missing difference and to sets module 2014-07-14 15:03:09 +02:00
Felix Krause
ac3f872fa3 Fixed TSet proc names to conform with set 2014-06-26 20:55:46 +02:00
Felix Krause
84643abd3e Fixed doc comments in sets.nim 2014-06-26 20:55:46 +02:00
Felix Krause
bdd3b6c612 Added logical set operations to TSet 2014-06-25 22:07:28 +02:00
Andreas Rumpf
455c3c19ca added mget for TSet 2014-04-13 00:33:06 +02:00
Simon Hafner
e8c87d070a fixed a bug in map for sets 2014-02-10 13:02:47 -06:00
Simon Hafner
0b5c14962e added map to sets 2014-02-10 12:44:44 -06:00
Simon Hafner
9f29bb8d9e corrected docs and tests 2014-02-01 16:07:44 -06:00
Simon Hafner
2c5a2d07fb sets equivalence 2014-01-31 18:22:27 -06:00
Araq
7e0da3e8f7 case consistency part 7 2013-12-28 01:36:35 +01:00
Grzegorz Adam Hankiewicz
72a3e21f28 Removes executable bit for text files. 2013-03-16 23:53:07 +01:00
Araq
a59abdf8e4 made more tests green; fixes #201 2012-09-12 21:48:37 +02:00
Araq
f893179889 documented hygienic templates; made tests green; fixed system.clamp 2012-08-22 22:46:02 +02:00
Araq
05a66a6a68 bugfix: collection/sets only worked by chance ... 2012-07-25 23:18:47 +02:00
Araq
4f1b89c30c year 2012 for most copyright headers 2012-01-02 23:07:35 +01:00
Araq
7000cf51b7 modifyable results for generics; teventemitter works 2011-08-09 01:40:12 +02:00
Araq
5b96eaa953 preparations for 0.8.12 2011-07-10 15:48:13 +02:00
Araq
ec2bd53ead implemented tables.add 2011-06-11 17:03:45 +02:00
Araq
3bc821aa5c basic generic collections implemented and tested 2011-06-07 03:37:36 +02:00