haccepted-0.1.0.0: Data structures and algorithms
Safe HaskellNone
LanguageHaskell2010

SegTree

Description

Segment tree

A data structure supporting point updates and range queries on a sequence of monoids. This implementation supports large ranges that do not fit in memory, sometimes called a dynamic or sparse segment tree.

Sources:

The complexities below assume mappend takes O(1) time. Let n = r - l + 1 in all instances below.

SegTree implementable Foldable. Folding over all the elements takes O(n).

Synopsis

Documentation

data SegTree a Source #

Instances

Instances details
Foldable SegTree Source # 
Instance details

Defined in SegTree

Methods

fold :: Monoid m => SegTree m -> m #

foldMap :: Monoid m => (a -> m) -> SegTree a -> m #

foldMap' :: Monoid m => (a -> m) -> SegTree a -> m #

foldr :: (a -> b -> b) -> b -> SegTree a -> b #

foldr' :: (a -> b -> b) -> b -> SegTree a -> b #

foldl :: (b -> a -> b) -> b -> SegTree a -> b #

foldl' :: (b -> a -> b) -> b -> SegTree a -> b #

foldr1 :: (a -> a -> a) -> SegTree a -> a #

foldl1 :: (a -> a -> a) -> SegTree a -> a #

toList :: SegTree a -> [a] #

null :: SegTree a -> Bool #

length :: SegTree a -> Int #

elem :: Eq a => a -> SegTree a -> Bool #

maximum :: Ord a => SegTree a -> a #

minimum :: Ord a => SegTree a -> a #

sum :: Num a => SegTree a -> a #

product :: Num a => SegTree a -> a #

Show a => Show (SegTree a) Source # 
Instance details

Defined in SegTree

Methods

showsPrec :: Int -> SegTree a -> ShowS #

show :: SegTree a -> String #

showList :: [SegTree a] -> ShowS #

NFData a => NFData (SegTree a) Source # 
Instance details

Defined in SegTree

Methods

rnf :: SegTree a -> () #

emptyST :: Monoid a => (Int, Int) -> SegTree a Source #

Builds a segment tree on range (l, r) where each element is mempty. O(log n).

fromListST :: Monoid a => (Int, Int) -> [a] -> SegTree a Source #

Builds a segment tree on (l, r) where the elements are taken from a list. If the list is shorter than the range, the remaining elements are mempty. O(n).

adjustST :: Monoid a => (a -> a) -> Int -> SegTree a -> SegTree a Source #

Adjusts the element at index i. O(log n).

foldRangeST :: Monoid a => Int -> Int -> SegTree a -> a Source #

Folds the elements in the range (ql, qr). Elements outside (l, r) are considered to be mempty. O(log n).