SegmentTree-0.1: Data structure for O(log n) mconcats on list intervals

Data.SegmentTree

Description

This module contains the SegmentTree data structure, its constructor and the query function.

Example Usage:

     import Data.Monoid
     import Data.SegmentTree
     ...
     st = mkTree $ map Sum [0..10]
     ...
     queryTree st (0, 10) == Sum 55
     queryTree st (5, 10) == Sum 45
     queryTree st (0, 4)  == Sum 10

Synopsis

Documentation

data Monoid a => SegmentTree a Source

A SegmentTree is a binary tree and the bounds of its corresponding interval.

Constructors

SegmentTree (Tree a) (Int, Int) 

Instances

mkTree :: Monoid a => [a] -> SegmentTree aSource

Build the SegmentTree for the given list. Time: O(n*log n)

queryTree :: Monoid a => SegmentTree a -> (Int, Int) -> aSource

Query the SegmentTree for the specified closed interval. Time: O(log n)