Portability | A lot of LANGUAGE extensions... |
---|---|
Stability | experimental |
Maintainer | Douglas Burke |
Safe Haskell | Safe-Infered |
This module defines a lookup table format and associated functions used by the graph matching code.
- class (Eq k, Show k) => LookupEntryClass a k v | a -> k, a -> v where
- data LookupMap a = LookupMap [a]
- emptyLookupMap :: LookupEntryClass a k v => LookupMap a
- makeLookupMap :: LookupEntryClass a k v => [a] -> LookupMap a
- listLookupMap :: LookupEntryClass a k v => LookupMap a -> [a]
- reverseLookupMap :: (LookupEntryClass a1 b c, LookupEntryClass a2 c b) => LookupMap a1 -> LookupMap a2
- keyOrder :: (LookupEntryClass a k v, Ord k) => a -> a -> Ordering
- mapFind :: LookupEntryClass a k v => v -> k -> LookupMap a -> v
- mapFindMaybe :: LookupEntryClass a k v => k -> LookupMap a -> Maybe v
- mapContains :: LookupEntryClass a k v => LookupMap a -> k -> Bool
- mapReplace :: LookupEntryClass a k v => LookupMap a -> a -> LookupMap a
- mapReplaceAll :: LookupEntryClass a k v => LookupMap a -> a -> LookupMap a
- mapReplaceMap :: LookupEntryClass a k v => LookupMap a -> LookupMap a -> LookupMap a
- mapAdd :: LookupMap a -> a -> LookupMap a
- mapAddIfNew :: LookupEntryClass a k v => LookupMap a -> a -> LookupMap a
- mapDelete :: LookupEntryClass a k v => LookupMap a -> k -> LookupMap a
- mapDeleteAll :: LookupEntryClass a k v => LookupMap a -> k -> LookupMap a
- mapEq :: (LookupEntryClass a k v, Eq v) => LookupMap a -> LookupMap a -> Bool
- mapKeys :: LookupEntryClass a k v => LookupMap a -> [k]
- mapVals :: (Eq v, LookupEntryClass a k v) => LookupMap a -> [v]
- mapMerge :: (LookupEntryClass a k v, Eq a, Show a, Ord k) => LookupMap a -> LookupMap a -> LookupMap a
Documentation
class (Eq k, Show k) => LookupEntryClass a k v | a -> k, a -> v whereSource
LookupEntryClass
defines essential functions of any datatype
that can be used to make a LookupMap
.
Minimal definition: newEntry
and keyVal
entryEq :: Eq v => a -> a -> BoolSource
entryShow :: Show v => a -> StringSource
kmap :: LookupEntryClass a2 k2 v => (k -> k2) -> a -> a2Source
vmap :: LookupEntryClass a2 k v2 => (v -> v2) -> a -> a2Source
Define a lookup map based on a list of values.
LookupMap [a] |
Functor LookupMap | |
Foldable LookupMap | |
Traversable LookupMap | |
Eq a => Eq (LookupMap a) | Define equality of (This is possibly a poor definition, as it is dependent on ordering of list members. But it passes all current test cases, and is used only for testing.) |
Show a => Show (LookupMap a) | Define Show instance for LookupMap based on Showing the list of entries. |
emptyLookupMap :: LookupEntryClass a k v => LookupMap aSource
Empty lookup map of arbitrary (i.e. polymorphic) type.
:: LookupEntryClass a k v | |
=> [a] | This list is not checked for duplicate entries, or entries with the same key but different values. |
-> LookupMap a |
Function to create a LookupMap
from a list of entries.
listLookupMap :: LookupEntryClass a k v => LookupMap a -> [a]Source
Returns a list of lookup map entries.
reverseLookupMap :: (LookupEntryClass a1 b c, LookupEntryClass a2 c b) => LookupMap a1 -> LookupMap a2Source
Given a lookup map, return a new map that can be used in the opposite direction of lookup.
keyOrder :: (LookupEntryClass a k v, Ord k) => a -> a -> OrderingSource
Given a pair of lookup entry values, return the ordering of their key values.
:: LookupEntryClass a k v | |
=> v | The default value. |
-> k | |
-> LookupMap a | |
-> v |
Find key in lookup map and return corresponding value, otherwise return default supplied.
mapFindMaybe :: LookupEntryClass a k v => k -> LookupMap a -> Maybe vSource
Find key in lookup map and return Just the corresponding value, otherwise return Nothing.
mapContains :: LookupEntryClass a k v => LookupMap a -> k -> BoolSource
Test to see if key is present in the supplied map
mapReplace :: LookupEntryClass a k v => LookupMap a -> a -> LookupMap aSource
Replace the first occurrence of a key a with a new key-value pair, or add a new key-value pair if the supplied key is not already present.
mapReplaceAll :: LookupEntryClass a k v => LookupMap a -> a -> LookupMap aSource
Replace all occurrence of a key a with a new key-value pair.
The resulting lookup map has the same form as the original in all other respects.
mapReplaceMap :: LookupEntryClass a k v => LookupMap a -> LookupMap a -> LookupMap aSource
Replace any occurrence of a key in the first argument with a corresponding key-value pair from the second argument, if present.
This could be implemented by multiple applications of mapReplaceAll
,
but is arranged differently so that only one new LookupMap
value is
created.
Note: keys in the new map that are not present in the old map are not included in the result map
mapAdd :: LookupMap a -> a -> LookupMap aSource
Add supplied key-value pair to the lookup map.
This is effectively an optimized case of mapReplace
or mapAddIfNew
,
where the caller guarantees to avoid duplicate key values.
mapAddIfNew :: LookupEntryClass a k v => LookupMap a -> a -> LookupMap aSource
Add supplied key-value pair to the lookup map, only if the key value is not already present.
mapDelete :: LookupEntryClass a k v => LookupMap a -> k -> LookupMap aSource
Delete the first occurrence of the key from the lookup map.
If the key does not exist in the map then no change is made.
mapDeleteAll :: LookupEntryClass a k v => LookupMap a -> k -> LookupMap aSource
Delete all occurrences of the key from the lookup map.
mapEq :: (LookupEntryClass a k v, Eq v) => LookupMap a -> LookupMap a -> BoolSource
Compare two lookup maps for equality.
Two maps are equal if they have the same set of keys, and if each key maps to an equivalent value. This is only guaranteed if the maps do not contain duplicate entries.
mapKeys :: LookupEntryClass a k v => LookupMap a -> [k]Source
Return the list of distinct keys in a supplied LookupMap
mapVals :: (Eq v, LookupEntryClass a k v) => LookupMap a -> [v]Source
Return list of distinct values in a supplied LookupMap