module Data.Queue.TrieQueue.TrieLabel where
import Data.Sequence (Seq, ViewL(..), viewl, (><), (<|), (|>))
import qualified Data.Sequence as Seq
import qualified Data.Foldable as Fold
type Split e x = Label e
-> e -> Label e
-> e -> Label e
-> x
type Tail e x = e -> Label e
-> x
merging :: Eq e => Label e
-> Label e
-> Split e x
-> Tail e x
-> Tail e x
-> x
-> x
cons :: e -> Label e -> Label e
labelToList :: Label e -> [e]
labelFromList :: [e] -> Label e
merging xs0 ys0 split xEnd yEnd xy = merging' 0 xs0 ys0 where
merging' n xs ys = let pfx = take n xs0 in case (xs, ys) of
(x:xs, y:ys) | x == y -> merging' (n+1) xs ys
| otherwise -> split pfx x xs y ys
(x:xs, []) -> yEnd x xs
([], y:ys) -> xEnd y ys
([], []) -> xy
type Label e = [e]
cons = (:)
labelToList = id
labelFromList = id
testMerging :: (Eq e, Show e) => Label e -> Label e -> String
testMerging xs0 ys0 = merging xs0 ys0 (\ pfx x xs y ys -> "Split " ++ show pfx ++ " (" ++ show x ++ " -> " ++ show xs ++ ") (" ++ show y ++ " -> " ++ show ys ++ ")")
(\ y ys -> "Break " ++ show xs0 ++ " = " ++ show y ++ " -> " ++ show ys)
(\ x xs -> "Break " ++ show ys0 ++ " = " ++ show x ++ " -> " ++ show xs)
("Equal " ++ show xs0)