Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quicksectx-0.3.1.tar.gz (165.8 kB view hashes)

Uploaded Source

Built Distributions

quicksectx-0.3.1-cp311-cp311-win_amd64.whl (178.6 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

quicksectx-0.3.1-cp311-cp311-win32.whl (168.6 kB view hashes)

Uploaded CPython 3.11 Windows x86

quicksectx-0.3.1-cp311-cp311-musllinux_1_1_x86_64.whl (230.6 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

quicksectx-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (227.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

quicksectx-0.3.1-cp311-cp311-macosx_10_9_x86_64.whl (195.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

quicksectx-0.3.1-cp310-cp310-win_amd64.whl (180.4 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

quicksectx-0.3.1-cp310-cp310-win32.whl (169.8 kB view hashes)

Uploaded CPython 3.10 Windows x86

quicksectx-0.3.1-cp310-cp310-musllinux_1_1_x86_64.whl (232.1 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

quicksectx-0.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (229.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

quicksectx-0.3.1-cp310-cp310-macosx_10_9_x86_64.whl (200.2 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

quicksectx-0.3.1-cp39-cp39-win_amd64.whl (183.3 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

quicksectx-0.3.1-cp39-cp39-win32.whl (172.4 kB view hashes)

Uploaded CPython 3.9 Windows x86

quicksectx-0.3.1-cp39-cp39-musllinux_1_1_x86_64.whl (236.8 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

quicksectx-0.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (234.1 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

quicksectx-0.3.1-cp39-cp39-macosx_10_9_x86_64.whl (201.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

quicksectx-0.3.1-cp38-cp38-win_amd64.whl (183.3 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

quicksectx-0.3.1-cp38-cp38-win32.whl (172.2 kB view hashes)

Uploaded CPython 3.8 Windows x86

quicksectx-0.3.1-cp38-cp38-musllinux_1_1_x86_64.whl (236.3 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

quicksectx-0.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (234.1 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

quicksectx-0.3.1-cp38-cp38-macosx_11_0_arm64.whl (184.3 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

quicksectx-0.3.1-cp38-cp38-macosx_10_9_x86_64.whl (198.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

quicksectx-0.3.1-cp37-cp37m-win_amd64.whl (180.1 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

quicksectx-0.3.1-cp37-cp37m-win32.whl (169.0 kB view hashes)

Uploaded CPython 3.7m Windows x86

quicksectx-0.3.1-cp37-cp37m-musllinux_1_1_x86_64.whl (233.2 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

quicksectx-0.3.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (231.7 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

quicksectx-0.3.1-cp37-cp37m-macosx_10_9_x86_64.whl (196.5 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

quicksectx-0.3.1-cp36-cp36m-win_amd64.whl (194.7 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

quicksectx-0.3.1-cp36-cp36m-win32.whl (179.2 kB view hashes)

Uploaded CPython 3.6m Windows x86

quicksectx-0.3.1-cp36-cp36m-musllinux_1_1_x86_64.whl (234.0 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ x86-64

quicksectx-0.3.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (231.8 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

quicksectx-0.3.1-cp36-cp36m-macosx_10_9_x86_64.whl (196.1 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page