Is there simple implementation of segment tree for python?

1.8k Views Asked by At

I need segment tree for solving of my task. Should I develop my own segment tree, or there is any good implementation of such tree?

I need the following operations:

  1. Segment update: tree.add(from, to, value)
  2. Segment sum: tree.sum(from, to)
1

There are 1 best solutions below

0
On

I'm the author of pypi.python.org/pypi/segmenttree. I recommend you to use it because I have fixed mistakes. (Actually they are just bad examples ;-)

It supports sum as one of it's features, which I think is what you right need.

If you find any mistakes or you have any suggestions, just drop me a message or just submit a pull request on github.