Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xanewok/segment_tree
Simple segment tree C++ implementation for range sum queries
https://github.com/xanewok/segment_tree
Last synced: 24 days ago
JSON representation
Simple segment tree C++ implementation for range sum queries
- Host: GitHub
- URL: https://github.com/xanewok/segment_tree
- Owner: Xanewok
- License: gpl-3.0
- Created: 2016-11-02T11:56:41.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-11-02T12:47:26.000Z (about 8 years ago)
- Last Synced: 2024-12-12T19:43:29.531Z (28 days ago)
- Language: C++
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# segment_tree
simple segment tree C++ implementation for range sum queriesHeap-allocated template segment tree for all your insert/range sum query needs.
Currently implements
```c++
segment_tree::segment_tree(T min, T max)
void segment_tree::insert(T key, T value)
T segment_tree::query(T key, T value) const
void segment_tree::clear()
```# Example
```c++
segment_tree tree(0, 100); // Construct a tree for an interval [0-100]tree.insert(20, 2);
assert(tree.query(15, 20) == 2);
assert(tree.query(15, 25) == 2);
tree.insert(21, 3);
assert(tree.query(15, 20) == 2);
assert(tree.query(21, 25) == 3);
assert(tree.query(15, 25) == 5);
```