Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
AtCoder.Extra.Seq.Raw
Description
Base module for implementing dynamic sequences. It internaly uses a splay tree and user has to track the root node change.
Since: 1.2.0.0
Synopsis
- data Seq s f a = Seq {}
- newST :: (Monoid f, Unbox f, Monoid a, Unbox a) => Int -> ST s (Seq s f a)
- resetST :: Seq s f a -> ST s ()
- newNodeST :: (HasCallStack, Monoid f, Unbox f, Unbox a) => Seq s f a -> a -> ST s Index
- newSeqST :: (HasCallStack, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Vector a -> ST s Index
- freeNodeST :: Seq s v a -> Index -> ST s ()
- freeSubtreeST :: Unbox a => Seq s f a -> Index -> ST s ()
- capacity :: Seq s f a -> Int
- lengthST :: Seq s f a -> Index -> ST s Int
- mergeST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Index -> ST s Index
- merge3ST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Index -> Index -> ST s Index
- merge4ST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Index -> Index -> Index -> ST s Index
- splitST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s (Index, Index)
- split3ST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> ST s (Index, Index, Index)
- split4ST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> Int -> ST s (Index, Index, Index, Index)
- splitLrST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> ST s (Index, Index, Index)
- sliceST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> ST s Index
- readST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s (a, Index)
- readMaybeST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s (Maybe (a, Index))
- writeST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> a -> ST s Index
- modifyST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> (a -> a) -> Int -> ST s Index
- exchangeST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> a -> ST s (a, Index)
- prodST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> ST s (a, Index)
- prodMaybeST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> ST s (Maybe (a, Index))
- prodAllST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> ST s a
- applyInST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> f -> ST s Index
- applyToRootST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> f -> ST s ()
- reverseST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> ST s Index
- insertST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> a -> ST s Index
- deleteST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s (a, Index)
- deleteST_ :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s Index
- detachST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s Index
- rotateST :: HasCallStack => Seq s v a -> Index -> ST s ()
- splayST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Bool -> ST s ()
- splayKthST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s Index
- ilowerBoundST :: (SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> (Int -> a -> Bool) -> ST s (Int, Index)
- ilowerBoundM :: (PrimMonad m, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq (PrimState m) f a -> Index -> (Int -> a -> m Bool) -> m (Int, Index)
- ilowerBoundProdST :: (SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> (Int -> a -> Bool) -> ST s (Int, Index)
- ilowerBoundProdM :: (PrimMonad m, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq (PrimState m) f a -> Index -> (Int -> a -> m Bool) -> m (Int, Index)
- isplitMaxRightST :: (SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> (Int -> a -> Bool) -> ST s (Index, Index)
- isplitMaxRightM :: (PrimMonad m, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq (PrimState m) f a -> Index -> (Int -> a -> m Bool) -> m (Index, Index)
- isplitMaxRightProdST :: (SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> (Int -> a -> Bool) -> ST s (Index, Index)
- isplitMaxRightProdM :: (PrimMonad m, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq (PrimState m) f a -> Index -> (Int -> a -> m Bool) -> m (Index, Index)
- imaxRightST :: (SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> (Int -> a -> Bool) -> ST s (Int, Index, Index)
- imaxRightM :: (PrimMonad m, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq (PrimState m) f a -> Index -> (Int -> a -> m Bool) -> m (Int, Index, Index)
- imaxRightProdST :: (SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> (Int -> a -> Bool) -> ST s (Int, Index, Index)
- imaxRightProdM :: (PrimMonad m, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq (PrimState m) f a -> Index -> (Int -> a -> m Bool) -> m (Int, Index, Index)
- freezeST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> ST s (Vector a)
- splitMaxRightWithST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> (Index -> ST s Bool) -> ST s (Index, Index)
- maxRightWithST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> (Index -> ST s Bool) -> ST s (Index, Index)
- updateNodeST :: (Monoid a, Unbox a) => Seq s f a -> Index -> ST s ()
- writeNodeST :: (Monoid a, Unbox a) => Seq s f a -> Index -> a -> ST s ()
- modifyNodeST :: (HasCallStack, Monoid a, Unbox a) => Seq s f a -> (a -> a) -> Index -> ST s ()
- exchangeNodeST :: (HasCallStack, Monoid a, Unbox a) => Seq s f a -> Index -> a -> ST s a
- propNodeST :: (HasCallStack, SegAct f a, Eq f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> ST s ()
- applyNodeST :: (HasCallStack, SegAct f a, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> f -> ST s ()
Seq
Storages of dynamic sequences of monoid values with monoid actions on them through the SegAct
instance.
Since: 1.2.0.0
Constructors
Seq | |
Fields
|
Constructors
newST :: (Monoid f, Unbox f, Monoid a, Unbox a) => Int -> ST s (Seq s f a) Source #
O(n) Creates a new Seq
of length n.
Since: 1.2.0.0
newNodeST :: (HasCallStack, Monoid f, Unbox f, Unbox a) => Seq s f a -> a -> ST s Index Source #
O(1) Allocates a new sequence of length 1.
Since: 1.2.0.0
newSeqST :: (HasCallStack, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Vector a -> ST s Index Source #
O(n) Allocates a new sequence.
Since: 1.2.0.0
freeSubtreeST :: Unbox a => Seq s f a -> Index -> ST s () Source #
O(n) Frees a subtree.
Since: 1.2.0.0
Metadata
capacity :: Seq s f a -> Int Source #
O(1) Returns the capacity of the sequence storage.
Since: 1.2.1.0
lengthST :: Seq s f a -> Index -> ST s Int Source #
O(1) Returns the length of a sequence or a subtree.
Since: 1.2.1.0
Merge/split
mergeST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Index -> ST s Index Source #
Amortized O(logn). Merges two sequences l,r into one in the given order, ignoring empty sequences.
Constraints
- The vertices must be either null or a root.
Since: 1.2.0.0
merge3ST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Index -> Index -> ST s Index Source #
Amortized O(logn). Merges three sequences l,m,r into one in the given order, ignoring empty sequences.
Constraints
- The vertices must be either null or a root.
Since: 1.2.0.0
merge4ST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Index -> Index -> Index -> ST s Index Source #
Amortized O(logn). Merges four sequences l,b,c,d,m,r into one in the given order, ignoring empty sequences.
Constraints
- The vertices must be either null or a root.
Since: 1.2.0.0
splitST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s (Index, Index) Source #
Amortized O(logn). Splits a sequences into two: [0,k),[k,n).
Constraints
- The node must be null or a root.
- 0≤k≤n.
Since: 1.2.0.0
split3ST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> ST s (Index, Index, Index) Source #
Amortized O(logn). Splits a sequences into three: [0,l),[l,r),[r,n).
Constraints
- The node must be null or a root.
- 0≤l≤r≤n.
Since: 1.2.0.0
split4ST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> Int -> ST s (Index, Index, Index, Index) Source #
Amortized O(logn). Splits a sequences into four: [0,i),[i,j),[j,k),[k,n).
Constraints
- The node must be null or a root.
- 0≤i≤j≤k≤n.
Since: 1.2.0.0
splitLrST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> ST s (Index, Index, Index) Source #
Amortized O(logn). Splits a sequence into three: [0,root),root,[root+1,n).
Constraints
- The node must be a root.
Since: 1.2.0.0
sliceST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> ST s Index Source #
Amortized O(logn). Captures the root of a subtree of [l,r). Splay the new root after call.
Constraints
- 0≤<r≤n. Note that the interval must have positive length.
Since: 1.2.0.0
Read/write
readST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s (a, Index) Source #
Amortized O(logn). Reads the k-th node's monoid value.
Constraints
- 0≤k<n
Since: 1.2.0.0
readMaybeST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s (Maybe (a, Index)) Source #
Amortized O(logn). Reads the k-th node's monoid value.
Constraints
- The root must be empty or a root.
Since: 1.2.0.0
writeST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> a -> ST s Index Source #
Amortized O(logn). Writes to the k-th node's monoid value.
Constraints
- The node must be a root.
- 0≤k<n
Since: 1.2.0.0
modifyST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> (a -> a) -> Int -> ST s Index Source #
Amortized O(logn). Modifies the k-th node's monoid value.
Constraints
- The node must be a root.
- 0≤k<n
Since: 1.2.0.0
exchangeST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> a -> ST s (a, Index) Source #
Amortized O(logn). Exchanges the k-th node's monoid value.
Constraints
- The node must be a root.
- 0≤k<n
Since: 1.2.0.0
Products
prodST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> ST s (a, Index) Source #
Amortized O(logn). Returns the monoid product in an interval [l,r).
Constraints
- The node must be a root
- 0≤l≤r≤n
Since: 1.2.0.0
prodMaybeST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> ST s (Maybe (a, Index)) Source #
Amortized O(logn). Returns the monoid product in an interval [l,r). Returns
Nothing
if an invalid interval is given or for an empty sequence.
Since: 1.2.0.0
prodAllST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> ST s a Source #
Amortized O(logn). Returns the monoid product of the whole sequence. Returns mempty
for an empty sequence.
Constraint
- The node must be null or a root.
Since: 1.2.0.0
Applications
applyInST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> f -> ST s Index Source #
Amortized O(logn). Given an interval [l,r), applies a monoid action f.
Constraints
- 0≤l≤r≤n
Since: 1.2.0.0
applyToRootST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> f -> ST s () Source #
O(1) Applies a monoid action f to the root of a sequence.
Since: 1.2.0.0
reverseST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> Int -> ST s Index Source #
Amortized O(logn). Reverses the sequence in [l,r).
Constraints
- The monoid action f must be commutative.
- The monoid value v must be commutative.
Since: 1.2.0.0
Insert/delete
insertST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> a -> ST s Index Source #
Amortized O(logn). Inserts a new node at k with initial monoid value v. This functions for an empty index.
Constraints
- The node must be null or a root.
- 0≤k≤n
Since: 1.2.0.0
deleteST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s (a, Index) Source #
Amortized O(logn). Frees the k-th node and returns the monoid value of it.
Constraints
- The node must be null or a root.
- 0≤k<n
Since: 1.2.0.0
deleteST_ :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s Index Source #
Amortized O(logn). Frees the k-th node.
Constraints
- The node must be null or a root.
- 0≤k<n
Since: 1.2.0.0
detachST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s Index Source #
Amortized O(logn). Detaches the k-th node and returns the new root of the original sequence.
Constraints
- The node must be null or a root.
- 0≤k<n
Since: 1.2.0.0
Balancing
rotateST :: HasCallStack => Seq s v a -> Index -> ST s () Source #
Amortized O(logn). Rotates a child node.
Constraints
- 0≤i<n
Since: 1.2.0.0
splayST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Bool -> ST s () Source #
Amortized O(logn). Moves up a node to be a root.
Since: 1.2.0.0
splayKthST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> Int -> ST s Index Source #
Amortized O(logn). Finds k-th node and splays it. Returns the new root.
Constraints
- 0≤k<n
Since: 1.2.0.0
Bisection methods
C++-like
Arguments
:: (SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq s f a | Sequence storage |
-> Index | Root node |
-> (Int -> a -> Bool) | User predicate f(i,vi) that takes the index and the monoid value |
-> ST s (Int, Index) | (r, root) |
Amortized O(logn).
Since: 1.2.0.0
Arguments
:: (PrimMonad m, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq (PrimState m) f a | Sequence storage |
-> Index | Root node |
-> (Int -> a -> m Bool) | User predicate f(i,vi) that takes the index and the monoid value |
-> m (Int, Index) | (r, root) |
Amortized O(logn).
Since: 1.2.0.0
Arguments
:: (SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq s f a | Sequence storage |
-> Index | Root node |
-> (Int -> a -> Bool) | User predicate f(i,v0…vi) that takes the index and the monoid product |
-> ST s (Int, Index) | (r, root) |
Amortized O(logn).
Constraints
- The node must be a root.
Since: 1.2.0.0
Arguments
:: (PrimMonad m, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq (PrimState m) f a | Sequence storage |
-> Index | Root node |
-> (Int -> a -> m Bool) | User predicate f(i,v0…vi) that takes the index and the monoid product |
-> m (Int, Index) | (r, root) |
Amortized O(logn).
Constraints
- The node must be a root.
Since: 1.2.0.0
Splits
Arguments
:: (SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq s f a | Sequence storage |
-> Index | Root node |
-> (Int -> a -> Bool) | User predicate f(i,vi) that takes the index and the monoid value |
-> ST s (Index, Index) | (left, right) sequences where f holds for the left |
Amortized O(logn). Given a monotonious sequence, returns the rightmost node vk where f(v) holds for every [0,i)(0≤i<k).
Since: 1.2.0.0
Arguments
:: (PrimMonad m, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq (PrimState m) f a | Sequence storage |
-> Index | Root node |
-> (Int -> a -> m Bool) | User predicate f(i,vi) that takes the index and the monoid value |
-> m (Index, Index) | (left, right) sequences where f holds for the left |
Amortized O(logn). Given a monotonious sequence, returns the rightmost node vk where f(v) holds for every [0,i)(0≤i<k).
Since: 1.2.0.0
Arguments
:: (SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq s f a | Sequence storage |
-> Index | Root node |
-> (Int -> a -> Bool) | User predicate f(i,v0…vi) that takes the index and the monoid value |
-> ST s (Index, Index) | (left, right) sequences where f holds for the left |
Amortized O(logn). Given a monotonious sequence, returns the rightmost node vk where f(v) holds for every [0,i)(0≤i<k).
Since: 1.2.0.0
Arguments
:: (PrimMonad m, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq (PrimState m) f a | Sequence storage |
-> Index | Root node |
-> (Int -> a -> m Bool) | User predicate f(i,vi) that takes the index and the monoid value | r |
-> m (Index, Index) | (left, right) sequences where f holds for the left |
Amortized O(logn). Given a monotonious sequence, returns the rightmost node vk where f(v) holds for every [0,i)(0≤i<k).
Since: 1.2.0.0
Max right
Arguments
:: (SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq s f a | Sequence storage |
-> Index | Root node |
-> (Int -> a -> Bool) | User predicate f(i,vi) that takes the index and the monoid value |
-> ST s (Int, Index, Index) | (r, left, right) |
Amortized O(logn). Given a monotonious sequence, returns the rightmost node v where f(v) holds for every vi(0≤i<k). Note that f works for a single node, not a monoid product.
Constraints
- The node must be a root.
Since: 1.2.0.0
Arguments
:: (PrimMonad m, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq (PrimState m) f a | Sequence storage |
-> Index | Root node |
-> (Int -> a -> m Bool) | User predicate f(i,vi) that takes the index and the monoid value |
-> m (Int, Index, Index) | (r, left, right) |
Amortized O(logn). Given a monotonious sequence, returns the rightmost node vk where f(v) holds for every vi(0≤i≤k). Note that f works for a single node, not a monoid product.
Constraints
- The node must be a root.
Since: 1.2.0.0
Arguments
:: (SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq s f a | Sequence storage |
-> Index | Root node |
-> (Int -> a -> Bool) | User predicate f(i,v0…vi) that takes the index and the monoid value |
-> ST s (Int, Index, Index) | (ilowerBound, rightmost node, new root) |
Amortized O(logn). Given a monotonious sequence, returns the rightmost node vk where f(v) holds for every [0,i)(0≤i<k).
Constraints
- The node must be a root.
Since: 1.2.0.0
Arguments
:: (PrimMonad m, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq (PrimState m) f a | Sequence storage |
-> Index | Root node |
-> (Int -> a -> m Bool) | User predicate f(i,v0…vi) that takes the index and the monoid value |
-> m (Int, Index, Index) | (ilowerBound, rightmost node, new root) |
Amortized O(logn). Given a monotonious sequence, returns the rightmost node vk where f(v) holds for every [0,i)(0≤i<k).
Constraints
- The node must be a root.
Since: 1.2.0.0
Conversions
freezeST :: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> ST s (Vector a) Source #
Amortized O(n). Returns the sequence of monoid values.
Since: 1.2.0.0
Internals
These functions are exported primarily for Map
implementations.
Arguments
:: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq s f a | Sequence storage |
-> Index | Root node |
-> (Index -> ST s Bool) | User predicate f(i) |
-> ST s (Index, Index) | (left, right) sequences where f holds for the left |
Amortized O(logn).
Since: 1.2.1.0
Arguments
:: (HasCallStack, SegAct f a, Eq f, Monoid f, Unbox f, Monoid a, Unbox a) | |
=> Seq s f a | Sequence storage |
-> Index | Root node |
-> (Index -> ST s Bool) | User predicate |
-> ST s (Index, Index) | (rightmost node, new root) |
Amortized O(logn). Given a monotonious sequence, returns the rightmost node vk where f(v) holds for every [0,i)(0≤i<k).
Constraints
- The node must be a root.
Since: 1.2.1.0
updateNodeST :: (Monoid a, Unbox a) => Seq s f a -> Index -> ST s () Source #
O(1) Recomputes the node size and the monoid product.
Since: 1.2.1.0
writeNodeST :: (Monoid a, Unbox a) => Seq s f a -> Index -> a -> ST s () Source #
O(1) Writes to the monoid value of a node.
Since: 1.2.1.0
modifyNodeST :: (HasCallStack, Monoid a, Unbox a) => Seq s f a -> (a -> a) -> Index -> ST s () Source #
O(1) Modifies the monoid value of a node.
Since: 1.2.1.0
exchangeNodeST :: (HasCallStack, Monoid a, Unbox a) => Seq s f a -> Index -> a -> ST s a Source #
O(1) Exchanges the monoid value of a node.
Since: 1.2.1.0
propNodeST :: (HasCallStack, SegAct f a, Eq f, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> ST s () Source #
Amortized O(logn). Propgates the lazily propagated values on a node.
Since: 1.2.1.0
applyNodeST :: (HasCallStack, SegAct f a, Unbox f, Monoid a, Unbox a) => Seq s f a -> Index -> f -> ST s () Source #
Amortized O(logn). Propgates at a node.
Since: 1.2.1.0