fingertree-rm-1.0.0.4: Finger-trees with root measures
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.FingerTree.RootMeasured.Strict

Synopsis

Strict finger trees with root measures

data StrictFingerTree vr vi a Source #

A StrictFingerTree with elements of type a, an internal measure of type vi, and a root measure of type vr.

Instances

Instances details
Measured vi a => Measured vi (StrictFingerTree vr vi a) Source #

All StrictFingerTrees are internally measured.

Instance details

Defined in Data.FingerTree.RootMeasured.Strict

Methods

measure :: StrictFingerTree vr vi a -> vi #

RootMeasured vr a => RootMeasured vr (StrictFingerTree vr vi a) Source #

All StrictFingerTrees are root measured.

Instance details

Defined in Data.FingerTree.RootMeasured.Strict

Methods

measureRoot :: StrictFingerTree vr vi a -> vr Source #

Foldable (StrictFingerTree vr vi) Source # 
Instance details

Defined in Data.FingerTree.RootMeasured.Strict

Methods

fold :: Monoid m => StrictFingerTree vr vi m -> m #

foldMap :: Monoid m => (a -> m) -> StrictFingerTree vr vi a -> m #

foldMap' :: Monoid m => (a -> m) -> StrictFingerTree vr vi a -> m #

foldr :: (a -> b -> b) -> b -> StrictFingerTree vr vi a -> b #

foldr' :: (a -> b -> b) -> b -> StrictFingerTree vr vi a -> b #

foldl :: (b -> a -> b) -> b -> StrictFingerTree vr vi a -> b #

foldl' :: (b -> a -> b) -> b -> StrictFingerTree vr vi a -> b #

foldr1 :: (a -> a -> a) -> StrictFingerTree vr vi a -> a #

foldl1 :: (a -> a -> a) -> StrictFingerTree vr vi a -> a #

toList :: StrictFingerTree vr vi a -> [a] #

null :: StrictFingerTree vr vi a -> Bool #

length :: StrictFingerTree vr vi a -> Int #

elem :: Eq a => a -> StrictFingerTree vr vi a -> Bool #

maximum :: Ord a => StrictFingerTree vr vi a -> a #

minimum :: Ord a => StrictFingerTree vr vi a -> a #

sum :: Num a => StrictFingerTree vr vi a -> a #

product :: Num a => StrictFingerTree vr vi a -> a #

(Monoid vr, Measured vi a) => Monoid (StrictFingerTree vr vi a) Source # 
Instance details

Defined in Data.FingerTree.RootMeasured.Strict

Methods

mempty :: StrictFingerTree vr vi a #

mappend :: StrictFingerTree vr vi a -> StrictFingerTree vr vi a -> StrictFingerTree vr vi a #

mconcat :: [StrictFingerTree vr vi a] -> StrictFingerTree vr vi a #

(Semigroup vr, Measured vi a) => Semigroup (StrictFingerTree vr vi a) Source # 
Instance details

Defined in Data.FingerTree.RootMeasured.Strict

Methods

(<>) :: StrictFingerTree vr vi a -> StrictFingerTree vr vi a -> StrictFingerTree vr vi a #

sconcat :: NonEmpty (StrictFingerTree vr vi a) -> StrictFingerTree vr vi a #

stimes :: Integral b => b -> StrictFingerTree vr vi a -> StrictFingerTree vr vi a #

Generic (StrictFingerTree vr vi a) Source # 
Instance details

Defined in Data.FingerTree.RootMeasured.Strict

Associated Types

type Rep (StrictFingerTree vr vi a) :: Type -> Type #

Methods

from :: StrictFingerTree vr vi a -> Rep (StrictFingerTree vr vi a) x #

to :: Rep (StrictFingerTree vr vi a) x -> StrictFingerTree vr vi a #

(Show vr, Show a) => Show (StrictFingerTree vr vi a) Source # 
Instance details

Defined in Data.FingerTree.RootMeasured.Strict

Methods

showsPrec :: Int -> StrictFingerTree vr vi a -> ShowS #

show :: StrictFingerTree vr vi a -> String #

showList :: [StrictFingerTree vr vi a] -> ShowS #

(Eq vr, Eq a) => Eq (StrictFingerTree vr vi a) Source # 
Instance details

Defined in Data.FingerTree.RootMeasured.Strict

Methods

(==) :: StrictFingerTree vr vi a -> StrictFingerTree vr vi a -> Bool #

(/=) :: StrictFingerTree vr vi a -> StrictFingerTree vr vi a -> Bool #

(Ord vr, Ord a) => Ord (StrictFingerTree vr vi a) Source # 
Instance details

Defined in Data.FingerTree.RootMeasured.Strict

Methods

compare :: StrictFingerTree vr vi a -> StrictFingerTree vr vi a -> Ordering #

(<) :: StrictFingerTree vr vi a -> StrictFingerTree vr vi a -> Bool #

(<=) :: StrictFingerTree vr vi a -> StrictFingerTree vr vi a -> Bool #

(>) :: StrictFingerTree vr vi a -> StrictFingerTree vr vi a -> Bool #

(>=) :: StrictFingerTree vr vi a -> StrictFingerTree vr vi a -> Bool #

max :: StrictFingerTree vr vi a -> StrictFingerTree vr vi a -> StrictFingerTree vr vi a #

min :: StrictFingerTree vr vi a -> StrictFingerTree vr vi a -> StrictFingerTree vr vi a #

NoThunks a => NoThunks (StrictFingerTree vr vi a) Source # 
Instance details

Defined in Data.FingerTree.RootMeasured.Strict

type Rep (StrictFingerTree vr vi a) Source # 
Instance details

Defined in Data.FingerTree.RootMeasured.Strict

type Rep (StrictFingerTree vr vi a) = D1 ('MetaData "StrictFingerTree" "Data.FingerTree.RootMeasured.Strict" "fingertree-rm-1.0.0.4-inplace" 'False) (C1 ('MetaCons "SFT" 'PrefixI 'True) (S1 ('MetaSel ('Just "rm") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 vr) :*: S1 ('MetaSel ('Just "elements") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (StrictFingerTree vi a))))

Measuring

class Monoid v => Measured v a | a -> v where #

Things that can be measured.

Methods

measure :: a -> v #

Instances

Instances details
Measured v a => Measured v (Digit a) 
Instance details

Defined in Data.FingerTree

Methods

measure :: Digit a -> v #

Measured v a => Measured v (StrictFingerTree v a) 
Instance details

Defined in Data.FingerTree.Strict

Methods

measure :: StrictFingerTree v a -> v #

Measured v a => Measured v (FingerTree v a)

O(1). The cached measure of a tree.

Instance details

Defined in Data.FingerTree

Methods

measure :: FingerTree v a -> v #

Monoid v => Measured v (Node v a) 
Instance details

Defined in Data.FingerTree

Methods

measure :: Node v a -> v #

Measured vi a => Measured vi (StrictFingerTree vr vi a) Source #

All StrictFingerTrees are internally measured.

Instance details

Defined in Data.FingerTree.RootMeasured.Strict

Methods

measure :: StrictFingerTree vr vi a -> vi #

class (LeftCancellative v, RightCancellative v, Monoid v) => RootMeasured v a | a -> v where Source #

Re-iteration of Measured, but for root measures.

This re-iteration is necessary because we want to allow the root measure to be distinct from the internal measure. For example, we can not create both of these instances for distinct types T and T':

instance Measured T  a where -- ...
instance Measured T' a where -- ...

Furthermore, we want the root measure to be a cancellative monoid.

Methods

measureRoot :: a -> v Source #

Instances

Instances details
RootMeasured vr a => RootMeasured vr (StrictFingerTree vr vi a) Source #

All StrictFingerTrees are root measured.

Instance details

Defined in Data.FingerTree.RootMeasured.Strict

Methods

measureRoot :: StrictFingerTree vr vi a -> vr Source #

type SuperMeasured vr vi a = (RootMeasured vr a, Measured vi a) Source #

Conjunction of RootMeasured and Measured constraints.

Construction

fromList :: SuperMeasured vr vi a => [a] -> StrictFingerTree vr vi a Source #

O(n). Create a sequence from a finite list of elements. The opposite operation toList is supplied by the Foldable instance.

(|>) :: SuperMeasured vr vi a => StrictFingerTree vr vi a -> a -> StrictFingerTree vr vi a infixl 5 Source #

O(1). Add an element to the right end of a sequence.

Mnemonic: a triangle with the single element at the pointy end.

Splitting

class Sized a where Source #

Methods

size :: a -> Int Source #

newtype SplitRootMeasure vr vi a Source #

A function that computes the root measures of the left and right parts of a split.

The function's arguments are: * The root measure of the input of the split function, and * The left and right parts of the split.

Constructors

SplitRootMeasure 

Fields

split :: SuperMeasured vr vi a => (vi -> Bool) -> SplitRootMeasure vr vi a -> StrictFingerTree vr vi a -> (StrictFingerTree vr vi a, StrictFingerTree vr vi a) Source #

O(log(min(i,n-i))) + O(f(l, r)). Split a sequence at a point where the predicate on the accumulated internal measure of the prefix changes from False to True.

For predictable results, one should ensure that there is only one such point, i.e. that the predicate is monotonic.

A SplitRootMeasure function f should be provided that computes the root measures of the left and right parts of the split. Since the vr type is a cancellative monoid, we can use stripPrefix and stripSuffix to compute the root measures: see splitl and splitr.

Note on time complexity: the log factor comes from split. Moreover, the log factor of the time complexity is determined by the smallest part of the split: the result of (min(i, n-i)) is either i or n-i, which are the lengths of the split parts.

Denotations for time complexity: n denotes the length of the input of the split. i denotes the length of left part of the split result. l denotes the left part of the split result. r denotes the right part of the split result. f denotes a SplitRootMeasure function. length denotes a function that computes the length of a finger tree.

splitSized :: (SuperMeasured vr vi a, Sized vi) => (vi -> Bool) -> StrictFingerTree vr vi a -> (StrictFingerTree vr vi a, StrictFingerTree vr vi a) Source #

O(log(min(i,n-i))) + O(min(i,n-i)). Specialisation of split that automatically determines whether i or n-i is smallest.

Note: a way to view splitSized is as being equivalent to a function that delegates to splitl or splitr based on whether i or n-i are smallest respectively.

splitl :: SuperMeasured vr vi a => (vi -> Bool) -> StrictFingerTree vr vi a -> (StrictFingerTree vr vi a, StrictFingerTree vr vi a) Source #

O(log(min(i,n-i))) + O(i). Specialisation of split that is fast if i is small.

splitr :: SuperMeasured vr vi a => (vi -> Bool) -> StrictFingerTree vr vi a -> (StrictFingerTree vr vi a, StrictFingerTree vr vi a) Source #

O(log(min(i,n-i))) + O(n-i). Specialisation of split that is fast if if i is large.

Maps

fmap' :: (SuperMeasured vr1 vi1 a1, SuperMeasured vr2 vi2 a2) => (a1 -> a2) -> StrictFingerTree vr1 vi1 a1 -> StrictFingerTree vr2 vi2 a2 Source #

Like fmap, but with constraints on the element types.

Note: vr2 is reconstructed in time linear in the size of the finger tree.

fmap'' :: (SuperMeasured vr1 vi1 a1, SuperMeasured vr2 vi2 a2) => (a1 -> a2) -> (vr1 -> vr2) -> StrictFingerTree vr1 vi1 a1 -> StrictFingerTree vr2 vi2 a2 Source #

Like fmap', but without the linear-time reconstruction of the root level measure.

Though similar to fmap', this function also requires a function parameter of root measures to root measures. This function ensures that we do not have to reconstruct vr2 from the elements of the finger tree.