用cython实现cedar的python绑定
pycedar的Python项目详细描述
松柏
使用cython的python绑定cedar
(高效可更新双数组trie的实现)
cedar
:http://www.tkl.iis.u-tokyo.ac.jp/~ynaga/cedar/
安装
从pypi release安装
$ pip install --user pycedar
从github master安装
$ pip install --user https://github.com/akivajp/pycedar/archive/master.zip
用法
使用基于双数组trie
的类似python的dict类>>>importpycedar>>>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'ind)True>>>deld['twenty four']>>>print('twenty four'ind)False>>>try:>>>print(d['twenty four'])>>>exceptExceptionase:>>>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_trieobjectat0x7fffe2394b80>,id=260,length=6,root=0)>>>print(n.key())twenty>>>print(n.value())20>>>print([n.key()forninn.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)]
使用更原始的数据结构
(待定)
待办事项
- 课程文件:
- 基准线
- str_trie
- 字节重试
- Unicode_-trie
- 节点