Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New discussion about dicts with mutable keys #8685

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,17 @@ As with arrays, ``Dicts`` may be created with comprehensions. For example,

Given a dictionary ``D``, the syntax ``D[x]`` returns the value of key ``x`` (if it exists) or throws an error, and ``D[x] = y`` stores the key-value pair ``x => y`` in ``D`` (replacing any existing value for the key ``x``). Multiple arguments to ``D[...]`` are converted to tuples; for example, the syntax ``D[x,y]`` is equivalent to ``D[(x,y)]``, i.e. it refers to the value keyed by the tuple ``(x,y)``.

Keys for a ``Dict`` may be either mutable or immutable. In the case of mutable keys, the
user should not mutate a key once it is in a dictionary. For example, in the following snippet::

a = [1,2,3]
b = Dict(a=>0)
a[3] = -1

the indexing structure of ``b`` is left in a corrupted state by the reassignment of ``a[3].`` In case
a user of ``Dict`` is concerned about having accidentally clobbered a dictionary's index in this manner,
the ``checkcorrectness`` function described below can be helpful.

.. function:: Dict([itr])

``Dict{K,V}()`` constructs a hash table with keys of type K and values of type V.
Expand Down Expand Up @@ -1041,7 +1052,12 @@ Given a dictionary ``D``, the syntax ``D[x]`` returns the value of key ``x`` (if
.. function:: sizehint(s, n)

Suggest that collection ``s`` reserve capacity for at least ``n`` elements. This can improve performance.

.. function:: checkcorrectness(associative, io) -> Bool

Verify that keys in a ``Dict`` match hash values. Useful for debugging code
involving dictionaries with mutable keys. Not exported.

Fully implemented by: ``ObjectIdDict``, ``Dict``, ``WeakKeyDict``.

Partially implemented by: ``IntSet``, ``Set``, ``EnvHash``, ``Array``, ``BitArray``.
Expand Down