Metadata-Version: 2.1
Name: pyrsistent-extras
Version: 0.1.0
Summary: Extra data structures for pyrsistent
Home-page: http://github.com/mingmingrr/pyrsistent-extras
Author: mingmingrr
Author-email: mingmingrr@gmail.com
License: MIT
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.7
Description-Content-Type: text/x-rst
License-File: LICENSE.mit
Requires-Dist: typing-extensions


Extra data structures for `pyrsistent <http://github.com/tobgu/pyrsistent>`_

Below are examples of common usage patterns for some of the structures and
features. More information and full documentation for all data structures is
available in the `documentation <http://pyrsistent-extras.readthedocs.org>`_.

PSequence
---------

Persistent sequences implemented with finger trees,
with :math:`O(\log{n})` merge/split/lookup
and :math:`O(1)` access at both ends.

.. code-block:: python

	>>> from pyrsistent_extras import psequence
	>>> seq1 = psequence([1, 2, 3])
	>>> seq1
	psequence([1, 2, 3])
	>>> seq2 = seq1.append(4)
	>>> seq2
	psequence([1, 2, 3, 4])
	>>> seq3 = seq1 + seq2
	>>> seq3
	psequence([1, 2, 3, 1, 2, 3, 4])
	>>> seq1
	psequence([1, 2, 3])
	>>> seq3[3]
	1
	>>> seq3[2:5]
	psequence([3, 1, 2])
	>>> seq1.set(1, 99)
	psequence([1, 99, 3])


PHeap
-----

Persistent heaps implemented with binomial heaps,
with :math:`O(1)` findMin/insert and :math:`O(\log{n})` merge/deleteMin.
Comes in two flavors: ``PMinHeap`` and ``PMaxHeap``.

.. code-block:: python

	>>> from pyrsistent_extras import pminheap
	>>> heap1 = pminheap([(1,'a'), (2,'b')])
	>>> heap1
	pminheap([(1, 'a'), (2, 'b')])
	>>> heap2 = heap1.push(3,'c')
	>>> heap2
	pminheap([(1, 'a'), (2, 'b'), (3, 'c')])
	>>> heap3 = heap1 + heap2
	>>> heap3
	pminheap([(1, 'a'), (1, 'a'), (2, 'b'), (2, 'b'), (3, 'c')])
	>>> key, value, heap4 = heap3.pop()
	>>> (key, value)
	(1, 'a')
	>>> heap4
	pminheap([(1, 'a'), (2, 'b'), (2, 'b'), (3, 'c')])

