Skip to content

Add ?size and ?random to Hashtbl.of_seq and related functions#2205

Closed
dra27 wants to merge 2 commits intoocaml:trunkfrom
dra27:hashtbl-of_seq
Closed

Add ?size and ?random to Hashtbl.of_seq and related functions#2205
dra27 wants to merge 2 commits intoocaml:trunkfrom
dra27:hashtbl-of_seq

Conversation

@dra27
Copy link
Copy Markdown
Member

@dra27 dra27 commented Dec 17, 2018

Split off from #2202 - note that the implementation of Hashtbl.MakeSeeded.of_seq is therefore wrong, but this would be corrected after #2202 is merged (if this GPR is accepted).

Add ?size to all hash table related of_seq functions, instead of
hard-coding 16.

All of_seq functions which wrap a create call which expose ?random now
themselves have ?random.
@dra27 dra27 added the stdlib label Dec 17, 2018
@dra27 dra27 mentioned this pull request Feb 6, 2019
@dra27 dra27 force-pushed the hashtbl-of_seq branch from 5c0461c to 61f3ce8 Compare May 4, 2020 13:13
@dra27
Copy link
Copy Markdown
Member Author

dra27 commented May 4, 2020

Ping @alainfrisch on this old one

@gasche
Copy link
Copy Markdown
Member

gasche commented May 4, 2020

See also #2236 which proposes to add an of_list with exactly the same question.

(Personally as I mentioned I think that the {add,replace}_{seq,list} are better building blocks and that we should de-emphasize of_* functions that force us to duplicate the API of the create all over the place. Unfortunately this tells nothing about what we should do with the existing of_* functions: leave them frozen in the errors of their ways, or bloat the API just for them?)

@dra27
Copy link
Copy Markdown
Member Author

dra27 commented Jul 31, 2020

I agree, @gasche. The problem with the approach I put here is that this breaks:

seq |> Hashtbl.of_seq

I think it's better to document that of_seq always uses a "default" interpretation of random Hashtbl of size 16 and note to use add_seq if more control is needed:

(* with this PR:
seq |> Hashtbl.of_seq ~size:32 ~random:true
*)
seq |> Hashtbl.add_seq (Hashtbl.create ~random:true 32)

I have one question before closing this. Given that #2236 is never going to land, should we:

  1. Just update the documentation for Hashtbl.of_seq as above
  2. Deprecate it in favour of always writing the version with add_seq?

@gasche
Copy link
Copy Markdown
Member

gasche commented Apr 18, 2021

There is a consensus against the change proposed in this PR, so closing.

I think it's better to document that of_seq always uses a "default" interpretation of random Hashtbl of size 16 and note to use add_seq if more control is needed

I agree. (I would document this, but not deprecate the function). Anyone, please feel free to open a PR with this documentation improvement.

@gasche gasche closed this Apr 18, 2021
@dra27 dra27 deleted the hashtbl-of_seq branch July 6, 2021 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants