Code Monkey home page Code Monkey logo

ratel's Introduction

Ratel

PyPI version Supported Python versions Build Status codecov ratel PyPI Downloads GitHub

Skip list is a data structure that allows fast search within an ordered sequence of elements and a probabilistic alternative to Balanced Trees.It is also easier to implement. This library uses redis skip list to implement SortedSet data types for Python

This library modified in four ways:

  1. This implementation is allowed to repeated scores.
  2. The comparison is not just by score but by key data.
  3. It's a doubly linked list with the backward being only at "level 1". This allows to traverse the list from tail to head, useful for zrevrange.
  4. This implementation is combined with dict data structure for fast search.

Skip Lists are data structure that can be used in place of balanced trees. They are easier to implement and generally faster. This library uses redis skip lists to implement SortedSet data types for Python.

SortedSet is implemented in Python and C with high performance.

Here is a few examples:

from boost_collections.zskiplist.zset_node import ZsetNode
from boost_collections.zskiplist.zset_obj import ZsetObj
zset_obj = ZsetObj()
elements = [ZsetNode('a', 1), ZsetNode('a', 2), ZsetNode('c', 2)]
# multi elements added
zset_obj.zadd(elements=elements)
# multi elements added nx
zset_obj.zadd(elements=elements, 'nx')
# one element added
zset_obj.zadd(elements=ZsetNode('d', 1))
# zincrby
zset_obj.zincrby(ZsetNode('a', 1), 'incr')
# zcard
zset_obj.zcard()
# zscore
zset_obj.zscore('a')
# zrange
zset_obj.zrange(0, -1, True)
# zrevrange
zset_obj.zrevrange(0, 1, True)
# zrange_by_score
zset_obj.zrange_by_score(1, 0, 2, 0)
# zrevrange_by_score
zset_obj.zrevrange_by_score(1, 0, 2, 0)

Compatibility

  • Python 2.7, 3.5+

Installation

pip install ratel

or

https://github.com/524243642/ratel
cd ratel
python setup.py install

Time Complexity

ZsetObj Operations Average Case
zadd O(log N)
zincrby O(log N)
zrem O(log N)
zscore O(1)
zcard O(1)
zrange O(log(N) + M)
zrevrange O(log(N) + M)
zfloor O(log N)
zlower O(log N)
zrange_by_score O(log(N) + M)
zrevrange_by_score O(log(N) + M)

Release

0.3.4 2018-12-04 zadd zincrby zrem zscore zcard zrange zrevrange

0.4.0 2018-12-23 zfloor zlower

0.4.1 2019-01-23 shields.io access

0.5.0 2019-04-25 zrange_by_score zrevrange_by_score

1.0.0 2020-11-23 stable version released

1.0.1 2020-11-24 python 3.7+ supported

License

MIT

Contributing

Welcome to feedback and improvements.Please submit a pull request!

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.