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 indexes 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])
None
>>> print(list(s[18:23]))
[8, 9, None, None, None]
>>> print(s[100500])
None

By default sparsedlist substitutes item on None value if it has not set. To disable this feature, pass required param to constructor. Then IndexError will be raised on getting unset items. For instance:

>>> from sparsedlist import SparsedList
>>> s = SparsedList(required=True)
>>> s[10:20] = range(10)
>>> print(s[100500])
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 '100500' does not exist
>>> print(list(s[18:25]))
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 '20' 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.4.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

sparsedlist-0.4-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file sparsedlist-0.4.tar.gz.

File metadata

  • Download URL: sparsedlist-0.4.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.6rc1+

File hashes

Hashes for sparsedlist-0.4.tar.gz
Algorithm Hash digest
SHA256 bbd2284c0b29b12a94e611cc8a7ebcf38449bd6b81f1e3bc1c402926820cbd0d
MD5 841d79769f5d4514e70a57252bc10a00
BLAKE2b-256 a89a0087b24a0cb3278edd8e60b82878788c2fd7234c0f36259a95823b81486a

See more details on using hashes here.

File details

Details for the file sparsedlist-0.4-py3-none-any.whl.

File metadata

  • Download URL: sparsedlist-0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.6rc1+

File hashes

Hashes for sparsedlist-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4978184ce4c188f4300febfa8a1db5fb427928fa6069f155c55c09bb5d9b6872
MD5 946d120260dfc8007d9fbfbbbd328936
BLAKE2b-256 af30aedd6a638c636bc77b50679fe7c8be01200b521f516da2c2aa16e903bed3

See more details on using hashes here.

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