Skip to content

Commit bf531bd

Browse files
committed
Better readme
1 parent fea3466 commit bf531bd

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

README.rst

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,69 @@
11
immutables
22
==========
33

4+
.. image:: https://travis-ci.org/MagicStack/immutables.svg?branch=master
5+
:target: https://travis-ci.org/MagicStack/immutables
6+
7+
.. image:: https://ci.appveyor.com/api/projects/status/tgbc6tq56u63qqhf?svg=true
8+
:target: https://ci.appveyor.com/project/MagicStack/immutables
9+
410
An immutable mapping type for Python.
511

612
The underlying datastructure is a Hash Array Mapped Trie (HAMT)
7-
used in Clojure and other functional languages. The actual
8-
implementation is used in CPython 3.7 (see PEP 567 and
9-
the contextvars module.)
13+
used in Clojure, Scala, Haskell, and other functional languages.
14+
This implementation is used in CPython 3.7 in the ``contextvars``
15+
module (see PEP 550 and PEP 567 for more details).
16+
17+
Immutable mappings based on HAMT have O(log\ :sub:`32`\ N)
18+
performance for both ``set()`` and ``get()`` operations, which is
19+
essentially O(1) for relatively small mappings.
20+
21+
Below is a visualization of a simple get/set benchmark comparing
22+
HAMT to an immutable mapping implemented with a Python dict
23+
copy-on-write approach (the benchmark code is available
24+
`here <https://gist.github.com/1st1/9004813d5576c96529527d44c5457dcd>`_):
25+
26+
.. image:: bench.png
27+
28+
29+
Installation
30+
------------
31+
32+
``immutables`` requires Python 3.5+ and is available on PyPI::
33+
34+
$ pip install immutables
35+
36+
37+
immutables.Map
38+
--------------
39+
40+
The ``Map`` object implements ``collections.abc.Mapping`` ABC
41+
so working with it is very similar to working with Python dicts.
42+
43+
The only exception is its ``Map.set()`` and ``Map.delete()`` methods
44+
which return a new instance of ``Map``:
45+
46+
.. code-block:: python
47+
48+
m1 = Map() # an empty Map
49+
m2 = m1.set('key1', 'val1') # m2 has a 'key1' key, m1 is still empty
50+
51+
m3 = m2.set('key2', 'val2')
52+
m3 = m3.delete('key1') # m3 has only a 'key2' key
53+
54+
55+
Further development
56+
-------------------
57+
58+
* An immutable version of Python ``set`` type with efficient
59+
``add()`` and ``discard()`` operations.
60+
61+
* Add support for efficient ``Map.update()`` operation, allow to
62+
pass a set of key/values to ``Map()``, and add support for
63+
pickling.
1064

1165

1266
License
13-
=======
67+
-------
1468

1569
Apache 2.0

bench.png

35.4 KB
Loading

0 commit comments

Comments
 (0)