sortedcontainers


Namesortedcontainers JSON
Version 2.4.0 PyPI version JSON
download
home_pagehttp://www.grantjenks.com/docs/sortedcontainers/
SummarySorted Containers -- Sorted List, Sorted Dict, Sorted Set
upload_time2021-05-16 22:03:42
maintainer
docs_urlNone
authorGrant Jenks
requires_python
licenseApache 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Python Sorted Containers
========================

`Sorted Containers`_ is an Apache2 licensed `sorted collections library`_,
written in pure-Python, and fast as C-extensions.

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

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

.. code-block:: python

    >>> from sortedcontainers import SortedList
    >>> sl = SortedList(['e', 'a', 'c', 'd', 'b'])
    >>> sl
    SortedList(['a', 'b', 'c', 'd', 'e'])
    >>> sl *= 10_000_000
    >>> sl.count('c')
    10000000
    >>> sl[-3:]
    ['e', 'e', 'e']
    >>> from sortedcontainers import SortedDict
    >>> sd = SortedDict({'c': 3, 'a': 1, 'b': 2})
    >>> sd
    SortedDict({'a': 1, 'b': 2, 'c': 3})
    >>> sd.popitem(index=-1)
    ('c', 3)
    >>> from sortedcontainers import SortedSet
    >>> ss = SortedSet('abracadabra')
    >>> ss
    SortedSet(['a', 'b', 'c', 'd', 'r'])
    >>> ss.bisect_left('c')
    2

All of the operations shown above run in faster than linear time. The above
demo also takes nearly a gigabyte of memory to run. When the sorted list is
multiplied by ten million, it stores ten million references to each of "a"
through "e". Each reference requires eight bytes in the sorted
container. That's pretty hard to beat as it's the cost of a pointer to each
object. It's also 66% less overhead than a typical binary tree implementation
(e.g. Red-Black Tree, AVL-Tree, AA-Tree, Splay-Tree, Treap, etc.) for which
every node must also store two pointers to children nodes.

`Sorted Containers`_ takes all of the work out of Python sorted collections -
making your deployment and use of Python easy. There's no need to install a C
compiler or pre-build and distribute custom extensions. Performance is a
feature and testing has 100% coverage with unit tests and hours of stress.

.. _`Sorted Containers`: http://www.grantjenks.com/docs/sortedcontainers/
.. _`sorted collections library`: http://www.grantjenks.com/docs/sortedcontainers/

Testimonials
------------

**Alex Martelli**, `Fellow of the Python Software Foundation`_

"Good stuff! ... I like the `simple, effective implementation`_ idea of
splitting the sorted containers into smaller "fragments" to avoid the O(N)
insertion costs."

**Jeff Knupp**, `author of Writing Idiomatic Python and Python Trainer`_

"That last part, "fast as C-extensions," was difficult to believe. I would need
some sort of `Performance Comparison`_ to be convinced this is true. The author
includes this in the docs. It is."

**Kevin Samuel**, `Python and Django Trainer`_

I'm quite amazed, not just by the code quality (it's incredibly readable and
has more comment than code, wow), but the actual amount of work you put at
stuff that is *not* code: documentation, benchmarking, implementation
explanations. Even the git log is clean and the unit tests run out of the box
on Python 2 and 3.

**Mark Summerfield**, a short plea for `Python Sorted Collections`_

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

`Sorted Containers`_ is used in popular open source projects such as:
`Zipline`_, an algorithmic trading library from Quantopian; `Angr`_, a binary
analysis platform from UC Santa Barbara; `Trio`_, an async I/O library; and
`Dask Distributed`_, a distributed computation library supported by Continuum
Analytics.

.. _`Fellow of the Python Software Foundation`: https://en.wikipedia.org/wiki/Alex_Martelli
.. _`simple, effective implementation`: http://www.grantjenks.com/docs/sortedcontainers/implementation.html
.. _`author of Writing Idiomatic Python and Python Trainer`: https://jeffknupp.com/
.. _`Python and Django Trainer`: https://www.elephorm.com/formateur/kevin-samuel
.. _`Python Sorted Collections`: http://www.qtrac.eu/pysorted.html
.. _`Zipline`: https://github.com/quantopian/zipline
.. _`Angr`: https://github.com/angr/angr
.. _`Trio`: https://github.com/python-trio/trio
.. _`Dask Distributed`: https://github.com/dask/distributed

Features
--------

- Pure-Python
- Fully documented
- Benchmark comparison (alternatives, runtimes, load-factors)
- 100% test coverage
- Hours of stress testing
- Performance matters (often faster than C implementations)
- Compatible API (nearly identical to older blist and bintrees modules)
- Feature-rich (e.g. get the five largest keys in a sorted dict: d.keys()[-5:])
- Pragmatic design (e.g. SortedSet is a Python set with a SortedList index)
- Developed on Python 3.7
- Tested on CPython 2.7, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7 and PyPy, PyPy3

.. image:: https://api.travis-ci.org/grantjenks/python-sortedcontainers.svg?branch=master
   :target: http://www.grantjenks.com/docs/sortedcontainers/

.. image:: https://ci.appveyor.com/api/projects/status/github/grantjenks/python-sortedcontainers?branch=master&svg=true
   :target: http://www.grantjenks.com/docs/sortedcontainers/

Quickstart
----------

Installing `Sorted Containers`_ is simple with `pip
<https://pypi.org/project/pip/>`_::

    $ pip install sortedcontainers

You can access documentation in the interpreter with Python's built-in `help`
function. The `help` works on modules, classes and methods in `Sorted
Containers`_.

.. code-block:: python

    >>> import sortedcontainers
    >>> help(sortedcontainers)
    >>> from sortedcontainers import SortedDict
    >>> help(SortedDict)
    >>> help(SortedDict.popitem)

Documentation
-------------

Complete documentation for `Sorted Containers`_ is available at
http://www.grantjenks.com/docs/sortedcontainers/

User Guide
..........

The user guide provides an introduction to `Sorted Containers`_ and extensive
performance comparisons and analysis.

- `Introduction`_
- `Performance Comparison`_
- `Load Factor Performance Comparison`_
- `Runtime Performance Comparison`_
- `Simulated Workload Performance Comparison`_
- `Performance at Scale`_

.. _`Introduction`: http://www.grantjenks.com/docs/sortedcontainers/introduction.html
.. _`Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance.html
.. _`Load Factor Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance-load.html
.. _`Runtime Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance-runtime.html
.. _`Simulated Workload Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance-workload.html
.. _`Performance at Scale`: http://www.grantjenks.com/docs/sortedcontainers/performance-scale.html

Community Guide
...............

The community guide provides information on the development of `Sorted
Containers`_ along with support, implementation, and history details.

- `Development and Support`_
- `Implementation Details`_
- `Release History`_

.. _`Development and Support`: http://www.grantjenks.com/docs/sortedcontainers/development.html
.. _`Implementation Details`: http://www.grantjenks.com/docs/sortedcontainers/implementation.html
.. _`Release History`: http://www.grantjenks.com/docs/sortedcontainers/history.html

API Documentation
.................

The API documentation provides information on specific functions, classes, and
modules in the `Sorted Containers`_ package.

- `Sorted List`_
- `Sorted Dict`_
- `Sorted Set`_

.. _`Sorted List`: http://www.grantjenks.com/docs/sortedcontainers/sortedlist.html
.. _`Sorted Dict`: http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html
.. _`Sorted Set`: http://www.grantjenks.com/docs/sortedcontainers/sortedset.html

Talks
-----

- `Python Sorted Collections | PyCon 2016 Talk`_
- `SF Python Holiday Party 2015 Lightning Talk`_
- `DjangoCon 2015 Lightning Talk`_

.. _`Python Sorted Collections | PyCon 2016 Talk`: http://www.grantjenks.com/docs/sortedcontainers/pycon-2016-talk.html
.. _`SF Python Holiday Party 2015 Lightning Talk`: http://www.grantjenks.com/docs/sortedcontainers/sf-python-2015-lightning-talk.html
.. _`DjangoCon 2015 Lightning Talk`: http://www.grantjenks.com/docs/sortedcontainers/djangocon-2015-lightning-talk.html

Resources
---------

- `Sorted Containers Documentation`_
- `Sorted Containers at PyPI`_
- `Sorted Containers at Github`_
- `Sorted Containers Issue Tracker`_

.. _`Sorted Containers Documentation`: http://www.grantjenks.com/docs/sortedcontainers/
.. _`Sorted Containers at PyPI`: https://pypi.org/project/sortedcontainers/
.. _`Sorted Containers at Github`: https://github.com/grantjenks/python-sortedcontainers
.. _`Sorted Containers Issue Tracker`: https://github.com/grantjenks/python-sortedcontainers/issues

Sorted Containers License
-------------------------

Copyright 2014-2019 Grant Jenks

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.



            

Raw data

            {
    "_id": null,
    "home_page": "http://www.grantjenks.com/docs/sortedcontainers/",
    "name": "sortedcontainers",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Grant Jenks",
    "author_email": "contact@grantjenks.com",
    "download_url": "https://files.pythonhosted.org/packages/e8/c4/ba2f8066cceb6f23394729afe52f3bf7adec04bf9ed2c820b39e19299111/sortedcontainers-2.4.0.tar.gz",
    "platform": "",
    "description": "Python Sorted Containers\n========================\n\n`Sorted Containers`_ is an Apache2 licensed `sorted collections library`_,\nwritten in pure-Python, and fast as C-extensions.\n\nPython's standard library is great until you need a sorted collections\ntype. Many will attest that you can get really far without one, but the moment\nyou **really need** a sorted list, sorted dict, or sorted set, you're faced\nwith a dozen different implementations, most using C-extensions without great\ndocumentation and benchmarking.\n\nIn Python, we can do better. And we can do it in pure-Python!\n\n.. code-block:: python\n\n    >>> from sortedcontainers import SortedList\n    >>> sl = SortedList(['e', 'a', 'c', 'd', 'b'])\n    >>> sl\n    SortedList(['a', 'b', 'c', 'd', 'e'])\n    >>> sl *= 10_000_000\n    >>> sl.count('c')\n    10000000\n    >>> sl[-3:]\n    ['e', 'e', 'e']\n    >>> from sortedcontainers import SortedDict\n    >>> sd = SortedDict({'c': 3, 'a': 1, 'b': 2})\n    >>> sd\n    SortedDict({'a': 1, 'b': 2, 'c': 3})\n    >>> sd.popitem(index=-1)\n    ('c', 3)\n    >>> from sortedcontainers import SortedSet\n    >>> ss = SortedSet('abracadabra')\n    >>> ss\n    SortedSet(['a', 'b', 'c', 'd', 'r'])\n    >>> ss.bisect_left('c')\n    2\n\nAll of the operations shown above run in faster than linear time. The above\ndemo also takes nearly a gigabyte of memory to run. When the sorted list is\nmultiplied by ten million, it stores ten million references to each of \"a\"\nthrough \"e\". Each reference requires eight bytes in the sorted\ncontainer. That's pretty hard to beat as it's the cost of a pointer to each\nobject. It's also 66% less overhead than a typical binary tree implementation\n(e.g. Red-Black Tree, AVL-Tree, AA-Tree, Splay-Tree, Treap, etc.) for which\nevery node must also store two pointers to children nodes.\n\n`Sorted Containers`_ takes all of the work out of Python sorted collections -\nmaking your deployment and use of Python easy. There's no need to install a C\ncompiler or pre-build and distribute custom extensions. Performance is a\nfeature and testing has 100% coverage with unit tests and hours of stress.\n\n.. _`Sorted Containers`: http://www.grantjenks.com/docs/sortedcontainers/\n.. _`sorted collections library`: http://www.grantjenks.com/docs/sortedcontainers/\n\nTestimonials\n------------\n\n**Alex Martelli**, `Fellow of the Python Software Foundation`_\n\n\"Good stuff! ... I like the `simple, effective implementation`_ idea of\nsplitting the sorted containers into smaller \"fragments\" to avoid the O(N)\ninsertion costs.\"\n\n**Jeff Knupp**, `author of Writing Idiomatic Python and Python Trainer`_\n\n\"That last part, \"fast as C-extensions,\" was difficult to believe. I would need\nsome sort of `Performance Comparison`_ to be convinced this is true. The author\nincludes this in the docs. It is.\"\n\n**Kevin Samuel**, `Python and Django Trainer`_\n\nI'm quite amazed, not just by the code quality (it's incredibly readable and\nhas more comment than code, wow), but the actual amount of work you put at\nstuff that is *not* code: documentation, benchmarking, implementation\nexplanations. Even the git log is clean and the unit tests run out of the box\non Python 2 and 3.\n\n**Mark Summerfield**, a short plea for `Python Sorted Collections`_\n\nPython's \"batteries included\" standard library seems to have a battery\nmissing. And the argument that \"we never had it before\" has worn thin. It is\ntime that Python offered a full range of collection classes out of the box,\nincluding sorted ones.\n\n`Sorted Containers`_ is used in popular open source projects such as:\n`Zipline`_, an algorithmic trading library from Quantopian; `Angr`_, a binary\nanalysis platform from UC Santa Barbara; `Trio`_, an async I/O library; and\n`Dask Distributed`_, a distributed computation library supported by Continuum\nAnalytics.\n\n.. _`Fellow of the Python Software Foundation`: https://en.wikipedia.org/wiki/Alex_Martelli\n.. _`simple, effective implementation`: http://www.grantjenks.com/docs/sortedcontainers/implementation.html\n.. _`author of Writing Idiomatic Python and Python Trainer`: https://jeffknupp.com/\n.. _`Python and Django Trainer`: https://www.elephorm.com/formateur/kevin-samuel\n.. _`Python Sorted Collections`: http://www.qtrac.eu/pysorted.html\n.. _`Zipline`: https://github.com/quantopian/zipline\n.. _`Angr`: https://github.com/angr/angr\n.. _`Trio`: https://github.com/python-trio/trio\n.. _`Dask Distributed`: https://github.com/dask/distributed\n\nFeatures\n--------\n\n- Pure-Python\n- Fully documented\n- Benchmark comparison (alternatives, runtimes, load-factors)\n- 100% test coverage\n- Hours of stress testing\n- Performance matters (often faster than C implementations)\n- Compatible API (nearly identical to older blist and bintrees modules)\n- Feature-rich (e.g. get the five largest keys in a sorted dict: d.keys()[-5:])\n- Pragmatic design (e.g. SortedSet is a Python set with a SortedList index)\n- Developed on Python 3.7\n- Tested on CPython 2.7, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7 and PyPy, PyPy3\n\n.. image:: https://api.travis-ci.org/grantjenks/python-sortedcontainers.svg?branch=master\n   :target: http://www.grantjenks.com/docs/sortedcontainers/\n\n.. image:: https://ci.appveyor.com/api/projects/status/github/grantjenks/python-sortedcontainers?branch=master&svg=true\n   :target: http://www.grantjenks.com/docs/sortedcontainers/\n\nQuickstart\n----------\n\nInstalling `Sorted Containers`_ is simple with `pip\n<https://pypi.org/project/pip/>`_::\n\n    $ pip install sortedcontainers\n\nYou can access documentation in the interpreter with Python's built-in `help`\nfunction. The `help` works on modules, classes and methods in `Sorted\nContainers`_.\n\n.. code-block:: python\n\n    >>> import sortedcontainers\n    >>> help(sortedcontainers)\n    >>> from sortedcontainers import SortedDict\n    >>> help(SortedDict)\n    >>> help(SortedDict.popitem)\n\nDocumentation\n-------------\n\nComplete documentation for `Sorted Containers`_ is available at\nhttp://www.grantjenks.com/docs/sortedcontainers/\n\nUser Guide\n..........\n\nThe user guide provides an introduction to `Sorted Containers`_ and extensive\nperformance comparisons and analysis.\n\n- `Introduction`_\n- `Performance Comparison`_\n- `Load Factor Performance Comparison`_\n- `Runtime Performance Comparison`_\n- `Simulated Workload Performance Comparison`_\n- `Performance at Scale`_\n\n.. _`Introduction`: http://www.grantjenks.com/docs/sortedcontainers/introduction.html\n.. _`Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance.html\n.. _`Load Factor Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance-load.html\n.. _`Runtime Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance-runtime.html\n.. _`Simulated Workload Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance-workload.html\n.. _`Performance at Scale`: http://www.grantjenks.com/docs/sortedcontainers/performance-scale.html\n\nCommunity Guide\n...............\n\nThe community guide provides information on the development of `Sorted\nContainers`_ along with support, implementation, and history details.\n\n- `Development and Support`_\n- `Implementation Details`_\n- `Release History`_\n\n.. _`Development and Support`: http://www.grantjenks.com/docs/sortedcontainers/development.html\n.. _`Implementation Details`: http://www.grantjenks.com/docs/sortedcontainers/implementation.html\n.. _`Release History`: http://www.grantjenks.com/docs/sortedcontainers/history.html\n\nAPI Documentation\n.................\n\nThe API documentation provides information on specific functions, classes, and\nmodules in the `Sorted Containers`_ package.\n\n- `Sorted List`_\n- `Sorted Dict`_\n- `Sorted Set`_\n\n.. _`Sorted List`: http://www.grantjenks.com/docs/sortedcontainers/sortedlist.html\n.. _`Sorted Dict`: http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html\n.. _`Sorted Set`: http://www.grantjenks.com/docs/sortedcontainers/sortedset.html\n\nTalks\n-----\n\n- `Python Sorted Collections | PyCon 2016 Talk`_\n- `SF Python Holiday Party 2015 Lightning Talk`_\n- `DjangoCon 2015 Lightning Talk`_\n\n.. _`Python Sorted Collections | PyCon 2016 Talk`: http://www.grantjenks.com/docs/sortedcontainers/pycon-2016-talk.html\n.. _`SF Python Holiday Party 2015 Lightning Talk`: http://www.grantjenks.com/docs/sortedcontainers/sf-python-2015-lightning-talk.html\n.. _`DjangoCon 2015 Lightning Talk`: http://www.grantjenks.com/docs/sortedcontainers/djangocon-2015-lightning-talk.html\n\nResources\n---------\n\n- `Sorted Containers Documentation`_\n- `Sorted Containers at PyPI`_\n- `Sorted Containers at Github`_\n- `Sorted Containers Issue Tracker`_\n\n.. _`Sorted Containers Documentation`: http://www.grantjenks.com/docs/sortedcontainers/\n.. _`Sorted Containers at PyPI`: https://pypi.org/project/sortedcontainers/\n.. _`Sorted Containers at Github`: https://github.com/grantjenks/python-sortedcontainers\n.. _`Sorted Containers Issue Tracker`: https://github.com/grantjenks/python-sortedcontainers/issues\n\nSorted Containers License\n-------------------------\n\nCopyright 2014-2019 Grant Jenks\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "Sorted Containers -- Sorted List, Sorted Dict, Sorted Set",
    "version": "2.4.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "5bede1950ae4d8ef1a037de51c3071cf",
                "sha256": "a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0"
            },
            "downloads": -1,
            "filename": "sortedcontainers-2.4.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5bede1950ae4d8ef1a037de51c3071cf",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 29575,
            "upload_time": "2021-05-16T22:03:41",
            "upload_time_iso_8601": "2021-05-16T22:03:41.177807Z",
            "url": "https://files.pythonhosted.org/packages/32/46/9cb0e58b2deb7f82b84065f37f3bffeb12413f947f9388e4cac22c4621ce/sortedcontainers-2.4.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "50eeb6cb739568b590b28f9a3f445c78",
                "sha256": "25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88"
            },
            "downloads": -1,
            "filename": "sortedcontainers-2.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "50eeb6cb739568b590b28f9a3f445c78",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 30594,
            "upload_time": "2021-05-16T22:03:42",
            "upload_time_iso_8601": "2021-05-16T22:03:42.897871Z",
            "url": "https://files.pythonhosted.org/packages/e8/c4/ba2f8066cceb6f23394729afe52f3bf7adec04bf9ed2c820b39e19299111/sortedcontainers-2.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-05-16 22:03:42",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "sortedcontainers"
}
        
Elapsed time: 0.02969s