Commit Graph

159 Commits

Author SHA1 Message Date
Araq
a541be8935 prepare for upcoming parsing change of unary operators 2015-03-22 09:31:15 +01:00
Hans Raaf
b42c729da4 Making tuples anonymous (so far... not finished). 2015-03-17 00:15:23 +01:00
Hans Raaf
51034d7e3a Changed cast to type conversion and added XXX. 2015-03-07 17:51:03 +01:00
Hans Raaf
9e2f79251c Do we want we to use the typesystem like this? 2015-03-06 18:16:00 +01:00
Hans Raaf
534fe46b82 Added repeat(seq, n) to sequtils.
This adds a repeat proc for sequences. There is also an test for it at the end of file.
2015-03-06 18:16:00 +01:00
krolik
4fe0a72577 Fixed table getter not compiling when table value type had not '$' proc overriden 2015-03-05 14:43:15 +02:00
Hans Raaf
93aa73284e Fix unknown symbol in tables mpairs iterator.
Fixes an error with mpairs iterator which was introduced with 5fbcf93860. This is used by nimforum thats why I found it. I also added a testcase for the mpairs iterator.
2015-02-21 23:20:02 +01:00
Andreas Rumpf
358d4b958c Merge pull request #2139 from c-blake/devel
Add mgetOrPut to support just one probe chase for the common
2015-02-18 15:56:23 +01:00
Araq
9fe1aa6996 intsets.empty is wrong 2015-02-18 13:44:00 +01:00
Charles Blake
55840d9505 Merge ../Nim into devel 2015-02-16 14:55:08 -05:00
Charles Blake
629decd170 Add comments explaining odd looking i<0..data[i]. 2015-02-16 07:48:31 -05:00
Charles Blake
0a3e732b9f Just do wide interface of hasKeyOrPut & mgetOrPut.
Extract maybe re-hash/re-search and insert logic into a new template.
Use this new template to do impl templates for all three put forms
(which required renaming a couple 'value' arguments to 'val').
Added OrderedTable and OrderedTableRef versions of both as well.
2015-02-16 06:52:23 -05:00
Charles Blake
614a1f9d5a Add TableRef version of mgetOrPut. 2015-02-16 06:02:31 -05:00
Federico Ceratto
657dca5c3b Fix typos 2015-02-15 16:20:32 +00:00
Federico Ceratto
c95f6f117a Fix typos 2015-02-15 16:06:06 +00:00
Charles Blake
7c1c9a6a9d Add mgetOrPut to support just one probe chase for the common
pattern of either updating or initializing table entries.
2015-02-15 10:03:41 -05:00
Charles Blake
5068a5aa01 assignment -> shallowCopy for efficiency. 2015-02-13 14:10:09 -05:00
Charles Blake
45a2c1b1d1 Merge ../Nim into devel; track ttables.nim delete. 2015-02-13 08:42:41 -05:00
Charles Blake
d129e8f6c6 Update doc comments to mention rightSize. 2015-02-13 08:28:58 -05:00
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