strict-containers-0.1.0.0: Various strict container types
Safe Haskell None
Language Haskell2010

Data.FingerTree.Strict

Description

Strict variants of FingerTree operations.

Synopsis

Documentation

data StrictFingerTree v a Source #

A newtype wrapper around a FingerTree , representing a finger tree that is strict in its values.

This strictness is not enforced at the type level, but rather by the construction functions in this module. These functions essentially just wrap the original Data.FingerTree functions while forcing the provided value to WHNF.

Instances

Instances details
Measured v a => Measured v ( StrictFingerTree v a) Source #
Instance details

Defined in Data.FingerTree.Strict

Foldable ( StrictFingerTree v) Source #
Instance details

Defined in Data.FingerTree.Strict

Eq a => Eq ( StrictFingerTree v a) Source #
Instance details

Defined in Data.FingerTree.Strict

Ord a => Ord ( StrictFingerTree v a) Source #
Instance details

Defined in Data.FingerTree.Strict

Show a => Show ( StrictFingerTree v a) Source #
Instance details

Defined in Data.FingerTree.Strict

NoThunks a => NoThunks ( StrictFingerTree v a) Source #
Instance details

Defined in Data.FingerTree.Strict

forceToStrict :: FingerTree v a -> StrictFingerTree v a Source #

Convert a FingerTree into a StrictFingerTree by forcing each element to WHNF.

Construction

empty :: Measured v a => StrictFingerTree v a Source #

O(1) . The empty sequence.

singleton :: Measured v a => a -> StrictFingerTree v a Source #

O(1) . A singleton sequence.

(<|) :: Measured v a => a -> StrictFingerTree v a -> StrictFingerTree v a infixr 5 Source #

O(1) . Add an element to the left end of a sequence. Mnemonic: a triangle with the single element at the pointy end.

(|>) :: Measured v a => StrictFingerTree v a -> a -> StrictFingerTree v 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.

(><) :: Measured v a => StrictFingerTree v a -> StrictFingerTree v a -> StrictFingerTree v a infixr 5 Source #

O(log(min(n1,n2))) . Concatenate two sequences.

fromList :: Measured v a => [a] -> StrictFingerTree v a Source #

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

Deconstruction

null :: StrictFingerTree v a -> Bool Source #

O(1) . Is this the empty sequence?

Examining the ends

viewl :: Measured v a => StrictFingerTree v a -> ViewL ( StrictFingerTree v) a Source #

O(1) . Analyse the left end of a sequence.

viewr :: Measured v a => StrictFingerTree v a -> ViewR ( StrictFingerTree v) a Source #

O(1) . Analyse the right end of a sequence.

Search

data SearchResult v a Source #

A result of search , attempting to find a point where a predicate on splits of the sequence changes from False to True .

Since: 0.1.2.0

Constructors

Position !( StrictFingerTree v a) !a !( StrictFingerTree v a)

A tree opened at a particular element: the prefix to the left, the element, and the suffix to the right.

OnLeft

A position to the left of the sequence, indicating that the predicate is True at both ends.

OnRight

A position to the right of the sequence, indicating that the predicate is False at both ends.

Nowhere

No position in the tree, returned if the predicate is True at the left end and False at the right end. This will not occur if the predicate in monotonic on the tree.

Instances

Instances details
Eq a => Eq ( SearchResult v a) Source #
Instance details

Defined in Data.FingerTree.Strict

Ord a => Ord ( SearchResult v a) Source #
Instance details

Defined in Data.FingerTree.Strict

Show a => Show ( SearchResult v a) Source #
Instance details

Defined in Data.FingerTree.Strict

Generic ( SearchResult v a) Source #
Instance details

Defined in Data.FingerTree.Strict

Associated Types

type Rep ( SearchResult v a) :: Type -> Type Source #

type Rep ( SearchResult v a) Source #
Instance details

Defined in Data.FingerTree.Strict

search :: Measured v a => (v -> v -> Bool ) -> StrictFingerTree v a -> SearchResult v a Source #

O(log(min(i,n-i))) . Search a sequence for a point where a predicate on splits of the sequence changes from False to True .

The argument p is a relation between the measures of the two sequences that could be appended together to form the sequence t . If the relation is False at the leftmost split and True at the rightmost split, i.e.

not (p mempty (measure t)) && p (measure t) mempty

then there must exist an element x in the sequence such that p is False for the split immediately before x and True for the split just after it:

In this situation, search p t returns such an element x and the pieces l and r of the sequence to its left and right respectively. That is, it returns Position l x r such that

  • l >< (x <| r) = t
  • not (p (measure l) (measure (x <| r))
  • p (measure (l |> x)) (measure r)

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

Since: 0.1.2.0

Splitting

These functions are special cases of search .

split :: Measured v a => (v -> Bool ) -> StrictFingerTree v a -> ( StrictFingerTree v a, StrictFingerTree v a) Source #

O(log(min(i,n-i))) . Split a sequence at a point where the predicate on the accumulated 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 .

takeUntil :: Measured v a => (v -> Bool ) -> StrictFingerTree v a -> StrictFingerTree v a Source #

O(log(min(i,n-i))) . Given a monotonic predicate p , takeUntil p t is the largest prefix of t whose measure does not satisfy p .

dropUntil :: Measured v a => (v -> Bool ) -> StrictFingerTree v a -> StrictFingerTree v a Source #

O(log(min(i,n-i))) . Given a monotonic predicate p , dropUntil p t is the rest of t after removing the largest prefix whose measure does not satisfy p .

Transformation

reverse :: Measured v a => StrictFingerTree v a -> StrictFingerTree v a Source #

O(n) . The reverse of a sequence.

Maps

fmap' :: ( Measured v1 a1, Measured v2 a2) => (a1 -> a2) -> StrictFingerTree v1 a1 -> StrictFingerTree v2 a2 Source #

Like fmap , but with constraints on the element types.

unsafeFmap :: (a -> b) -> StrictFingerTree v a -> StrictFingerTree v b Source #

Like fmap , but safe only if the function preserves the measure.

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

Things that can be measured.

Methods

measure :: a -> v Source #

Instances

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

Defined in Data.FingerTree

Methods

measure :: Digit a -> v Source #

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

Defined in Data.FingerTree.Strict

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

Defined in Data.FingerTree

Methods

measure :: Node v a -> v Source #

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

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

Instance details

Defined in Data.FingerTree

data ViewL (s :: Type -> Type ) a Source #

View of the left end of a sequence.

Constructors

EmptyL

empty sequence

a :< (s a) infixr 5

leftmost element and the rest of the sequence

Instances

Instances details
Functor s => Functor ( ViewL s)
Instance details

Defined in Data.FingerTree

Methods

fmap :: (a -> b) -> ViewL s a -> ViewL s b Source #

(<$) :: a -> ViewL s b -> ViewL s a Source #

( Eq a, Eq (s a)) => Eq ( ViewL s a)
Instance details

Defined in Data.FingerTree

( Ord a, Ord (s a)) => Ord ( ViewL s a)
Instance details

Defined in Data.FingerTree

( Read a, Read (s a)) => Read ( ViewL s a)
Instance details

Defined in Data.FingerTree

( Show a, Show (s a)) => Show ( ViewL s a)
Instance details

Defined in Data.FingerTree

Generic ( ViewL s a)
Instance details

Defined in Data.FingerTree

Associated Types

type Rep ( ViewL s a) :: Type -> Type Source #

type Rep ( ViewL s a)
Instance details

Defined in Data.FingerTree

data ViewR (s :: Type -> Type ) a Source #

View of the right end of a sequence.

Constructors

EmptyR

empty sequence

(s a) :> a infixl 5

the sequence minus the rightmost element, and the rightmost element

Instances

Instances details
Functor s => Functor ( ViewR s)
Instance details

Defined in Data.FingerTree

Methods

fmap :: (a -> b) -> ViewR s a -> ViewR s b Source #

(<$) :: a -> ViewR s b -> ViewR s a Source #

( Eq a, Eq (s a)) => Eq ( ViewR s a)
Instance details

Defined in Data.FingerTree

( Ord a, Ord (s a)) => Ord ( ViewR s a)
Instance details

Defined in Data.FingerTree

( Read a, Read (s a)) => Read ( ViewR s a)
Instance details

Defined in Data.FingerTree

( Show a, Show (s a)) => Show ( ViewR s a)
Instance details

Defined in Data.FingerTree

Generic ( ViewR s a)
Instance details

Defined in Data.FingerTree

Associated Types

type Rep ( ViewR s a) :: Type -> Type Source #

type Rep ( ViewR s a)
Instance details

Defined in Data.FingerTree