Safe Haskell | None |
---|---|
Language | Haskell98 |
The module implements directed acyclic word graphs (DAWGs) internaly represented as minimal acyclic deterministic finite-state automata. The implementation provides a fast insert operation which can be used to build the DAWG structure incrementaly.
Keys and values must provide an Enum
instance; see the
Ord
module if you look for a more generic solution.
- data DAWG a
- type ID = Int
- root :: DAWG a -> ID
- lookup :: Enum a => [a] -> DAWG a -> Maybe Val
- numStates :: DAWG a -> Int
- numEdges :: DAWG a -> Int
- value :: ID -> DAWG a -> Maybe Val
- edges :: Enum a => ID -> DAWG a -> [(a, ID)]
- follow :: Enum a => ID -> a -> DAWG a -> Maybe ID
- empty :: DAWG a
- fromList :: Enum a => [([a], Val)] -> DAWG a
- fromListWith :: Enum a => (Val -> Val -> Val) -> [([a], Val)] -> DAWG a
- fromLang :: Enum a => [[a]] -> DAWG a
- insert :: Enum a => [a] -> Val -> DAWG a -> DAWG a
- insertWith :: Enum a => (Val -> Val -> Val) -> [a] -> Val -> DAWG a -> DAWG a
- delete :: Enum a => [a] -> DAWG a -> DAWG a
- assocs :: Enum a => DAWG a -> [([a], Val)]
- keys :: Enum a => DAWG a -> [[a]]
- elems :: DAWG a -> [Val]
DAWG type
Query
Traversal
follow :: Enum a => ID -> a -> DAWG a -> Maybe ID Source
Follow the given transition from the given state.
Construction
fromList :: Enum a => [([a], Val)] -> DAWG a Source
Construct DAWG from the list of (word, value) pairs.
fromListWith :: Enum a => (Val -> Val -> Val) -> [([a], Val)] -> DAWG a Source
Construct DAWG from the list of (word, value) pairs with a combining function. The combining function is applied strictly.
fromLang :: Enum a => [[a]] -> DAWG a Source
Make DAWG from the list of words. Annotate each word with
the ()
value.
Insertion
insert :: Enum a => [a] -> Val -> DAWG a -> DAWG a Source
Insert the (key, value) pair into the DAWG.
insertWith :: Enum a => (Val -> Val -> Val) -> [a] -> Val -> DAWG a -> DAWG a Source
Insert with a function, combining new value and old value.
insertWith
f key value d will insert the pair (key, value) into d if
key does not exist in the DAWG. If the key does exist, the function
will insert the pair (key, f new_value old_value).