Skip to main content

Cython implementation of Python's collections.OrderedDict

Project description

=============
cyordereddict
=============

.. image:: https://travis-ci.org/shoyer/cyordereddict.svg?branch=master
:target: https://travis-ci.org/shoyer/cyordereddict

The Python standard library's ``OrderedDict`` ported to Cython. A drop-in
replacement that is 2-6x faster.

Install:
``pip install cyordereddict``

Dependencies:
CPython (2.6, 2.7, 3.3 or 3.4) and a C compiler. Cython is only required
for the dev version.

Use:
.. code-block:: python

from cyordereddict import OrderedDict

Benchmarks:
Python 2.7:

================== ================================= =========================
Test Code Ratio (stdlib / cython)
================== ================================= =========================
``__init__`` empty ``OrderedDict()`` 1.8
``__init__`` list ``OrderedDict(list_data)`` 4.8
``__init__`` dict ``OrderedDict(dict_data)`` 4.6
``__setitem__`` ``ordereddict[0] = 0`` 8.6
``__getitem__`` ``ordereddict[0]`` 3
``update`` ``ordereddict.update(dict_data)`` 5.5
``__iter__`` ``list(ordereddict)`` 5.6
``items`` ``ordereddict.items()`` 5.9
``__contains__`` ``0 in ordereddict`` 2.3
================== ================================= =========================

Python 3.4:

================== ================================= =========================
Test Code Ratio (stdlib / cython)
================== ================================= =========================
``__init__`` empty ``OrderedDict()`` 1.5
``__init__`` list ``OrderedDict(list_data)`` 3.9
``__init__`` dict ``OrderedDict(dict_data)`` 4.2
``__setitem__`` ``ordereddict[0] = 0`` 8.4
``__getitem__`` ``ordereddict[0]`` 2.9
``update`` ``ordereddict.update(dict_data)`` 6.5
``__iter__`` ``list(ordereddict)`` 2.3
``items`` ``list(ordereddict.items())`` 2.1
``__contains__`` ``0 in ordereddict`` 2.3
================== ================================= =========================
To run these yourself, use ``cyordereddict.benchmark()``

Cavaets:
``cyorderedddict.OrderedDict`` is an extension type (similar to the
built-in ``dict``) instead of a Python class. This is necessary for speed,
but means that in a few pathological cases its behavior will defer from
``collections.OrderedDict``:

* The ``inspect`` module does not work on ``cyorderedddict.OrderedDict``
methods.
* Extension types use slots instead of dictionaries, so you cannot add
custom attributes without making a subclass (e.g.,
``OrderedDict.foo = 'bar'`` will fail).

You can do anything else you might do with an OrderedDict, including
subclassing: everything else passes the ``collections.OrderedDict`` test
suite. We based the Cython code directly on the Python standard library,
and thus use separate code bases for Python 2 and 3, specifically to
reduce the potential for introducing new bugs.

License:
MIT. Based on the Python standard library, which is under the Python
Software Foundation License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cyordereddict-0.2.tar.gz (130.9 kB view details)

Uploaded Source

File details

Details for the file cyordereddict-0.2.tar.gz.

File metadata

  • Download URL: cyordereddict-0.2.tar.gz
  • Upload date:
  • Size: 130.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cyordereddict-0.2.tar.gz
Algorithm Hash digest
SHA256 72299a1783f51f0e1d8ed33fb1aa8b644deaef163cbf57eab71d8350b61f8ffe
MD5 25b8d5ab16be4190385fa7992799c9eb
BLAKE2b-256 5c062732e943637b541748b2ccfff1583bd8c2303c2bd9ede54da766c52c2e5e

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page