Skip to main content

Python binding of cedar (implementation of efficiently-updatable double-array trie) using Cython

Project description

pycedar

version python license

Python binding of cedar (implementation of efficiently-updatable double-array trie) using Cython

Official URL of cedar: http://www.tkl.iis.u-tokyo.ac.jp/~ynaga/cedar/

Installation

install from PyPi release

$ pip install --user pycedar

install from GitHub master

$ pip install --user https://github.com/akivajp/pycedar/archive/master.zip

Usage

using python-like dict class based on double array trie

>>> import pycedar

>>> d = pycedar.dict()
>>> print( len(d) )
0
>>> print( bool(d) )
False
>>> print( list(d) )
[]

>>> d['nineteen'] = 19
>>> d.set('twenty', 20)
>>> d['twenty one'] = 21
>>> d['twenty two'] = 22
>>> d['twenty three'] = 23
>>> d['twenty four'] = 24

>>> print( len(d) )
6
>>> print( bool(d) )
True
>>> print( list(d) )
['nineteen', 'twenty', 'twenty four', 'twenty one', 'twenty three', 'twenty two']
>>> print( list(d.keys()) )
['nineteen', 'twenty', 'twenty four', 'twenty one', 'twenty three', 'twenty two']
>>> print( list(d.values()) )
[19, 20, 24, 21, 23, 22]
>>> print( list(d.items()) )
[('nineteen', 19), ('twenty', 20), ('twenty four', 24), ('twenty one', 21), ('twenty three', 23), ('twenty two', 22)]
>>> print( d['twenty four'] )
24
>>> print( 'twenty four' in d )
True
>>> del d['twenty four']
>>> print( 'twenty four' in d )
False
>>> try:
>>>     print( d['twenty four'] )
>>> except Exception as e:
>>>     print( repr(e) )
KeyError('twenty four',)
>>> print( d.get('twenty three') )
23
>>> print( d.get('twenty four') )
-1
>>> print( d.get('twenty four', None) )
None

>>> print( list(d.find('')) )
[('nineteen', 19), ('twenty', 20), ('twenty one', 21), ('twenty three', 23), ('twenty two', 22)]
>>> print( list(d.find('tw')) )
[('twenty', 20), ('twenty one', 21), ('twenty three', 23), ('twenty two', 22)]
>>> print( list(d.find('twenty t')) )
[('twenty three', 23), ('twenty two', 22)]
>>> print( list(d.find_keys('twenty')) )
['twenty', 'twenty one', 'twenty three', 'twenty two']
>>> print( list(d.find_values('twenty')) )
[20, 21, 23, 22]

>>> n = d.get_node('twenty')
>>> print( n )
'twenty'
>>> print( repr(n) )
pycedar.node(trie=<pycedar.str_trie object at 0x7fffe2394b80>, id=260, length=6, root=0)
>>> print( n.key() )
twenty
>>> print( n.value() )
20
>>> print( [n.key() for n in n.find_nodes(' t')] )
[' three', ' two']

>>> n = d.get_node('twenty ')
>>> print( n )
None

>>> d.save('test.dat')
>>> d2 = pycedar.dict()
>>> print( d2.setdefault('eighteen', 18) )
18
>>> print( list(d2.items()) )
[('eighteen', 18)]
>>> d2.load('test.dat')
>>> print( list(d2.items()) )
[('nineteen', 19), ('twenty', 20), ('twenty one', 21), ('twenty three', 23), ('twenty two', 22)]
>>> print( d2.setdefault('eighteen', 18) )
18
>>> print( list(d2.items()) )
[('eighteen', 18), ('nineteen', 19), ('twenty', 20), ('twenty one', 21), ('twenty three', 23), ('twenty two', 22)]

using more primitive data structures

(TBA)

todo

  • documentation of classes:
    • base_trie
    • str_trie
    • bytes_trie
    • unicode_trie
    • node

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

pycedar-0.1.3.tar.gz (16.5 kB view hashes)

Uploaded Source

Built Distributions

pycedar-0.1.3-cp37-cp37m-manylinux1_x86_64.whl (741.1 kB view hashes)

Uploaded CPython 3.7m

pycedar-0.1.3-cp37-cp37m-manylinux1_i686.whl (687.1 kB view hashes)

Uploaded CPython 3.7m

pycedar-0.1.3-cp37-cp37m-macosx_10_15_x86_64.whl (179.1 kB view hashes)

Uploaded CPython 3.7m macOS 10.15+ x86-64

pycedar-0.1.3-cp36-cp36m-manylinux1_x86_64.whl (755.6 kB view hashes)

Uploaded CPython 3.6m

pycedar-0.1.3-cp36-cp36m-manylinux1_i686.whl (706.8 kB view hashes)

Uploaded CPython 3.6m

pycedar-0.1.3-cp36-cp36m-macosx_10_14_x86_64.whl (184.0 kB view hashes)

Uploaded CPython 3.6m macOS 10.14+ x86-64

pycedar-0.1.3-cp35-cp35m-manylinux1_x86_64.whl (707.3 kB view hashes)

Uploaded CPython 3.5m

pycedar-0.1.3-cp35-cp35m-manylinux1_i686.whl (652.3 kB view hashes)

Uploaded CPython 3.5m

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