Safe Haskell | None |
---|---|
Language | Haskell2010 |
Prefix trees on arbitrary keys.
Synopsis
- data Trie k v = Trie {}
- empty :: Trie k v
- singleton :: Hashable k => [k] -> v -> Trie k v
- lookup :: (Eq k, Hashable k) => [k] -> Trie k v -> Maybe v
- insert :: (Eq k, Hashable k) => [k] -> v -> Trie k v -> Trie k v
- insertWith :: (Eq k, Hashable k) => (v -> v -> v) -> [k] -> v -> Trie k v -> Trie k v
- elems :: Trie k v -> [v]
Documentation
Data structure for storing a value v
keyed on a sequence of k
s
Instances
(Eq k, Eq v) => Eq (Trie k v) Source # | |
(Ord k, Ord v) => Ord (Trie k v) Source # | |
(Show k, Show v) => Show (Trie k v) Source # | |
Generic (Trie k v) Source # | |
(Eq k, Hashable k, Semigroup v) => Semigroup (Trie k v) Source # | Semigroup via union.
The resulting |
(Eq k, Hashable k, Semigroup v) => Monoid (Trie k v) Source # | |
(ToJSONKey a, ToJSON v) => ToJSON (Trie a v) Source # | |
Defined in Data.Trie toEncoding :: Trie a v -> Encoding toJSONList :: [Trie a v] -> Value toEncodingList :: [Trie a v] -> Encoding | |
type Rep (Trie k v) Source # | |
Defined in Data.Trie type Rep (Trie k v) = D1 ('MetaData "Trie" "Data.Trie" "graphql-engine-1.0.0-inplace" 'False) (C1 ('MetaCons "Trie" 'PrefixI 'True) (S1 ('MetaSel ('Just "trieMap") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (HashMap k (Trie k v))) :*: S1 ('MetaSel ('Just "trieData") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe v)))) |
singleton :: Hashable k => [k] -> v -> Trie k v Source #
Creates a trie from a path and a value
>>>
singleton ["a", "b"] 5
Trie (fromList [("a", Trie (fromList [("b", Trie (fromList []) (Just 5))]) Nothing)]) Nothing
>>>
singleton [] 5
Trie (fromList []) (Just 5)
lookup :: (Eq k, Hashable k) => [k] -> Trie k v -> Maybe v Source #
Find a value at the given path, if any.
insert :: (Eq k, Hashable k) => [k] -> v -> Trie k v -> Trie k v Source #
Insert the given value at the given path.
If there's already a value at the given path, it is replaced.