summary refs log tree commit diff stats
path: root/lib/pure/hashes.nim
Commit message (Collapse)AuthorAgeFilesLines
* Alternate to https://github.com/nim-lang/Nim/pull/15915 (#15937)c-blake2020-11-131-2/+7
| | | | | | | | * Alternate PR to https://github.com/nim-lang/Nim/pull/15915 to resolve the problem mentioned there (`hash() == 0`) as well as to close https://github.com/nim-lang/Nim/issues/15624 * Address https://github.com/nim-lang/Nim/pull/15937#discussion_r522759669 { though this was only a move from 2 copies to 3 copies. ;-) }
* Fix #14394 (#14395)Clyybber2020-05-181-1/+1
|
* move since from inclrtl to std/private/since (#14188)hlaaftana2020-05-021-1/+1
| | | | * move since from inclrtl to std/private/since * move since import in system below for HCR
* bug fix (#14149) [backport:1.2]cooldome2020-04-281-1/+4
| | | Co-authored-by: cooldome <ariabushenko@bk.ru>
* fixes #12834 (#14017)Andreas Rumpf2020-04-191-3/+3
|
* added a .since annotation to hashIdentityAndreas Rumpf2020-04-151-2/+4
|
* Add `hashWangYi1` (#13823)c-blake2020-04-151-2/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Unwind just the "pseudorandom probing" (whole hash-code-keyed variable stride double hashing) part of recent sets & tables changes (which has still been causing bugs over a month later (e.g., two days ago https://github.com/nim-lang/Nim/issues/13794) as well as still having several "figure this out" implementation question comments in them (see just diffs of this PR). This topic has been discussed in many places: https://github.com/nim-lang/Nim/issues/13393 https://github.com/nim-lang/Nim/pull/13418 https://github.com/nim-lang/Nim/pull/13440 https://github.com/nim-lang/Nim/issues/13794 Alternative/non-mandatory stronger integer hashes (or vice-versa opt-in identity hashes) are a better solution that is more general (no illusion of one hard-coded sequence solving all problems) while retaining the virtues of linear probing such as cache obliviousness and age-less tables under delete-heavy workloads (still untested after a month of this change). The only real solution for truly adversarial keys is a hash keyed off of data unobservable to attackers. That all fits better with a few families of user-pluggable/define-switchable hashes which can be provided in a separate PR more about `hashes.nim`. This PR carefully preserves the better (but still hard coded!) probing of the `intsets` and other recent fixes like `move` annotations, hash order invariant tests, `intsets.missingOrExcl` fixing, and the move of `rightSize` into `hashcommon.nim`. * Fix `data.len` -> `dataLen` problem. * This is an alternate resolution to https://github.com/nim-lang/Nim/issues/13393 (which arguably could be resolved outside the stdlib). Add version1 of Wang Yi's hash specialized to 8 byte integers. This gives simple help to users having trouble with overly colliding hash(key)s. I.e., A) `import hashes; proc hash(x: myInt): Hash = hashWangYi1(int(x))` in the instantiation context of a `HashSet` or `Table` or B) more globally, compile with `nim c -d:hashWangYi1`. No hash can be all things to all use cases, but this one is A) vetted to scramble well by the SMHasher test suite (a necessarily limited but far more thorough test than prior proposals here), B) only a few ALU ops on many common CPUs, and C) possesses an easy via "grade school multi-digit multiplication" fall back for weaker deployment contexts. Some people might want to stampede ahead unbridled, but my view is that a good plan is to A) include this in the stdlib for a release or three to let people try it on various key sets nim-core could realistically never access/test (maybe mentioning it in the changelog so people actually try it out), B) have them report problems (if any), C) if all seems good, make the stdlib more novice friendly by adding `hashIdentity(x)=x` and changing the default `hash() = hashWangYi1` with some `when defined` rearranging so users can `-d:hashIdentity` if they want the old behavior back. This plan is compatible with any number of competing integer hashes if people want to add them. I would strongly recommend they all *at least* pass the SMHasher suite since the idea here is to become more friendly to novices who do not generally understand hashing failure modes. * Re-organize to work around `when nimvm` limitations; Add some tests; Add a changelog.md entry. * Add less than 64-bit CPU when fork. * Fix decl instead of call typo. * First attempt at fixing range error on 32-bit platforms; Still do the arithmetic in doubled up 64-bit, but truncate the hash to the lower 32-bits, but then still return `uint64` to be the same. So, type correct but truncated hash value. Update `thashes.nim` as well. * A second try at making 32-bit mode CI work. * Use a more systematic identifier convention than Wang Yi's code. * Fix test that was wrong for as long as `toHashSet` used `rightSize` (a very long time, I think). `$a`/`$b` depend on iteration order which varies with table range reduced hash order which varies with range for some `hash()`. With 3 elements, 3!=6 is small and we've just gotten lucky with past experimental `hash()` changes. An alternate fix here would be to not stringify but use the HashSet operators, but it is not clear that doesn't alter the "spirit" of the test. * Fix another stringified test depending upon hash order. * Oops - revert the string-keyed test. * Fix another stringify test depending on hash order. * Add a better than always zero `defined(js)` branch. * It turns out to be easy to just work all in `BigInt` inside JS and thus guarantee the same low order bits of output hashes (for `isSafeInteger` input numbers). Since `hashWangYi1` output bits are equally random in all their bits, this means that tables will be safely scrambled for table sizes up to 2**32 or 4 gigaentries which is probably fine, as long as the integer keys are all < 2**53 (also likely fine). (I'm unsure why the infidelity with C/C++ back ends cut off is 32, not 53 bits.) Since HashSet & Table only use the low order bits, a quick corollary of this is that `$` on most int-keyed sets/tables will be the same in all the various back ends which seems a nice-to-have trait. * These string hash tests fail for me locally. Maybe this is what causes the CI hang for testament pcat collections? * Oops. That failure was from me manually patching string hash in hashes. Revert. * Import more test improvements from https://github.com/nim-lang/Nim/pull/13410 * Fix bug where I swapped order when reverting the test. Ack. * Oh, just accept either order like more and more hash tests. * Iterate in the same order. * `return` inside `emit` made us skip `popFrame` causing weird troubles. * Oops - do Windows branch also. * `nimV1hash` -> multiply-mnemonic, type-scoped `nimIntHash1` (mnemonic resolutions are "1 == identity", 1 for Nim Version 1, 1 for first/simplest/fastest in a series of possibilities. Should be very easy to remember.) * Re-organize `when nimvm` logic to be a strict `when`-`else`. * Merge other changes. * Lift constants to a common area. * Fall back to identity hash when `BigInt` is unavailable. * Increase timeout slightly (probably just real-time perturbation of CI system performance).
* fix #12508, unaligned access on sparc64 (#13594)Miran2020-03-091-1/+1
|
* cleanup Ordinal (#13501)Timothee Cour2020-02-271-1/+1
|
* [backport] pseudorandom probing for hash collision (#13418)Timothee Cour2020-02-191-28/+4
|
* style fix: change 'JS' to 'js' to make it consistent (#13168)Miran2020-01-161-2/+2
|
* fixes #11764, faster hashing of (u)int (#12407)Miran2019-10-151-6/+9
|
* [backport] run nimpretty on hashesnarimiran2019-09-301-4/+4
|
* hashes: implement murmur3 (#12022)Miran2019-09-011-47/+149
| | | | | | | | * hashes: implement murmur3 * refactoring; there is only one murmurHash and it works at compile-time via VM hooks * fixes JS tests * makes toOpenArrayByte work with C++ * make it bootstrap in C++ mode for 0.20
* int128 on firstOrd, lastOrd and lengthOrd (#11701)Arne Döring2019-08-071-2/+2
| | | | * fixes #11847
* [refactoring] remove unused imports in the compiler and in some stdlib modulesAraq2019-07-181-4/+0
|
* styleCheck: make the compiler and large parts of the stdlib compatible with ↵Araq2019-07-101-1/+1
| | | | --styleCheck:error
* [bugfix] hashes: fix regression for nested containers (#11426)Miran2019-06-081-6/+6
| | | Move forward declarations earlier.
* right shift is now by default sign preserving (#11322)Arne Döring2019-05-291-7/+12
| | | | | | | | | | | * right shift is now by default sign preserving * fix hashString and semfold * enable arithmetic shift right globally for CI * fix typo * remove xxx * use oldShiftRight as flag * apply feedback * add changelog entry
* hashes: quickfix one testnarimiran2019-05-271-1/+1
|
* fix spelling [ci skip] (#11307)Andy Davidoff2019-05-221-1/+1
|
* faster hashing (#11203)Miran2019-05-211-41/+94
| | | | | | | | | | | | | | | | | | | * faster hashing * multibyte hashing for: * string and string slices * cstring * string, ignoring case * string, ignoring style * openArray of byte or char * address the review comments * use optimized version for all ints * add more tests * make it work in VM * put warnings about differences between CT and runtime * minor style tweaks
* hashes: fix inconsistent tests, fixes #10771narimiran2019-03-031-4/+3
|
* improved documentation for several modules (#10752)Miran2019-03-011-40/+91
| | | | | | | | | | | | More detailed documentation for: * md5 * hashes Mostly cosmetic improvements for: * threadpool * typetraits * channels * threads
* remove deprecated stuff from the stdlib; introduce better deprecation warningsAraq2018-05-051-1/+0
|
* fixes #5969Araq2017-06-091-3/+8
|
* remove en-dash from the languageAndreas Rumpf2017-04-021-5/+1
|
* added hash for uints (#5435)Fabian Keller2017-02-261-0/+8
|
* Add hash proc for cstrings (#5386)Ruslan Mustakov2017-02-131-0/+10
|
* added hash procs for handling portions of strings/arrays/seqs.JamesP2015-10-071-4/+70
| | | | | | | | | added tests at bottom of file changed some doco layout Makes hashing iteratively through buffers faster when you don't have to pass copied portions of the buffer to the hash function
* Added commaapense2015-07-061-1/+1
| | | "e.g." and "i.e." both usually take commas after, as they would in normal English ("for example, ..." and "that is, ..." respectively)
* THash -> Hash correctionapense2015-07-061-1/+1
|
* added hash function for ordinal typesFabian Keller2015-07-031-0/+4
|
* lib/pure/e-o - Dropped 'T' from typespdw2015-06-041-30/+31
|
* Restructure branching slighty. Fix error message.Oscar Campbell2015-06-011-7/+6
|
* Implement #2811 - Unicode en-dash (U+2013) as hump/snake alt.Oscar Campbell2015-05-311-2/+10
|
* Fix floats in tuples in HashSetsNycto2015-04-241-29/+37
| | | | | Previously, the added tests would fail to compile with errors complaining that 'hash(float)' didn't exist
* Changed some characters (&! -> !&) in the documentation in lib/pure/hashes.nimJohanna Berewinkel2015-03-051-2/+2
|
* big renameAraq2014-08-271-4/+4
|
* Adds brief intro to hashes module.Grzegorz Adam Hankiewicz2014-06-061-1/+28
|
* added 'hash' for set[T]'Andreas Rumpf2014-04-131-0/+4
|
* case consistency: cs:partial bootstraps on windowsAraq2013-12-291-3/+3
|
* case consistency part 4Araq2013-12-271-6/+6
|
* Change varargs[T] to openarray[T]Billingsly Wetherfordshire2013-05-041-1/+1
|
* Change hash[T](seq[A]) to take varargs[A]Billingsly Wetherfordshire2013-05-041-1/+1
|
* add hashing for seqsBillingsly Wetherfordshire2013-05-041-0/+3
|
* Removes executable bit for text files.Grzegorz Adam Hankiewicz2013-03-161-0/+0
|
* EcmaScript => JS. Fixes #330Simon Hafner2013-02-151-3/+3
| | | | No one calls it EcmaScript anymore.
* hash() for floatsSimon Hafner2012-09-081-0/+4
|
* attempt to fix DLL generationAraq2012-07-181-6/+7
|