Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- data LCT s a = LCT {
- parentLCT :: MVector s Int32
- leftChildLCT :: MVector s Int32
- rightChildLCT :: MVector s Int32
- commMonoidLCT :: MVector s a
- foldSubtreesLCT :: MVector s a
- lazyRevFlagLCT :: MVector s Bool
- newLCT :: (Unbox a, Monoid a, PrimMonad m) => Int -> m (LCT (PrimState m) a)
- buildLCT :: (Unbox a, Monoid a, PrimMonad m) => Vector a -> m (LCT (PrimState m) a)
- evertLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> m ()
- cutLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> Int -> m ()
- linkLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> Int -> m ()
- mconcatPathLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> Int -> m a
- findRootLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> m Int
- setCMonLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> a -> m ()
- lcaLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> Int -> m Int
- newtype SplayNodeId = SplayNodeId {}
- asSplayNodeId :: Int -> SplayNodeId
- getLeftChildLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> m SplayNodeId
- getRightChildLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> m SplayNodeId
- getParentLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> m SplayNodeId
- setLeftChildLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> SplayNodeId -> m ()
- setRightChildLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> SplayNodeId -> m ()
- setParentLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> SplayNodeId -> m ()
- nothingLCT :: SplayNodeId
- isSplayTreeRootLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> m Bool
- pullLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> SplayNodeId -> m ()
- pushLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> SplayNodeId -> m ()
- traverseDownLCT :: (Unbox a, Monoid a, PrimMonad m) => (SplayNodeId -> m ()) -> LCT (PrimState m) a -> SplayNodeId -> m ()
- rotateRightLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> SplayNodeId -> m ()
- rotateLeftLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> SplayNodeId -> m ()
- splayLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> SplayNodeId -> m ()
- exposeLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> SplayNodeId -> m SplayNodeId
Documentation
for commutative monoids
LCT | |
|
evertLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> m () Source #
make v root
>>>
lct <- newLCT @() 3
>>>
linkLCT lct 1 0 >> linkLCT lct 2 1
>>>
findRootLCT lct 2
0>>>
evertLCT lct 1
>>>
findRootLCT lct 2
1
cutLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> Int -> m () Source #
require: the edge (u, v)
exists
linkLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> Int -> m () Source #
link u to v
require: u
and v
are *not connected*
mconcatPathLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> Int -> m a Source #
require: l
and r
connected
>>>
import Data.Monoid
>>>
lct <- buildLCT @(Sum Int) $ U.fromList $ map Sum [0..3]
>>>
linkLCT lct 1 0 >> linkLCT lct 2 1 >> linkLCT lct 3 1
>>>
mconcatPathLCT lct 0 1
Sum {getSum = 1}>>>
mconcatPathLCT lct 2 3 -- 2 - 1 - 3
Sum {getSum = 6}>>>
mconcatPathLCT lct 0 3 -- 0 - 1 - 3
Sum {getSum = 4}
findRootLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> m Int Source #
root is the left most node of the root path
setCMonLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> a -> m () Source #
commutative monoids
>>>
import Data.Monoid
>>>
lct <- buildLCT @(Sum Int) $ U.fromList $ map Sum [0..2]
>>>
linkLCT lct 1 0 >> linkLCT lct 2 1
>>>
mconcatPathLCT lct 0 2
Sum {getSum = 3}>>>
setCMonLCT lct 1 (Sum 100)
>>>
mconcatPathLCT lct 0 2
Sum {getSum = 102}
lcaLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> Int -> Int -> m Int Source #
require: u and v are connected
>>>
lct <- newLCT @() 4
>>>
linkLCT lct 1 0 >> linkLCT lct 2 1 >> linkLCT lct 3 2
>>>
evertLCT lct 0
>>>
lcaLCT lct 0 3
0>>>
evertLCT lct 2
>>>
lcaLCT lct 0 3
2
newtype SplayNodeId Source #
Instances
asSplayNodeId :: Int -> SplayNodeId Source #
getLeftChildLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> m SplayNodeId Source #
getRightChildLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> m SplayNodeId Source #
getParentLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> m SplayNodeId Source #
setLeftChildLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> SplayNodeId -> m () Source #
setRightChildLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> SplayNodeId -> m () Source #
setParentLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> SplayNodeId -> m () Source #
isSplayTreeRootLCT :: PrimMonad m => LCT (PrimState m) a -> SplayNodeId -> m Bool Source #
traverseDownLCT :: (Unbox a, Monoid a, PrimMonad m) => (SplayNodeId -> m ()) -> LCT (PrimState m) a -> SplayNodeId -> m () Source #
from the splay tree root to v
:: (Unbox a, Monoid a, PrimMonad m) | |
=> LCT (PrimState m) a | |
-> SplayNodeId | has pasrent node |
-> m () |
:: (Unbox a, Monoid a, PrimMonad m) | |
=> LCT (PrimState m) a | |
-> SplayNodeId | has parent node |
-> m () |
exposeLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> SplayNodeId -> m SplayNodeId Source #
make v on the root path
properties
* v
is the root of the splay tree.
* v
is the right most node of the root path.
* expose u >> expose v == lca u v
.
>>>
lct <- newLCT @() 2
>>>
linkLCT lct 0 1
>>>
evertLCT lct 0
>>>
exposeLCT lct 1
1>>>
isSplayTreeRootLCT lct 1
True>>>
findRootLCT lct 1
0