Agda
Safe HaskellNone
LanguageHaskell2010

Agda.Utils.CompressedTrie

Description

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

In contrast to Agda.Utils.Trie, branches from a node can be labeled with non-empty lists of keys that do not overlap, meaning they start with different first elements. This way, non-branching unlabelled pathes can be stored more efficiently.

As a side effect, the notion of height changes which we utilize in the truncate function.

An Trie is usually constructed from an Trie via the compress function.

Synopsis

Documentation

data Trie k v Source #

Finite map from [k] to v.

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

Invariant: only the root of the tree may be of the form Trie Nothing (Map.singleton ks t). A node inside of the trie of that form must be fused into its branch.

Constructors

Trie 

Fields

Instances

Instances details
Functor (Trie k) Source # 
Instance details

Defined in Agda.Utils.CompressedTrie

Methods

fmap :: (a -> b) -> Trie k a -> Trie k b #

(<$) :: a -> Trie k b -> Trie k a #

Foldable (Trie k) Source # 
Instance details

Defined in Agda.Utils.CompressedTrie

Methods

fold :: Monoid m => Trie k m -> m #

foldMap :: Monoid m => (a -> m) -> Trie k a -> 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 #

Null (Trie k v) Source #

Empty trie.

Instance details

Defined in Agda.Utils.CompressedTrie

Methods

empty :: Trie k v Source #

null :: Trie k v -> Bool Source #

(NFData k, NFData v) => NFData (Trie k v) Source # 
Instance details

Defined in Agda.Utils.CompressedTrie

Methods

rnf :: Trie k v -> () #

(Show v, Show k) => Show (Trie k v) Source # 
Instance details

Defined in Agda.Utils.CompressedTrie

Methods

showsPrec :: Int -> Trie k v -> ShowS #

show :: Trie k v -> String #

showList :: [Trie k v] -> ShowS #

(Eq v, Eq k) => Eq (Trie k v) Source # 
Instance details

Defined in Agda.Utils.CompressedTrie

Methods

(==) :: Trie k v -> Trie k v -> Bool #

(/=) :: Trie k v -> Trie k v -> Bool #

Singleton ([k], v) (Trie k v) Source # 
Instance details

Defined in Agda.Utils.CompressedTrie

Methods

singleton :: ([k], v) -> Trie k v Source #

Construction

root :: v -> Trie k v Source #

Singleton tree with value at the root.

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

Singleton trie.

singleton1 :: List1 k -> v -> Trie k v Source #

Singleton tree with empty root.

singleBranch :: List1 k -> Trie k v -> (List1 k, Trie k v) Source #

A single branch with the given subtree. Precondition: the given subtree has a value at the root.

isSingleBranch :: Trie k v -> Maybe (List1 k, Trie k v) Source #

Is the trie starting with a single branch?

compress :: Ord k => Trie k v -> Trie k v Source #

Turn a trie into a compressed trie.

Deconstruction

uncompress :: Ord k => Trie k v -> Trie k v Source #

Turn a compressed trie into an uncompressed trie.

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

Convert to ascending list.

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

Convert to ascending list.

size :: Trie k v -> Int Source #

The number of labeled nodes.

sizeWithLeaves :: Trie k v -> Int Source #

The number of nodes that are labeled or leaves..

Modification

substLeaves :: (Maybe v -> Trie k v) -> Trie k v -> Trie k v Source #

Modify the leaves (input and output may be non-canonical).

truncate :: Int -> Trie k v -> Trie k v Source #

Truncate tree at given depth. truncate 0 t returns the root.

truncateSize :: (Trie k v -> Int) -> Int -> Trie k v -> Trie k v Source #

Truncate the tree so that it has at most the given size according to the given sizing function. truncateSize sizing 0 t returns the trie truncate 0 t.

truncateSizeWithLeaves :: Int -> Trie k v -> Trie k v Source #

truncateSize sizeWithLeaves