The most comprehensive implementation of Segment Tree.
Project description
Segment Tree implementation for Python 3
This is a general implementation of a segment tree for Python 3.
Semigroup range operations in O(logN) time
Built-in support for max, min, sum, mul functions
Extensible to support all semigroup operations
Only Python 3 for now
Example usage
array = [3, 1, 5, 3, 13, 7, 2, 7, 2]
tree = SegmentTree(array, [min, max, sum])
t.query(1, 3, sum) # 9
t.update(0, 10) # [10, 1, 5, 3, 13, 7, 2, 7, 2]
t.query(0, 3, sum) # 19
t.update(7, 0) # [10, 1, 5, 3, 13, 7, 2, 0, 2]
t.query(0, 8, min) # 0
t.update(2, -1) # [10, 1, -1, 3, 13, 7, 2, 0, 2]
t.query(0, 2, min) # -1
Installation
pip3 install segment-tree
Complexity of operations
TODO
Dependencies
TODO
Status: WIP
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
segment_tree-0.1.4.tar.gz
(2.3 kB
view hashes)
Built Distribution
Close
Hashes for segment_tree-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2911ff26b1609e2b47b785a2234c7450bd2b994fafb8fbaa97263f25a1beb4d |
|
MD5 | 1b6217aadad21dce93ac10d342e94d5d |
|
BLAKE2b-256 | f69f69e47ec4aceaeed877f66c60f7f04e83b83f07e583d8d57f5a8bb1c6981a |