Skip to content

Commit acbb13b

Browse files
committed
Update README
1 parent 1ee43ef commit acbb13b

File tree

1 file changed

+68
-46
lines changed

1 file changed

+68
-46
lines changed

README.rst

Lines changed: 68 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Python Sorted Containers
44
.. todo::
55

66
* Update history and document v3 milestone
7-
* Update landing page
7+
* Review implementation page
8+
* Review development page
89
* Re-run performance benchmarks
910
* Rename github repo
1011
* Tell Doug Hellmann about Sorted Containers and relation to bisect module
@@ -14,32 +15,44 @@ written in pure-Python, and fast as C-extensions.
1415

1516
Python's standard library is great until you need a sorted collections
1617
type. Many will attest that you can get really far without one, but the moment
17-
you **really need** a sorted list, dict, or set, you're faced with a dozen
18-
different implementations, most using C-extensions without great documentation
19-
and benchmarking.
18+
you **really need** a sorted list, sorted dict, or sorted set, you're faced
19+
with a dozen different implementations, most using C-extensions without great
20+
documentation and benchmarking.
2021

2122
In Python, we can do better. And we can do it in pure-Python!
2223

2324
.. code-block:: python
2425
25-
>>> sl = sortedcontainers.SortedList(xrange(10000000))
26-
>>> 1234567 in sl
27-
True
28-
>>> sl[7654321]
29-
7654321
30-
>>> sl.add(1234567)
31-
>>> sl.count(1234567)
26+
>>> from sortedcontainers import SortedList
27+
>>> sl = SortedList(['e', 'a', 'c', 'd', 'b'])
28+
>>> sl
29+
SortedList(['a', 'b', 'c', 'd', 'e'])
30+
>>> sl *= 10_000_000
31+
>>> sl.count('c')
32+
10000000
33+
>>> sl[-3:]
34+
['e', 'e', 'e']
35+
>>> from sortedcontainers import SortedDict
36+
>>> sd = SortedDict({'c': 3, 'a': 1, 'b': 2})
37+
>>> sd
38+
SortedDict({'a': 1, 'b': 2, 'c': 3})
39+
>>> sd.popitem(index=-1)
40+
('c', 3)
41+
>>> from sortedcontainers import SortedSet
42+
>>> ss = SortedSet('abracadabra')
43+
>>> ss
44+
SortedSet(['a', 'b', 'c', 'd', 'r'])
45+
>>> ss.bisect_left('c')
3246
2
33-
>>> sl *= 3
34-
>>> len(sl)
35-
30000003
3647
37-
**Note:** don't try this without at least a half gigabyte of memory. In Python
38-
an integer requires about 24 bytes. SortedList will add about 8 bytes per
39-
object stored in the container. That's pretty hard to beat as it's the cost of
40-
a pointer to each object. It's also 66% less overhead than a typical binary
41-
tree implementation (e.g. red-black tree, avl tree, aa tree, splay tree, treap,
42-
etc.) for which every node must also store two pointers to children nodes.
48+
All of the operations shown above run in faster than linear time. The above
49+
demo also take nearly a gigabyte of memory to run. When the sorted list is
50+
multiplied by ten million, it stores ten million references to each of "a"
51+
through "e". Each reference requires eight bytes in the sorted
52+
container. That's pretty hard to beat as it's the cost of a pointer to each
53+
object. It's also 66% less overhead than a typical binary tree implementation
54+
(e.g. Red-Black Tree, AVL-Tree, AA-Tree, Splay-Tree, Treap, etc.) for which
55+
every node must also store two pointers to children nodes.
4356

4457
`Sorted Containers`_ takes all of the work out of Python sorted collections -
4558
making your deployment and use of Python easy. There's no need to install a C
@@ -52,41 +65,48 @@ feature and testing has 100% coverage with unit tests and hours of stress.
5265
Testimonials
5366
------------
5467

55-
**Alex Martelli**, `Wikipedia`_
68+
**Alex Martelli**, `Fellow of the Python Software Foundation`_ --
5669

57-
Good stuff! ... I like the `simple, effective implementation`_ idea of splitting
58-
the sorted containers into smaller "fragments" to avoid the O(N) insertion costs.
70+
"Good stuff! ... I like the `simple, effective implementation`_ idea of
71+
splitting the sorted containers into smaller "fragments" to avoid the O(N)
72+
insertion costs."
5973

60-
.. _`Wikipedia`: http://en.wikipedia.org/wiki/Alex_Martelli
61-
.. _`simple, effective implementation`: http://www.grantjenks.com/docs/sortedcontainers/implementation.html
62-
63-
**Jeff Knupp**, `Review of Sorted Containers`_
74+
**Jeff Knupp**, `author of Writing Idiomatic Python and Python Trainer`_ --
6475

65-
That last part, "fast as C-extensions," was difficult to believe. I would need
76+
"That last part, "fast as C-extensions," was difficult to believe. I would need
6677
some sort of `Performance Comparison`_ to be convinced this is true. The author
67-
includes this in the docs. It is.
68-
69-
.. _`Review of Sorted Containers`: http://reviews.jeffknupp.com/reviews/sortedcontainers/3/
78+
includes this in the docs. It is."
7079

71-
**Kevin Samuel**, `Formations Python`_
80+
**Kevin Samuel**, `Python and Django Trainer`_ --
7281

73-
I'm quite amazed, not just by the code quality (it's incredibly
74-
readable and has more comment than code, wow), but the actual
75-
amount of work you put at stuff that is *not* code:
76-
documentation, benchmarking, implementation explanations. Even
77-
the git log is clean and the unit tests run out of the box on
78-
Python 2 and 3.
82+
I'm quite amazed, not just by the code quality (it's incredibly readable and
83+
has more comment than code, wow), but the actual amount of work you put at
84+
stuff that is *not* code: documentation, benchmarking, implementation
85+
explanations. Even the git log is clean and the unit tests run out of the box
86+
on Python 2 and 3.
7987

80-
.. _`Formations Python`: http://formationspython.com/
81-
82-
**Mark Summerfield**, a short plea for `Python Sorted Collections`_
88+
**Mark Summerfield**, a short plea for `Python Sorted Collections`_ --
8389

8490
Python's "batteries included" standard library seems to have a battery
8591
missing. And the argument that "we never had it before" has worn thin. It is
8692
time that Python offered a full range of collection classes out of the box,
8793
including sorted ones.
8894

95+
`Sorted Containers`_ is used in popular open source projects such as:
96+
`Zipline`_, an algorithmic trading library from Quantopian; `Angr`_, a binary
97+
analysis platform from UC Santa Barbara; `Trio`_, an async I/O library; and
98+
`Dask Distributed`_, a distributed computation library supported by Continuum
99+
Analytics.
100+
101+
.. _`Fellow of the Python Software Foundation`: http://en.wikipedia.org/wiki/Alex_Martelli
102+
.. _`simple, effective implementation`: http://www.grantjenks.com/docs/sortedcontainers/implementation.html
103+
.. _`author of Writing Idiomatic Python and Python Trainer`: http://reviews.jeffknupp.com/reviews/sortedcontainers/3/
104+
.. _`Python and Django Trainer`: https://www.elephorm.com/formateur/kevin-samuel
89105
.. _`Python Sorted Collections`: http://www.qtrac.eu/pysorted.html
106+
.. _`Zipline`: https://github.com/quantopian/zipline
107+
.. _`Angr`: https://github.com/angr/angr
108+
.. _`Trio`: https://github.com/python-trio/trio
109+
.. _`Dask Distributed`: https://github.com/dask/distributed
90110

91111
Features
92112
--------
@@ -117,15 +137,17 @@ Installing `Sorted Containers`_ is simple with `pip
117137

118138
$ pip install sortedcontainers
119139

120-
You can access documentation in the interpreter with Python's built-in help
121-
function:
140+
You can access documentation in the interpreter with Python's built-in `help`
141+
function. The `help` works on modules, classes and methods in `Sorted
142+
Containers`_::
122143

123144
.. code-block:: python
124145
125-
>>> from sortedcontainers import SortedList, SortedDict, SortedSet
126-
>>> help(SortedList)
146+
>>> import sortedcontainers
147+
>>> help(sortedcontainers)
148+
>>> from sortedcontainers import SortedDict
127149
>>> help(SortedDict)
128-
>>> help(SortedSet)
150+
>>> help(SortedDict.popitem)
129151
130152
Documentation
131153
-------------

0 commit comments

Comments
 (0)