2015-12-21 03:05:20 +00:00
|
|
|
Addendum
|
|
|
|
========
|
|
|
|
|
2016-06-28 04:05:22 +00:00
|
|
|
.. include:: performance.rst.inc
|
|
|
|
|
2017-12-17 18:58:57 +00:00
|
|
|
.. include:: inv-avoids-reference-cycles.rst.inc
|
|
|
|
|
2015-12-21 03:05:20 +00:00
|
|
|
Terminology
|
|
|
|
-----------
|
|
|
|
|
|
|
|
- It's intentional that the term "inverse" is used rather than "reverse".
|
|
|
|
|
|
|
|
Consider a collection of *(k, v)* pairs.
|
|
|
|
Taking the reverse of the collection can only be done if it is ordered,
|
|
|
|
and (as you'd expect) reverses the order of the pairs in the collection.
|
|
|
|
But each original *(k, v)* pair remains in the resulting collection.
|
|
|
|
|
|
|
|
By contrast, taking the inverse of such a collection
|
|
|
|
neither requires the collection to be ordered
|
|
|
|
nor guarantees any ordering in the result,
|
|
|
|
but rather just replaces every *(k, v)* pair
|
|
|
|
with the inverse pair *(v, k)*.
|
|
|
|
|
|
|
|
- "keys" and "values" could perhaps more properly be called
|
|
|
|
"primary keys" and "secondary keys" (as in a database),
|
|
|
|
or even "forward keys" and "inverse keys", respectively.
|
|
|
|
bidict sticks with the terms "keys" and "values"
|
|
|
|
for the sake of familiarity and to avoid potential confusion,
|
|
|
|
but technically values are also keys themselves.
|
|
|
|
|
|
|
|
Concretely, this allows bidict to return a set-like (*dict_keys*) object
|
squashed changes for 0.13.0
- support Python 3.6, refactor CI/test setup, increase test coverage
- refactor BidirectionalMapping, BidictBase, OrderedBidictBase,
FrozenBidictBase, and subclasses
- move frozenorderedbidict into _frozen and looseorderedbidict into _loose
- register bidict as a virtual subclass of MutableMapping rather than
inheriting from it directly. This makes it clearer that it does not use any
of the concrete generic methods that MutableMapping provides.
- improve performance and flexibility of frozenbidict and
frozenorderedbidict hashing
- docs, including new type-hierarchy.png diagram
- rm unused imap, ifilter, izip_longest from compat, add PYPY
- update to latest versions of dependencies
- restore benchmarking on travis
2017-01-09 15:37:31 +00:00
|
|
|
for :func:`bidict.values <bidict.BidictBase.values>` (Python 3) /
|
2016-06-28 04:05:22 +00:00
|
|
|
``bidict.viewvalues()``
|
2015-12-21 03:05:20 +00:00
|
|
|
(Python 2.7), rather than a non-set-like *dict_values* object.
|
2015-03-22 18:21:15 +00:00
|
|
|
|
|
|
|
|
2015-04-30 18:49:30 +00:00
|
|
|
Missing bidicts in Stdlib!
|
|
|
|
--------------------------
|
2015-03-22 18:21:15 +00:00
|
|
|
|
|
|
|
The Python standard library actually contains some examples
|
|
|
|
where bidicts could be used for fun and profit
|
|
|
|
(depending on your ideas of fun and profit):
|
|
|
|
|
|
|
|
- The :mod:`logging` module
|
2016-06-28 04:05:22 +00:00
|
|
|
contains a private ``_levelToName`` dict
|
2015-12-21 03:05:20 +00:00
|
|
|
which maps integer levels like *10* to their string names like *DEBUG*.
|
2015-03-22 18:21:15 +00:00
|
|
|
If I had a nickel for every time I wanted that exposed in a bidirectional map
|
2017-10-11 14:26:20 +00:00
|
|
|
(and as a public attribute, no less),
|
2015-03-22 18:21:15 +00:00
|
|
|
I bet I could afford some better turns of phrase.
|
|
|
|
|
2015-04-30 18:49:30 +00:00
|
|
|
- The :mod:`dis` module
|
|
|
|
maintains a mapping from opnames to opcodes
|
2016-06-28 04:05:22 +00:00
|
|
|
``dis.opmap``
|
2015-04-30 18:49:30 +00:00
|
|
|
and a separate list of opnames indexed by opcode
|
2016-06-28 04:05:22 +00:00
|
|
|
``dis.opnames``.
|
2015-04-30 18:49:30 +00:00
|
|
|
These could be combined into a single bidict.
|
|
|
|
|
2015-03-22 18:21:15 +00:00
|
|
|
- Python 3's
|
|
|
|
:mod:`html.entities` module /
|
|
|
|
Python 2's
|
2016-06-28 04:05:22 +00:00
|
|
|
``htmlentitydefs`` module
|
2015-04-30 18:49:30 +00:00
|
|
|
maintains separate
|
2016-06-28 04:05:22 +00:00
|
|
|
``html.entities.name2codepoint`` and
|
|
|
|
``html.entities.codepoint2name`` dicts.
|
2015-04-30 18:49:30 +00:00
|
|
|
These could be combined into a single bidict.
|
2015-03-22 18:21:15 +00:00
|
|
|
|
|
|
|
|
2015-12-21 03:05:20 +00:00
|
|
|
Caveats
|
|
|
|
-------
|
2015-03-22 18:21:15 +00:00
|
|
|
|
2016-06-28 04:05:22 +00:00
|
|
|
.. include:: caveat-mutation.rst.inc
|
2015-03-22 18:21:15 +00:00
|
|
|
|
squashed changes for 0.13.0
- support Python 3.6, refactor CI/test setup, increase test coverage
- refactor BidirectionalMapping, BidictBase, OrderedBidictBase,
FrozenBidictBase, and subclasses
- move frozenorderedbidict into _frozen and looseorderedbidict into _loose
- register bidict as a virtual subclass of MutableMapping rather than
inheriting from it directly. This makes it clearer that it does not use any
of the concrete generic methods that MutableMapping provides.
- improve performance and flexibility of frozenbidict and
frozenorderedbidict hashing
- docs, including new type-hierarchy.png diagram
- rm unused imap, ifilter, izip_longest from compat, add PYPY
- update to latest versions of dependencies
- restore benchmarking on travis
2017-01-09 15:37:31 +00:00
|
|
|
.. include:: caveat-equivalence-vs-identity.rst.inc
|
2015-03-22 18:21:15 +00:00
|
|
|
|
2016-06-28 04:05:22 +00:00
|
|
|
.. include:: caveat-nan-as-key.rst.inc
|
2015-12-21 03:05:20 +00:00
|
|
|
|
|
|
|
Thanks
|
|
|
|
------
|
|
|
|
|
|
|
|
.. include:: thanks.rst.inc
|