https://github.com/toastdriven/pyskip
A pure Python skiplist implementation. For fun.
https://github.com/toastdriven/pyskip
Last synced: 11 months ago
JSON representation
A pure Python skiplist implementation. For fun.
- Host: GitHub
- URL: https://github.com/toastdriven/pyskip
- Owner: toastdriven
- License: bsd-3-clause
- Created: 2013-10-16T10:04:33.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-12-03T10:02:29.000Z (over 12 years ago)
- Last Synced: 2025-06-07T16:54:57.825Z (11 months ago)
- Language: Python
- Size: 112 KB
- Stars: 22
- Watchers: 3
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
======
pyskip
======
A pure Python skiplist implementation.
A skiplist provides a quickly searchable structure (like a balanced binary
tree) that also updates fairly cheaply (no nasty rebalancing acts).
In other words, it's **awesome**.
See http://en.wikipedia.org/wiki/Skip_list for more information.
Written mostly an exercise for myself, it turns out skiplists are really useful.
It also comes with a (mostly-underdocumented) linked-list implementation
(+ a sorted variant), if that's useful.
Requirements
============
* Python 3.3+ (should work on Python 2.6+ as well, as well as PyPy 2.0+)
* ``nose>=1.30`` for running unittests
Usage
=====
Using it looks like:
>>> import skiplist
>>> skip = skiplist.Skiplist()
>>> len(skip)
0
>>> 6 in skip
False
>>> skip.insert(0)
>>> skip.insert(7)
>>> skip.insert(3)
>>> skip.insert(6)
>>> skip.insert(245)
>>> len(skip)
5
>>> 6 in skip
True
>>> skip.remove(245)
>>> len(skip)
4
>>> skip.find(3)
Performance
===========
Performance is alright, though I'm sure there's room for improvement. See the
``bench.py`` script for more information.
Running Tests
=============
Run ``pip install nose`` (preferrably within a virtualenv) to install nose.
Then run ``nosetests -s -v tests.py`` to exercise the full suite.
TODO
====
* A more performant implementation of ``remove`` (still O(N))
* More performance testing
* Loading data seems slow
Meta
====
:author: Daniel Lindsley
:license: BSD
:version: 0.9.0