自平衡二叉搜索树

aa-sbst的Python项目详细描述


There is no implemenation of SBST in Standard Python Library, and I found it quite inconvenient and a little bit disappointing.

This is a compact, portable (no dependencies) and extremely easy-to-use implementation of self-balancing binary search tree. This particular type of trees (so called AA-tree) is described here: https://en.wikipedia.org/wiki/AA_tree

Features:

  1. You can use this module through import instruction or simply copy-paste the implementation into your source code, and be happy.

  2. While instantiating sbst object you can specify your own comparison function or use default simple comparison.

  3. You can add values to tree one-by-one using function add, or fill it from some iterable object (function addfrom). Either initialization in constructor is possible.

  4. The tree stores all duplicates. This feature is vital if the tree is an index for in-memory table.

  5. This SBST gives you two basic search operations:

    • min - returns minimal value that is not less (if inclusive parameter is True) or greater (inclusive=False) than specified limit.
    • max - returns maximal value that is not greater (if inclusive parameter is True) or less (inclusive=False) than specified limit.

    If you have not specified limit, functions return respectively minimal or maximal value in the tree.

  6. Function forward_from returns generator that yields sorted sequence of values starting from a specified value. Function backward_from yields reverse-sorted sequence down from a specified value. These functions have inclusive option too. If starting value is not specified, these functions yield respectively sorted or reverse-sorted sequences of all values in the tree. If tree modified while iterating (some values inserted, some removed, tree rebalanced), sequence will be yielded in right predictable way.

  7. If comparison function treats values as equal, they will be yielded by forward_from and backward_from generators in the insertion order.

  8. Do not store _None_ values into tree. Even if your comparison function can process them, you will not be able to search them because None value will be treated as ‘not specified’.

  9. If mutable objects inserted into the tree are changed, their sequence in tree may become irrelevant. So after value mutation it is a good idea to remove it from tree and add again.

  10. Methods add and remove are not thread-safe. Be careful.

Tutorial: [doc/tutorial.md](doc/tutorial.md)

关键词:二叉树 平台:未知 分类器:开发状态::4-测试版 分类器:目标受众::开发人员 分类器:目标受众:教育 分类器:主题::软件开发::库 分类器:许可证::CC0 1.0通用(cc01.0)公共域专用 分类器:编程语言::python::3 分类器:编程语言::python::3.4 分类器:编程语言::python::3.5 分类器:编程语言::python::3.6 描述内容类型:文本/标记

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java通过Spring MVC web应用程序向客户端发送文本文件   java是否可以在运行时动态实例化DAO类?   调用VB。来自Java的net函数   java在Android中通过单击打开特定文件夹   java如何使用maven pom。xml标识非标准项目结构中的testng测试用例?   java为什么FOP在大文件上崩溃?   Architecture python+flask和spring boot+java   java Kafka工具根本没有启动Ubuntu 19.10   如何使用Eclipse运行Java USB API for Windows   java如何在Eclipse中查看J2EE预览服务器/容器的日志/控制台?   网页抓取是否可以使用Java crawler crawler4j暂停和恢复抓取?   java当我第二次按下按钮时,应用程序停止工作   带有偏移量和限制的java SQLite分页问题   java如何在OSX mavericks中将端口80转发到8080   java从泛型方法调用非泛型方法   java My代码未按预期工作。十进制输出不是它应该的样子   节点。java中的js加密(jasypt)和nodejs中的解密   java乘法表不工作数组索引超出范围   java将JDBC与Firebirdsql连接起来