pred-trie-0.0.2: src/Data/Trie/Pred/Unified.hs
module Data.Trie.Pred.Unified where
import Data.Trie.Pred.Unified.Norm
import qualified Data.Trie.Pred.Unified.Norm as NU
import Data.Monoid
data RPTrie t x = Rooted (Maybe x) [NUPTrie t x]
instance (Eq t) => Monoid (RPTrie t x) where
mempty = Rooted Nothing []
mappend = Data.Trie.Pred.Unified.merge
merge :: (Eq t) => RPTrie t x -> RPTrie t x -> RPTrie t x
merge (Rooted mx xs) (Rooted my ys) =
Rooted my $ foldr go [] $ xs ++ ys
where
go :: (Eq t) => NUPTrie t x -> [NUPTrie t x] -> [NUPTrie t x]
go a [] = [a]
go a (b:bs) | NU.areDisjoint a b = a : b : bs
| otherwise = (NU.merge a b) : bs