| Copyright | (c) Edward Kmett 2017 (c) Ross Paterson Ralf Hinze 2006 |
|---|---|
| License | BSD-style |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Coda.FingerTree
Description
- data FingerTree a
- class Monoid (Measure a) => Measured a where
- empty :: FingerTree a
- singleton :: a -> FingerTree a
- fromList :: IsList l => [Item l] -> l
- data SearchResult a
- = Position (FingerTree a) a (FingerTree a)
- | OnLeft
- | OnRight
- | Nowhere
- search :: Measured a => (Measure a -> Measure a -> Bool) -> FingerTree a -> SearchResult a
- split :: Measured a => (Measure a -> Bool) -> FingerTree a -> (FingerTree a, FingerTree a)
- takeUntil :: Measured a => (Measure a -> Bool) -> FingerTree a -> FingerTree a
- dropUntil :: Measured a => (Measure a -> Bool) -> FingerTree a -> FingerTree a
- reverse :: Measured a => FingerTree a -> FingerTree a
- fmap' :: Measured b => (a -> b) -> FingerTree a -> FingerTree b
- fmapWithPos :: (Measured a, Measured b) => (Measure a -> a -> b) -> FingerTree a -> FingerTree b
- fmapWithContext :: (Measured a, Measured b) => (Measure a -> a -> Measure a -> b) -> FingerTree a -> FingerTree b
- unsafeFmap :: Measure a ~ Measure b => (a -> b) -> FingerTree a -> FingerTree b
- traverse' :: (Measured b, Applicative f) => (a -> f b) -> FingerTree a -> f (FingerTree b)
- traverseWithPos :: (Measured a, Measured b, Applicative f) => (Measure a -> a -> f b) -> FingerTree a -> f (FingerTree b)
- traverseWithContext :: (Measured a, Measured b, Applicative f) => (Measure a -> a -> Measure a -> f b) -> FingerTree a -> f (FingerTree b)
- unsafeTraverse :: (Measure a ~ Measure b, Applicative f) => (a -> f b) -> FingerTree a -> f (FingerTree b)
Documentation
data FingerTree a Source #
A representation of a sequence of values of type a, allowing
access to the ends in constant time, and append and split in time
logarithmic in the size of the smaller piece.
A variety of abstract data types can be implemented by using different element types and measurements.
Instances
| Foldable FingerTree Source # | Elements from left to right. |
| Measured a => IsList (FingerTree a) Source # | |
| Eq a => Eq (FingerTree a) Source # | |
| Ord a => Ord (FingerTree a) Source # | |
| Show a => Show (FingerTree a) Source # | |
| Measured a => Semigroup (FingerTree a) Source # | O(log(min(n1,n2))). Concatenate two sequences. |
| Measured a => Monoid (FingerTree a) Source # | |
| AsEmpty (FingerTree a) Source # | |
| Default (FingerTree a) Source # | |
| Measured a => Measured (FingerTree a) Source # | O(1). The cached measure of a tree. |
| (Measured a, HasMonoidalDelta (Measure a)) => HasMonoidalDelta (FingerTree a) Source # | |
| (Measured a, HasDelta (Measure a)) => HasDelta (FingerTree a) Source # | |
| Strippable (FingerTree Text) Source # | |
| Splittable a => Splittable (FingerTree a) Source # | |
| (Measured a, Measured b) => Snoc (FingerTree a) (FingerTree b) a b Source # | |
| (Measured a, Measured b) => Cons (FingerTree a) (FingerTree b) a b Source # | |
| type Item (FingerTree a) Source # | |
| type Measure (FingerTree a) Source # | |
class Monoid (Measure a) => Measured a where Source #
Things that can be measured.
Minimal complete definition
Construction
empty :: FingerTree a Source #
O(1). The empty sequence.
singleton :: a -> FingerTree a Source #
O(1). A singleton sequence.
fromList :: IsList l => [Item l] -> l #
The fromList function constructs the structure l from the given
list of Item l
Deconstruction
Search
data SearchResult a Source #
A result of search, attempting to find a point where a predicate
on splits of the sequence changes from False to True.
Constructors
| Position (FingerTree a) a (FingerTree 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 |
| OnRight | A position to the right of the sequence, indicating that the
predicate is |
| Nowhere | No position in the tree, returned if the predicate is |
Instances
| Eq a => Eq (SearchResult a) Source # | |
| Ord a => Ord (SearchResult a) Source # | |
| Show a => Show (SearchResult a) Source # | |
search :: Measured a => (Measure a -> Measure a -> Bool) -> FingerTree a -> SearchResult 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 (pmempty(measuret)) && p (measuret)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, returns such an element search p tx and the
pieces l and r of the sequence to its left and right respectively.
That is, it returns such thatPosition l x r
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.
Splitting
These functions are special cases of search.
split :: Measured a => (Measure a -> Bool) -> FingerTree a -> (FingerTree a, FingerTree a) Source #
takeUntil :: Measured a => (Measure a -> Bool) -> FingerTree a -> FingerTree a Source #
dropUntil :: Measured a => (Measure a -> Bool) -> FingerTree a -> FingerTree a Source #
Transformation
reverse :: Measured a => FingerTree a -> FingerTree a Source #
O(n). The reverse of a sequence.
Maps
fmap' :: Measured b => (a -> b) -> FingerTree a -> FingerTree b Source #
Like fmap, but with constraints on the element types.
fmapWithPos :: (Measured a, Measured b) => (Measure a -> a -> b) -> FingerTree a -> FingerTree b Source #
Map all elements of the tree with a function that also takes the measure of the prefix of the tree to the left of the element.
fmapWithContext :: (Measured a, Measured b) => (Measure a -> a -> Measure a -> b) -> FingerTree a -> FingerTree b Source #
Map all elements of the tree with a function that also takes the measure of the prefix to the left and of the suffix to the right of the element.
unsafeFmap :: Measure a ~ Measure b => (a -> b) -> FingerTree a -> FingerTree b Source #
Like fmap, but safe only if the function preserves the measure.
Traversals
traverse' :: (Measured b, Applicative f) => (a -> f b) -> FingerTree a -> f (FingerTree b) Source #
Like traverse, but with constraints on the element types.
traverseWithPos :: (Measured a, Measured b, Applicative f) => (Measure a -> a -> f b) -> FingerTree a -> f (FingerTree b) Source #
Traverse the tree from left to right with a function that also takes the measure of the prefix of the tree to the left of the element.
traverseWithContext :: (Measured a, Measured b, Applicative f) => (Measure a -> a -> Measure a -> f b) -> FingerTree a -> f (FingerTree b) Source #
Traverse the tree from left to right with a function that also takes the measure of the prefix to the left and the measure of the suffix to the right of the element.
unsafeTraverse :: (Measure a ~ Measure b, Applicative f) => (a -> f b) -> FingerTree a -> f (FingerTree b) Source #
Like traverse, but safe only if the function preserves the measure.