Skip to main content

Endless list with non-contiguous indexes

Project description

sparsedlist

sparsedlist is endless list with non-contiguous indexes. Based on Skip list data structure. Python3 is used.

sparsedlist is a list structure, where set of indices can have “gaps” and you can put a value to any index. In other words, the structure is similar to dict, but has list interface and sorted numeric indexes.

Since skiplist structure is used as machinery, then you have fast forward iteration with O(1) complexity and pretty good indexation/insertion/deletion with O(log n) complexity.

Example:

>>> from sparsedlist import SparsedList
>>> s = SparsedList()
>>> s[180] = 'rock the microphone'
>>> s[10:20] = range(10)
>>> print(s)
SparsedList{{10: 0, 11: 1, 12: 2, 13: 3, 14: 4, 15: 5, 16: 6, 17: 7, 18: 8, 19: 9, 180: 'rock the microphone'}}
>>> print(s[180])
rock the microphone
>>> print(s[-1])
rock the microphone
>>> print(s[-2])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/sparsedlist.py", line 73, in __getitem__
    raise IndexError("Item with index '{}' does not exist".format(item))
IndexError: Item with index '179' does not exist
>>>
>>> print(s[100])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/sparsedlist.py", line 73, in __getitem__
    raise IndexError("Item with index '{}' does not exist".format(item))
IndexError: Item with index '100' does not exist

Dependencies

pyskiplist only. Tested on python3.6.

Installation

pip3 install sparsedlist

Author

Igor Derkach, gosha753951@gmail.com

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

sparsedlist-0.2.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

sparsedlist-0.2-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

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