iota-0.1.0.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Data.Graph.Tree.LCT

Synopsis

Documentation

data LCT s a Source #

for commutative monoids

Constructors

LCT 

Fields

newLCT :: (Unbox a, Monoid a, PrimMonad m) => Int -> m (LCT (PrimState m) a) Source #

buildLCT :: (Unbox a, Monoid a, PrimMonad m) => Vector a -> m (LCT (PrimState m) a) Source #

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 #

Constructors

SplayNodeId 

Fields

Instances

Instances details
Enum SplayNodeId Source # 
Instance details

Defined in Data.Graph.Tree.LCT

Num SplayNodeId Source # 
Instance details

Defined in Data.Graph.Tree.LCT

Integral SplayNodeId Source # 
Instance details

Defined in Data.Graph.Tree.LCT

Real SplayNodeId Source # 
Instance details

Defined in Data.Graph.Tree.LCT

Show SplayNodeId Source # 
Instance details

Defined in Data.Graph.Tree.LCT

Eq SplayNodeId Source # 
Instance details

Defined in Data.Graph.Tree.LCT

Ord SplayNodeId Source # 
Instance details

Defined in Data.Graph.Tree.LCT

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 #

pullLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> SplayNodeId -> m () Source #

pushLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> SplayNodeId -> m () Source #

traverseDownLCT :: (Unbox a, Monoid a, PrimMonad m) => (SplayNodeId -> m ()) -> LCT (PrimState m) a -> SplayNodeId -> m () Source #

from the splay tree root to v

rotateRightLCT Source #

Arguments

:: (Unbox a, Monoid a, PrimMonad m) 
=> LCT (PrimState m) a 
-> SplayNodeId

has pasrent node

-> m () 

rotateLeftLCT Source #

Arguments

:: (Unbox a, Monoid a, PrimMonad m) 
=> LCT (PrimState m) a 
-> SplayNodeId

has parent node

-> m () 

splayLCT :: (Unbox a, Monoid a, PrimMonad m) => LCT (PrimState m) a -> SplayNodeId -> m () Source #

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