Commit Graph

60 Commits (master)

Author SHA1 Message Date
Mehdi Bouaziz 6ab6052e15
[hashtbl] Restore ongoing traversal status after filter_map_inplace (#8746) 2020-10-12 15:12:09 +02:00
Nicolás Ojeda Bär a803cd4cc2
Merge pull request #9781 from yallop/injective-stdlib
Add some injectivity annotations to the standard library.
2020-07-20 19:40:50 +02:00
Xavier Leroy 40399cca5e Hashtbl: remove support for pre-4.00 hash tables
When the hash function and the internal representation of hash tables
was changed in 4.00, some compatibility code was left so that "old"
hash tables (created with OCaml < 4.00 and marshaled to files)
could still be operated upon by the functions of the new implementation.

This was 9 years ago, so it is reasonable to expect that none of these
"old" hash tables are still in use.

This commit removes the compatibility code in stdlib/hashtbl.ml.
It still tries to detect "old" hash tables and raise an
Invalid_argument exception instead of crashing.
2020-07-19 19:58:01 +02:00
Xavier Leroy a6f03cc10f Add Hashtbl.rebuild function
This provides an officially-sanctioned, guaranteed-to-work way to
import a hash table that has been built with an old version of OCaml
(say, before 4.00) and marshaled to persistent storage.
2020-07-19 19:38:25 +02:00
Jeremy Yallop 0aa72dd034 Add some injectivity annotations to the standard library. 2020-07-18 15:50:42 +01:00
David Allsopp 94c5cbfb8d Refactor stdlib/hashtbl.ml
No code changes - move the definitions to ensure that the functorial
interface doesn't accidentally rely on polymorphic hash function.
2019-07-19 13:17:52 +01:00
Alain Frisch 430c20bb78
A new runtime primitive for Array.fill (#8716) 2019-07-16 09:21:23 +02:00
David Allsopp 947486007e Fix Hashtbl.Make.of_seq creating randomized tables
Book-keeping error only - although it does potentially initialise the PRNG
unnecessarily.
2019-03-29 11:11:41 +01:00
David Allsopp fc8be501aa Fix Hashtbl.MakeSeeded.{add,replace,of}_seq
Hashtbl.MakeSeeded.{add,replace}_seq were not using the hash function
provided by the functor (Hashtbl.MakeSeeded.of_seq uses replace_seq and
so also has to be redefined locally).
2019-03-29 11:11:41 +01:00
Daniel Bünzli acb0e91ac6 Stdlib doc: harmonize heading levels again. (#2142) 2018-11-08 17:33:55 +01:00
Simon Cruanes df80f34a92 Stdlib functional iterators (#1002)
* add `Seq` module, expose iterator conversions in most containers

* small typo

* typo

* change order of arguments for `{Map,Set}.add_seq`

* watch for max string length in `Bytes.of_seq`

* wip: make it build again

* Fix dependency

Sys needs to be linked before Bytes in stdlib.

* Update threads/stdlib.ml

* Update stdlib_no_prefixed/.depend

* fix inconsistencies with label modules

* update testsuite to work with seq

* update change file

* small change in `Hashtbl.to_seq`, capturing only the underlying array

* add some documentation to seq.mli

* revert to good ol' module type names for hashtables

* fix test

* change style of comments in seq.mli

* follow some demands in review of GPR #1002

* some fixes for #1002

* add Seq-related functions to Ephemeron

* add some comments on `Hashtbl.of_seq`

* add more tests for `Hashtbl.{to,of}_seq`

* fix bug in `Ephemeron.to_seq`

* Update Changes
2018-03-16 18:25:10 +01:00
Alain Frisch 69263a9893 Option-returning variants of stdlib functions (#885)
Provide an xxx_opt alternative for functions raising Not_found
and many instances of Failure/Invalid_arg.

The only exception is the rarely used Buffer.add_substitute, where
the [Not_found] can really be interpreted as an error condition.

Most new functions are implemented directly (instead of wrapping the
raising version).  This is for performance reasons and also to avoid
destroying the stacktrace (if the function is used in an exception
handler).  One could instead implement the raising versions on top of
the new functions, but there might be a small penalty.
2016-11-07 16:11:35 +00:00
Damien Doligez 0b4fbc2b30 fix whitespace, long lines, headers 2016-08-01 16:06:59 +02:00
alainfrisch bff08d2763 Adapt filter_map_inplace. 2016-03-11 11:45:59 +01:00
alainfrisch 23b2edf286 Keep track of whether a traversal is ongoing and in this case, disables the inplace implementation of resizing. 2016-03-11 11:45:58 +01:00
alainfrisch 7394676c7d Optimize Hashtbl by using in-place updates of bucket list cells. 2016-03-11 11:45:57 +01:00
alainfrisch 6d36beb17a Switch to inline records to represent bucket lists in Hashtbl. 2016-03-11 11:45:16 +01:00
Alain Frisch af09eacaf2 Bug fix: Hashtbl.filter_map_inplace did not correctly update the size field. 2016-03-10 15:10:47 +01:00
Damien Doligez 5401ce8473 Update headers for the new license.
Remains to be done: remove all headers in testsuite/tests.
2016-02-18 16:59:16 +01:00
François Bobot 189d29bfcf [Stdlib] Hashtbl: add a getter for randomize 2016-01-23 11:28:01 +01:00
alainfrisch 7dce037bdf GPR#337: Hashtbl.filter_map_inplace. 2016-01-22 18:40:16 +01:00
alainfrisch 66e864a53f Use raise_notrace instead of raise to implement Hashtbl.replace.
This significantly improves the benchmark below:

  let ht = Hashtbl.create 100 in
  for x = 1 to 2500000 do
    Hashtbl.replace ht x ();
    Hashtbl.remove ht x
  done

(about 20% faster, still not as good as #328, which is about 35% faster
than trunk on this one)

In addition to the speedup, using raise_notrace should avoid destroying
the current stack trace when Hashtbl.replace is used in an exception
handler.
2015-12-04 08:57:16 +01:00
Jérémie Dimino 62b89a3a5c Replace uses of "noalloc" by [@@noalloc]
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@16455 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2015-10-06 10:58:22 +00:00
Damien Doligez c63f9e0957 fix a few problems with whitespace and over-long lines
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13393 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-03-09 22:38:52 +00:00
Damien Doligez def31744f9 remove all $Id keywords
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13013 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2012-10-15 17:50:56 +00:00
Damien Doligez 8a216cd3bb fix two bugs in commit 12453
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12476 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2012-05-24 15:12:37 +00:00
Fabrice Le Fessant 621dd2dd5f Fix PR#5555
Add Hashtbl.reset to resize the bucket table to its initial size.



git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12451 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2012-05-15 08:36:25 +00:00
Xavier Leroy b2166e33f5 - Hashtbl:
. Added optional "random" parameter to Hashtbl.create to randomize
      collision patterns and improve security (PR#5572, CVE-2012-0839)
    . Added "randomize" function and "R" parameter to OCAMLRUNPARAM
      to turn randomization on by default (PR#5572, CVE-2012-0839)
- Filename: on-demand (lazy) initialization of the PRNG used by "temp_file".



git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12384 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2012-04-19 13:17:40 +00:00
Xavier Leroy bd3e65ea7a PR#5349: "replace" uses new key instead of reusing old key.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11205 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2011-09-18 09:40:21 +00:00
Xavier Leroy 8e33ab4f2d Improve backward compatibility for Hashtbl functorial interface:
Hashtbl.Make returns a "create" function without an optional seed parameter.
(Which would be ignored anyway.)
Hashtbl.MakeSeeded returns a "create" function with an optional seed parameter.


git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11204 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2011-09-18 09:35:27 +00:00
Damien Doligez 3b507dd1aa renaming of Objective Caml to OCaml and cleanup of copyright headers
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11156 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2011-07-27 14:17:02 +00:00
Xavier Leroy e6d76ed5b1 Hashtbl again: simplified interface for seeding; seed is now an optional parameter of the "create" function, and it is the user's responsibility to generate a random seed if desired.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11063 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2011-06-04 08:08:40 +00:00
Xavier Leroy aea227fdeb Better hashing!
- New generic hash function based on Murmur 3, with better statistical
  properties (PR#5225), and better speed
- Make sure equal floats hash equally (PR#5222)
- Breadth-first traversal instead of depth-first
- Added seeded hash functions and seeded functorial interface to Hashtbl.


git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11056 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2011-05-29 09:52:27 +00:00
Damien Doligez 0e5ca9dca5 nettoyage
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@7164 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2005-10-25 18:34:07 +00:00
Basile Starynkevitch 2c8fe3ae6b added length function.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@6167 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2004-03-23 12:37:19 +00:00
Damien Doligez 0c7aecb88d depollution suite (et fin?) (PR#1914 et PR#1956)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@6047 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2004-01-02 19:23:29 +00:00
Xavier Leroy f009490d09 Utiliser compare x y = 0 au lieu de x = y lorsqu'on compare des cles qui peuvent etre le flottant nan
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5962 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2003-11-21 16:04:26 +00:00
Damien Doligez 1915402f26 elargissement de la spec de la fonction de hash
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@4305 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2002-01-23 17:52:46 +00:00
Xavier Leroy 7501784c80 MAJ en-tetes pour mentionner la 'special exception' sur la LGPL
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@4144 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2001-12-07 13:41:02 +00:00
Xavier Leroy d3db3052c3 Bug dans l'interface fonctorielle pour add et resize
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@4021 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2001-11-19 15:37:19 +00:00
Xavier Leroy 1a1d67bb95 Revu strategie de redimensionnement des hashtables; ajout Hashtbl.copy.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3919 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2001-10-25 11:32:36 +00:00
Jacques Garrigue ea299bbbc1 passage aux labels stricts
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3696 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2001-09-06 08:52:32 +00:00
Xavier Leroy 371e5b9cde Ajout de Hashtbl.fold (PR#195)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3544 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2001-06-25 08:33:25 +00:00
Xavier Leroy d48c6cfaea Ajout de Hashtbl.replace. Pas d'allocation dans Hashtbl.find
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3262 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2000-07-28 12:24:25 +00:00
Xavier Leroy e508598e0f Meilleur comportement de resize quand on s'approche de max_array_length
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2880 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2000-02-29 13:06:40 +00:00
Damien Doligez a9127cb36f unicite de la fonction de hash
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2627 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1999-11-29 19:04:12 +00:00
Jérôme Vouillon 764f2c83c3 Bug in the function "mem" of the functorial interface
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2601 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1999-11-25 22:39:23 +00:00
Xavier Leroy cc0f32b054 Changement de la licence
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2553 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1999-11-17 18:59:06 +00:00
Damien Doligez 10270afb11 array.mli: documentation des cas d'erreur de make, make_matrix
string.mli: documentation des cas d'erreur de create, make
buffer.ml, buffer.mli: blindage de create
hashtbl.ml, hashtbl.mli: blindage de create
pervasives.ml: fix typo dans bool_of_string
gc.mli: utilisation de {r with l=v} dans l'exemple


git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2411 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1999-10-02 12:09:43 +00:00
Pierre Weis 36dea1c565 Added Hashtbl.mem to test if a given key is bound into the table.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2271 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1999-02-11 09:46:14 +00:00