Skip to main content

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)

Keywords: binary tree Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: Intended Audience :: Education Classifier: Topic :: Software Development :: Libraries Classifier: License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Description-Content-Type: text/markdown

Release files for aa-sbst 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aa-sbst 0.1.2
File Size Uploaded
aa_sbst-0.1.2.tar.gz 12.0 kB Details

Release files / aa_sbst-0.1.2.tar.gz

Download URL aa_sbst-0.1.2.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
279d17d260138eb8c2d10c43c6f3664b1501a8cfcf6b9cf664fcb1130e7cafc8
BLAKE2b-256 checksum
How to use checksums
32b8d1d1c862649d3fd35e7f12707116139f2f8f44d36ed51077b6e62a0639a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page