您的位置:首页 > 数据库 > Redis

使用redis实现trie结构

2011-12-11 11:30 656 查看

http://jedp.posterous.com/auto-complete-with-redis-and-python

Auto-complete with Redis and Python

Salvatore Sanfilippo is always sharing cool things to do with redis. As with all things redis, it never ceases to amaze how much you can do with so little code. Thanks, Salvatore.

He posted this gist which implements an autocompleter in redis using ordered sets to represent trie data.

j4mie promptly translated the same into Python.

I’ve branched j4mie’s version and made it work for multi-word phrases. There’s a github gist here.

In his comments, j4mie extends the invitation to make his version more Pythonic. I’ve tried to do so in my fork. I hope I haven’t damaged too much in the process. I also put a command-line wrapper around it, so you can run it from the shell and play with redis interactively.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: