Agda-2.5.2: A dependently typed functional programming language and proof assistant

Safe Haskell | None
Language | Haskell2010

Agda.Utils.Trie

Description

Strict tries (based on Data.Map.Strict and Agda.Utils.Maybe.Strict).

Synopsis

- data Trie k v
- empty :: Null a => a
- singleton :: [k] -> v -> Trie k v
- everyPrefix :: [k] -> v -> Trie k v
- insert :: Ord k => [k] -> v -> Trie k v -> Trie k v
- insertWith :: Ord k => (v -> v -> v) -> [k] -> v -> Trie k v -> Trie k v
- union :: Ord k => Trie k v -> Trie k v -> Trie k v
- unionWith :: Ord k => (v -> v -> v) -> Trie k v -> Trie k v -> Trie k v
- adjust :: Ord k => [k] -> (Maybe v -> Maybe v) -> Trie k v -> Trie k v
- delete :: Ord k => [k] -> Trie k v -> Trie k v
- toList :: Ord k => Trie k v -> [([k], v)]
- toAscList :: Ord k => Trie k v -> [([k], v)]
- lookup :: Ord k => [k] -> Trie k v -> Maybe v
- member :: Ord k => [k] -> Trie k v -> Bool
- lookupPath :: Ord k => [k] -> Trie k v -> [v]
- lookupTrie :: Ord k => [k] -> Trie k v -> Trie k v

# Documentation

data Trie k v #

Finite map from `[k]` to `v`.

With the strict `Maybe` type, `Trie` is also strict in `v`.

Instances

Functor (Trie k) # |
Methods fmap :: (a -> b) -> Trie k a -> Trie k b # (<$) :: a -> Trie k b -> Trie k a #
Foldable (Trie k) # |
Methods fold :: Monoid m => Trie k m -> m # foldMap :: Monoid m => (a -> m) -> Trie k a -> m # foldr :: (a -> b -> b) -> b -> Trie k a -> b # foldr' :: (a -> b -> b) -> b -> Trie k a -> b # foldl :: (b -> a -> b) -> b -> Trie k a -> b # foldl' :: (b -> a -> b) -> b -> Trie k a -> b # foldr1 :: (a -> a -> a) -> Trie k a -> a # foldl1 :: (a -> a -> a) -> Trie k a -> a # toList :: Trie k a -> [a] # null :: Trie k a -> Bool # length :: Trie k a -> Int # elem :: Eq a => a -> Trie k a -> Bool # maximum :: Ord a => Trie k a -> a # minimum :: Ord a => Trie k a -> a # sum :: Num a => Trie k a -> a # product :: Num a => Trie k a -> a #
(Eq k, Eq v) => Eq (Trie k v) # |
Methods (==) :: Trie k v -> Trie k v -> Bool # (/=) :: Trie k v -> Trie k v -> Bool #
(Show k, Show v) => Show (Trie k v) # |
Methods showsPrec :: Int -> Trie k v -> ShowS # show :: Trie k v -> String # showList :: [Trie k v] -> ShowS #
Null (Trie k v) # | Empty trie.
Methods empty :: Trie k v # null :: Trie k v -> Bool #

empty :: Null a => a #

singleton :: [k] -> v -> Trie k v #

Singleton trie.

everyPrefix :: [k] -> v -> Trie k v #

`everyPrefix k v` is a trie where every prefix of `k` (including `k` itself) is mapped to `v`.

insert :: Ord k => [k] -> v -> Trie k v -> Trie k v #

Insert. Overwrites existing value if present.

    insert = insertWith ( new old -> new)

insertWith :: Ord k => (v -> v -> v) -> [k] -> v -> Trie k v -> Trie k v #

Insert with function merging new value with old value.

union :: Ord k => Trie k v -> Trie k v -> Trie k v #

Left biased union.

`union = unionWith ( new old -> new)`.

unionWith :: Ord k => (v -> v -> v) -> Trie k v -> Trie k v -> Trie k v #

Pointwise union with merge function for values.

adjust :: Ord k => [k] -> (Maybe v -> Maybe v) -> Trie k v -> Trie k v #

Adjust value at key, leave subtree intact.

delete :: Ord k => [k] -> Trie k v -> Trie k v #

Delete value at key, but leave subtree intact.

toList :: Ord k => Trie k v -> [([k], v)] #

Convert to ascending list.

toAscList :: Ord k => Trie k v -> [([k], v)] #

Convert to ascending list.

lookup :: Ord k => [k] -> Trie k v -> Maybe v #

Returns the value associated with the given key, if any.

member :: Ord k => [k] -> Trie k v -> Bool #

Is the given key present in the trie?

lookupPath :: Ord k => [k] -> Trie k v -> [v] #

Collect all values along a given path.

lookupTrie :: Ord k => [k] -> Trie k v -> Trie k v #

Get the subtrie rooted at the given key.