fast, simple interval intersection
Project description
Description
Quicksect is a fast python / cython implementation of interval search based on the pure python version in bx-python I pulled it out, optimized and converted to cython and James Taylor has incoporated it back into bx-python with his improvements.
I have brought this project back from the dead because I want a fast, simple, no-dependencies Interval tree.
Extended with removal operations and allows pretty print to display tree structure (By Jianlin)
License is MIT.
Installation
pip install quicksectx
Use
To use extended quicksect(quicksectx):
>>> from quicksectx import IntervalNode, IntervalTree, Interval >>> tree = IntervalTree() >>> tree.add(1, 3, 100) >>> tree.add(3, 7, 110) >>> tree.add(2, 5, 120) >>> tree.add(4, 6, 130) >>> print(tree.pretty_print()) Inv(1, 3, d=100) r: Inv(3, 7, d=110) l: Inv(2, 5, d=120) r: Inv(4, 6, d=130) >>> print(tree.find(Interval(2, 5))) [Inv(1, 3, d=100), Inv(3, 7, d=110), Inv(2, 5, d=120), Inv(4, 6, d=130)] >>> tree.remove(Interval(2, 5)) >>> print(tree.find(Interval(2, 5))) [Inv(1, 3, d=100), Inv(3, 7, d=110), Inv(4, 6, d=130)]
To use traditional quicksect, you can still using the same syntax:
>>> from quicksect import IntervalNode, Interval, IntervalTree
Most common use will be via IntervalTree:
>>> tree = IntervalTree() >>> tree.add(23, 45) >>> tree.add(55, 66) >>> tree.search(46, 47) [] >>> tree.search(44, 56) [Interval(55, 66), Interval(23, 45)]>>> tree.insert(Interval(88, 444)) >>> res = tree.find(Interval(99, 100)) >>> res [Interval(88, 444)] >>> res[0].start, res[0].end (88, 444)
Thats pretty much everything you need to know about the tree.
Test
$ python setup.py test
Low-Level
In some cases, users may want to utilize the lower-level interface that accesses the nodes of the tree:
>>> inter = IntervalNode(Interval(22, 33)) >>> inter = inter.insert(Interval(44, 55)) >>> inter.intersect(24, 26) [Interval(22, 33)]>>> inter.left(Interval(34, 35), n=1) [Interval(22, 33)]>>> inter.right(Interval(34, 35), n=1) [Interval(44, 55)]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for quicksectx-0.3.0b3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64d030ad8b72c8769ce4701a09fa1ff757adf384bc22b8a071e8703fca0fb8cf |
|
MD5 | ec8415d09161b98698c908afae0c0747 |
|
BLAKE2b-256 | 8cfe78844a24b6c751ac30c7568fe683cc7eaf08a031006357b9b6ad43de1f1c |
Hashes for quicksectx-0.3.0b3-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0b6bb14f4ee9e53047fb831d6b0939ba5ae45cd3275a8c90c2d6548c4aefa13 |
|
MD5 | 9587d1cf808c24094d1638582dce6229 |
|
BLAKE2b-256 | 9aeb76467e462849ed0bd454166898b2cc60be5be29cb0854a0926ebd972b9f6 |
Hashes for quicksectx-0.3.0b3-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c671445ff527766d146655bf1c49254716d2ae3cf63d316a44265d875dee7c6c |
|
MD5 | 1e26fb0dd2a6f0001bacd97baf68f300 |
|
BLAKE2b-256 | b0f27601892b2708bf33dfffea84c6b7da2398f16c4d8c07330c15ea5317f38c |
Hashes for quicksectx-0.3.0b3-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69fb3325a4cd94d75e4b3287780a9aa5c0e0af3ef22bd20fe07f613b65ca6fb5 |
|
MD5 | 2cd118260fb720f7e56b9efacaa35747 |
|
BLAKE2b-256 | 2ae0225a808ed3135b35692b5a14a59e400d38c345cd8359dd800513d03cd88c |
Hashes for quicksectx-0.3.0b3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87e23498fe24963d712a4fde93e75a796b2394a480017f30b622b6fb0e0e3feb |
|
MD5 | 37391161a3944707d1fc37f52d4d5e3b |
|
BLAKE2b-256 | 70a18b8bcec5e6ad0296af321daefc5bf8dd97b651b79d5679550e0846cc3d82 |
Hashes for quicksectx-0.3.0b3-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 624f49975f7f910621b5df1a2da36a3338f08b037874ae1cc77b3000ad566cde |
|
MD5 | b13492d3d1f2c6bdd01e0e7b9db66ded |
|
BLAKE2b-256 | b0f4fef52df30b66440c67ba594c21b4406abe11a4a3c0091391ed8a8783e8cf |
Hashes for quicksectx-0.3.0b3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3484eeabba1cb8ae82524419f39e4665691b618eaea04c0b3cbba13e74eaca3 |
|
MD5 | bb6491fbc147d67360aa27fbbe985c60 |
|
BLAKE2b-256 | f754745d9fd3a92520a1aab8c284b88744a7888f218bdf23bb90f126ba97cd10 |
Hashes for quicksectx-0.3.0b3-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93d47905f200a513f7f17248d8ca9a64cce4675cbef67f54eee2e2f5f93e2184 |
|
MD5 | 9a668852743a7b3b65e8e5a97cbfc0b4 |
|
BLAKE2b-256 | 67233db324a44482c6d851a49c2a0be4cea1cca91f256af74d3259bc79c7aa58 |
Hashes for quicksectx-0.3.0b3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d5010669865aab5d5fadbe92cd1a439ea34268d6d9ebd1bd0b07708459c17e9 |
|
MD5 | b2334427046271bdbf72c90795c5b352 |
|
BLAKE2b-256 | b454d0bf369e6a7d2bacff7f92f13e22b2dec7de9a1142d9228510ef65f2f723 |
Hashes for quicksectx-0.3.0b3-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8ab185b259621c7db55a857d988044c5f87be7960ca7d7a3288d52db94b632c |
|
MD5 | 1926cb072141190a6fa2e9b81c56aa0f |
|
BLAKE2b-256 | c0dad39d3d7067264ce854acb7afbee395cc1ba61cb2d7df5f6c0d7fdb673a96 |
Hashes for quicksectx-0.3.0b3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be13ae8dde8b4563affee71d894ea9fa908e2f5eee7851f1b9d2f7415c777988 |
|
MD5 | e8d470b6bf7e806f3fa467f61a11ab81 |
|
BLAKE2b-256 | 7543a023b52fe38b4ef89448f6be6896bc11c6c4996792e394d035da99c03de6 |
Hashes for quicksectx-0.3.0b3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a43551bcc766898c6c380bbc6b47b571983ed9f83db16759bb7eef621f8c22c5 |
|
MD5 | 9ecabd06c616ad5d065e991153135ed9 |
|
BLAKE2b-256 | 512e9ecaf3ac8904a277b647745991b851334e212a511309db3357015ca6b57d |