Code Monkey home page Code Monkey logo

pyskip's Introduction

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)
<Skiplist: 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

pyskip's People

Contributors

toastdriven avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pyskip's Issues

Memory improvement and _sizeof__ for skiplist

Important for skip list is the memory usage (compared to linked lists etc.), especially depending on the max layers. Some more infos of it in runtime would be nice

Would suggest something for the skiplist class like:

import sys
...

def __sizeof__(self):
    return sum([sys.getsizeof(x) for x in self.layers])

...

Suggestion for usage of: slots

Reductio of overhead for instanciation of heave used classes

e.g.:

class Foo:
    __slots__ = ["x", "y"]
    def __init__(self, x, y):
        self.x = x
        self.y = y

It removes the attribute dict of instance and therefore reduces memory usage.

Range Queries

I do not see an API for doing range queries such as for geohashes. Is any in the offing ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.