Skip to content

Instantly share code, notes, and snippets.

-- the following is for trie nodes where the source is smaller
insertNode contextNode@TrieNode{children=childNodes,nodeType=oldNodeType}
SourceIsSmallerDatum {pre=source,
suffixT= suffixStringOfTarget}
= contextNode{ wordFragment = source,
nodeType = Word,
children= slidNode *-> childNodes }
where slidNode = contextNode{wordFragment=suffixStringOfTarget,nodeType=oldNodeType}
-- the following is guaranteed not to have something at the child node as we
-- checked it above
insertNode contextNode@TrieNode{children=childNodes}
TargetIsSmallerDatum {pre=target,
suffixS= suffixStringOfSource}
= contextNode{ children=(insertNewChildWordNode suffixStringOfSource childNodes) }
insertNode contextNode ExactMatchDatum{} = switchToWord contextNode
data PrefixSuffixTree a = ExactMatchDatum { shared :: a } |
SharedPrefixDatum { shared :: a, suffixT :: a, suffixS :: a } |
TargetIsSmallerDatum { pre :: a, suffixS :: a } |
SourceIsSmallerDatum { pre :: a, suffixT :: a } |
NoMatchDatum deriving (Show,Eq)
data MatchType = TargetIsPrefix | SourceIsPrefix |
SharedPrefix | ExactMatch | NotEqual deriving (Show)
-- utility functions
switchToWord node = node{nodeType = Word}
data NodeType = Top|Word|NonWord
deriving (Show,Eq)
data TrieNode a = TrieNode { wordFragment :: [a], children :: (Map.Map a (TrieNode a)),
nodeType:: NodeType } deriving (Show,Eq)