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 Distribution
Built Distributions
Hashes for quicksectx-0.3.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6146584cac5af3c04fa9fdc2bf55857f18e05d1e551fa5b2ccf24ec4677b1b07 |
|
MD5 | 66039b7fa75d6e596ca3d9970ea62a28 |
|
BLAKE2b-256 | 785d5887eb7f7f27652ba2204c194be24a156b5577bfed5c5a2a8e5429bc9fcd |
Hashes for quicksectx-0.3.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e8268ac400bb98a134c0d540bb7153ee3f793d624f6e12b6fbea454c5a8c0c1 |
|
MD5 | 0f36dca4172854e344f569d9b144cfb6 |
|
BLAKE2b-256 | 3c65411e5d367cec68098b8ebd868bf7a32c91dfc94fea99cc7a6da15cd76349 |
Hashes for quicksectx-0.3.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3734302e4a41686e684ca8e9c4446f9a719e83643d1f945266c5b33260c7ff8d |
|
MD5 | 48eea1059553f8e4ef4a00c8adcdd5c8 |
|
BLAKE2b-256 | 8ff09116109d57ed0166182b17042f9d1be419231567c703852f06f6caf30f3b |
Hashes for quicksectx-0.3.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf8818bdc5e0e0dcfc968e4c39919334a7a898e9bdfa4f943e1c850356481d2a |
|
MD5 | b327578cb1f85ff29f5d8e47119fa807 |
|
BLAKE2b-256 | 0b8bac05d9ed41b5f3562b9dec9e05d6596fd6240255e5536af3bd33ecdbf463 |
Hashes for quicksectx-0.3.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f3200a21ffb7ddbc0e8beea73addd4f9374c558fc619959bcd96b3569c63fc7 |
|
MD5 | cdcee776515d7205493b85498b209ede |
|
BLAKE2b-256 | 982d871716014a311caaab02425f4f3cf0f30cb46450f61bb284c64cfd329ccc |
Hashes for quicksectx-0.3.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ad9c772020294cdb33491db37e376a046ceff3d0a04e4563c3ec07043b2340d |
|
MD5 | 7d748c857199c9359caba16ccf25e2a4 |
|
BLAKE2b-256 | 67a17f1727a3eabb30874769522bdedf12d54d866f553be8d2200266037966d8 |
Hashes for quicksectx-0.3.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a19dcec4cf60194f26ad23f94c0786ea23119df0b57f856486f2b33e610cc73 |
|
MD5 | 19ce9194b2688f69c9b4864617b21df1 |
|
BLAKE2b-256 | c03b54f56c4249dc9a9943f858df460665a9cb45fcbf87bba726525b4ef2c8ee |
Hashes for quicksectx-0.3.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f220c7e34da6bcee302c4f5cb9ff031a387b65b5f5bcb4d8784817d9f88f21c2 |
|
MD5 | 8b96f0a9c0fe712ec66b735071f864b1 |
|
BLAKE2b-256 | 83c8da8733821dd0cce171388b60b97775457afe136724b749693beb37ba7273 |
Hashes for quicksectx-0.3.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db9ae8277e0ca176af8e5d6dc56fb2200a9fde0d0cc2478557063978abe30d8e |
|
MD5 | 0f02ad9d9a3bd0da1962b86370804bf4 |
|
BLAKE2b-256 | 88561e9878b09fa85d099f8ceb88f6e0e7c7d334ffacb53be1416200235d8aec |
Hashes for quicksectx-0.3.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6a4824413383698f622a170e2a393f5067120a7bcc0dbe084a6cedea524f6d4 |
|
MD5 | a9d8494694987964bb36ad130c8777ab |
|
BLAKE2b-256 | abd9eba2f5a982f4ba9593adc6819d8504f34b0d99d62a17dc7b9ff5f77486d4 |
Hashes for quicksectx-0.3.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba9a18f382fba737c42f7e4de87d236d504757647aa8d6d08ca1d5b618922ccf |
|
MD5 | 64daa4d7c8283e8186cb4479a24562cd |
|
BLAKE2b-256 | 0af85f056fb252610aa1392178fe1a00be8379730a8209791b13703247d7134b |
Hashes for quicksectx-0.3.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c37cb8ff8f8986ae0d4dd9e19141c501a96ac7c408ca36b8bc8f01853ec45522 |
|
MD5 | a2953d2c5b85a33035f8abefbdf8e8e9 |
|
BLAKE2b-256 | b96b57a36339c9da6ba20be55990db9bbe4ef997165f73990050fe69699282a8 |
Hashes for quicksectx-0.3.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05bdaab46d700623989d42138e52a7b73ce00990d1fff16b1875eb73f1f19c19 |
|
MD5 | 893b39e57159b5d7d0c9d46c46e08657 |
|
BLAKE2b-256 | 348c343c3d73cea0ac162071c24e1cb604ccdc2e86d8285cc3383b8c2e97f72f |
Hashes for quicksectx-0.3.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b96681bec3c3ae82b64f676e59ab3f89c233b448e62bb3f4e6290d51e06a95c6 |
|
MD5 | 758a3a77f8e42ba9ce24b5815843d11a |
|
BLAKE2b-256 | e389bb84b22abc4173679e91f97f099f9657872124d79485f38245ec7666d1a8 |
Hashes for quicksectx-0.3.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e17b1478fb57630fce75d38685a3cfbf920d777da3d4f0528d4cfa69f63ea455 |
|
MD5 | eda8178e7bad65f2f29316f0901e781c |
|
BLAKE2b-256 | d9871fc5082072e495ac3522a57955ac0cdc3f074fda07d7d455a5cba673194c |