unimap-0.1.0: A union-find/map data structure
Safe HaskellSafe-Inferred
LanguageGHC2021

Unimap

Description

(Import this module qualified)

Synopsis

Documentation

data Changed Source #

Constructors

ChangedYes 
ChangedNo 

Instances

Instances details
Show Changed Source # 
Instance details

Defined in Unimap

Eq Changed Source # 
Instance details

Defined in Unimap

Methods

(==) :: Changed -> Changed -> Bool #

(/=) :: Changed -> Changed -> Bool #

data Equiv k Source #

Constructors

Equiv 

Fields

Instances

Instances details
Show k => Show (Equiv k) Source # 
Instance details

Defined in Unimap

Methods

showsPrec :: Int -> Equiv k -> ShowS #

show :: Equiv k -> String #

showList :: [Equiv k] -> ShowS #

Eq k => Eq (Equiv k) Source # 
Instance details

Defined in Unimap

Methods

(==) :: Equiv k -> Equiv k -> Bool #

(/=) :: Equiv k -> Equiv k -> Bool #

data Entry k v Source #

Constructors

EntryLink !k 
EntryValue !v 

Instances

Instances details
Foldable (Entry k) Source # 
Instance details

Defined in Unimap

Methods

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

foldMap :: Monoid m => (a -> m) -> Entry k a -> m #

foldMap' :: Monoid m => (a -> m) -> Entry k a -> m #

foldr :: (a -> b -> b) -> b -> Entry k a -> b #

foldr' :: (a -> b -> b) -> b -> Entry k a -> b #

foldl :: (b -> a -> b) -> b -> Entry k a -> b #

foldl' :: (b -> a -> b) -> b -> Entry k a -> b #

foldr1 :: (a -> a -> a) -> Entry k a -> a #

foldl1 :: (a -> a -> a) -> Entry k a -> a #

toList :: Entry k a -> [a] #

null :: Entry k a -> Bool #

length :: Entry k a -> Int #

elem :: Eq a => a -> Entry k a -> Bool #

maximum :: Ord a => Entry k a -> a #

minimum :: Ord a => Entry k a -> a #

sum :: Num a => Entry k a -> a #

product :: Num a => Entry k a -> a #

Traversable (Entry k) Source # 
Instance details

Defined in Unimap

Methods

traverse :: Applicative f => (a -> f b) -> Entry k a -> f (Entry k b) #

sequenceA :: Applicative f => Entry k (f a) -> f (Entry k a) #

mapM :: Monad m => (a -> m b) -> Entry k a -> m (Entry k b) #

sequence :: Monad m => Entry k (m a) -> m (Entry k a) #

Functor (Entry k) Source # 
Instance details

Defined in Unimap

Methods

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

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

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

Defined in Unimap

Methods

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

show :: Entry k v -> String #

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

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

Defined in Unimap

Methods

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

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

(Ord k, Ord v) => Ord (Entry k v) Source # 
Instance details

Defined in Unimap

Methods

compare :: Entry k v -> Entry k v -> Ordering #

(<) :: Entry k v -> Entry k v -> Bool #

(<=) :: Entry k v -> Entry k v -> Bool #

(>) :: Entry k v -> Entry k v -> Bool #

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

max :: Entry k v -> Entry k v -> Entry k v #

min :: Entry k v -> Entry k v -> Entry k v #

type MergeOne e v r = Maybe v -> v -> Either e (r, v) Source #

type MergeMany f e v r = Maybe v -> f v -> Either e (r, v) Source #

adaptMergeOne :: (v -> f v) -> MergeMany f e v r -> MergeOne e v r Source #

foldMergeOne :: Monoid r => (v -> v -> Either e (r, v)) -> MergeOne e v r Source #

foldMergeMany :: (Foldable f, Monoid r) => Either e v -> (v -> v -> Either e (r, v)) -> MergeMany f e v r Source #

data UnionMap k v Source #

Instances

Instances details
Foldable (UnionMap k) Source # 
Instance details

Defined in Unimap

Methods

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

foldMap :: Monoid m => (a -> m) -> UnionMap k a -> m #

foldMap' :: Monoid m => (a -> m) -> UnionMap k a -> m #

foldr :: (a -> b -> b) -> b -> UnionMap k a -> b #

foldr' :: (a -> b -> b) -> b -> UnionMap k a -> b #

foldl :: (b -> a -> b) -> b -> UnionMap k a -> b #

foldl' :: (b -> a -> b) -> b -> UnionMap k a -> b #

foldr1 :: (a -> a -> a) -> UnionMap k a -> a #

foldl1 :: (a -> a -> a) -> UnionMap k a -> a #

toList :: UnionMap k a -> [a] #

null :: UnionMap k a -> Bool #

length :: UnionMap k a -> Int #

elem :: Eq a => a -> UnionMap k a -> Bool #

maximum :: Ord a => UnionMap k a -> a #

minimum :: Ord a => UnionMap k a -> a #

sum :: Num a => UnionMap k a -> a #

product :: Num a => UnionMap k a -> a #

Traversable (UnionMap k) Source # 
Instance details

Defined in Unimap

Methods

traverse :: Applicative f => (a -> f b) -> UnionMap k a -> f (UnionMap k b) #

sequenceA :: Applicative f => UnionMap k (f a) -> f (UnionMap k a) #

mapM :: Monad m => (a -> m b) -> UnionMap k a -> m (UnionMap k b) #

sequence :: Monad m => UnionMap k (m a) -> m (UnionMap k a) #

Functor (UnionMap k) Source # 
Instance details

Defined in Unimap

Methods

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

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

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

Defined in Unimap

Methods

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

show :: UnionMap k v -> String #

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

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

Defined in Unimap

Methods

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

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

type UnionMapLens s k v = Lens' s (UnionMap k v) Source #

member :: Coercible k Int => k -> UnionMap k v -> Bool Source #

toList :: Coercible k Int => UnionMap k v -> [(k, Entry k v)] Source #

data AddRes k v Source #

Constructors

AddResAdded !(UnionMap k v) 
AddResDuplicate 

Instances

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

Defined in Unimap

Methods

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

show :: AddRes k v -> String #

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

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

Defined in Unimap

Methods

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

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

data AddVal Source #

Instances

Instances details
Show AddVal Source # 
Instance details

Defined in Unimap

Eq AddVal Source # 
Instance details

Defined in Unimap

Methods

(==) :: AddVal -> AddVal -> Bool #

(/=) :: AddVal -> AddVal -> Bool #

add :: Coercible k Int => k -> v -> UnionMap k v -> AddRes k v Source #

addLM :: (Coercible k Int, MonadState s m) => UnionMapLens s k v -> k -> v -> m AddVal Source #

addM :: (Coercible k Int, MonadState (UnionMap k v) m) => k -> v -> m AddVal Source #

data TraceRes k v Source #

Constructors

TraceResMissing !k 
TraceResFound !k !v ![k] 

Instances

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

Defined in Unimap

Methods

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

show :: TraceRes k v -> String #

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

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

Defined in Unimap

Methods

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

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

trace :: Coercible k Int => k -> UnionMap k v -> TraceRes k v Source #

data LookupRes k v Source #

Constructors

LookupResMissing !k 
LookupResFound !k !v !(Maybe (UnionMap k v)) 

Instances

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

Defined in Unimap

Methods

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

show :: LookupRes k v -> String #

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

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

Defined in Unimap

Methods

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

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

data LookupVal k v Source #

Constructors

LookupValMissing !k 
LookupValOk !k !v !Changed 

Instances

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

Defined in Unimap

Methods

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

show :: LookupVal k v -> String #

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

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

Defined in Unimap

Methods

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

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

lookup :: Coercible k Int => k -> UnionMap k v -> LookupRes k v Source #

lookupLM :: (Coercible k Int, MonadState s m) => UnionMapLens s k v -> k -> m (LookupVal k v) Source #

lookupM :: (Coercible k Int, MonadState (UnionMap k v) m) => k -> m (LookupVal k v) Source #

equiv :: Coercible k Int => UnionMap k v -> (Equiv k, Maybe (UnionMap k v)) Source #

equivLM :: (Coercible k Int, MonadState s m) => UnionMapLens s k v -> m (Equiv k) Source #

equivM :: (Coercible k Int, MonadState (UnionMap k v) m) => m (Equiv k) Source #

compact :: Coercible k Int => UnionMap k v -> (IntLikeMap k k, UnionMap k v) Source #

Compresses all paths so there is never more than one jump to the root of each class Retains all keys in the map but returns a mapping of non-root -> root keys

canonicalize :: Coercible k Int => Traversal' v k -> UnionMap k v -> (IntLikeMap k k, UnionMap k v) Source #

Compacts and rewrites all values with canonical keys. Retains all keys in the map and again returns a mapping of non-root -> root keys. TODO remove non-canonical keys?

data UpdateRes e k v r Source #

Constructors

UpdateResMissing !k 
UpdateResEmbed !e 
UpdateResAdded !v !r !(UnionMap k v) 
UpdateResUpdated !k !v !r !(UnionMap k v) 

Instances

Instances details
(Show e, Show k, Show v, Show r) => Show (UpdateRes e k v r) Source # 
Instance details

Defined in Unimap

Methods

showsPrec :: Int -> UpdateRes e k v r -> ShowS #

show :: UpdateRes e k v r -> String #

showList :: [UpdateRes e k v r] -> ShowS #

(Eq e, Eq k, Eq v, Eq r) => Eq (UpdateRes e k v r) Source # 
Instance details

Defined in Unimap

Methods

(==) :: UpdateRes e k v r -> UpdateRes e k v r -> Bool #

(/=) :: UpdateRes e k v r -> UpdateRes e k v r -> Bool #

data UpdateVal e k v r Source #

Constructors

UpdateValMissing !k 
UpdateValEmbed !e 
UpdateValAdded !v !r 
UpdateValUpdated !k !v !r 

Instances

Instances details
(Show e, Show k, Show v, Show r) => Show (UpdateVal e k v r) Source # 
Instance details

Defined in Unimap

Methods

showsPrec :: Int -> UpdateVal e k v r -> ShowS #

show :: UpdateVal e k v r -> String #

showList :: [UpdateVal e k v r] -> ShowS #

(Eq e, Eq k, Eq v, Eq r) => Eq (UpdateVal e k v r) Source # 
Instance details

Defined in Unimap

Methods

(==) :: UpdateVal e k v r -> UpdateVal e k v r -> Bool #

(/=) :: UpdateVal e k v r -> UpdateVal e k v r -> Bool #

update :: (Coercible k Int, Eq k) => MergeOne e v r -> k -> v -> UnionMap k v -> UpdateRes e k v r Source #

updateLM :: (Coercible k Int, Eq k, MonadState s m) => UnionMapLens s k v -> MergeOne e v r -> k -> v -> m (UpdateVal e k v r) Source #

updateM :: (Coercible k Int, Eq k, MonadState (UnionMap k v) m) => MergeOne e v r -> k -> v -> m (UpdateVal e k v r) Source #

data MergeRes e k v r Source #

Constructors

MergeResMissing !k 
MergeResEmbed !e 
MergeResMerged !k !v !r !(UnionMap k v) 

Instances

Instances details
(Show e, Show k, Show v, Show r) => Show (MergeRes e k v r) Source # 
Instance details

Defined in Unimap

Methods

showsPrec :: Int -> MergeRes e k v r -> ShowS #

show :: MergeRes e k v r -> String #

showList :: [MergeRes e k v r] -> ShowS #

(Eq e, Eq k, Eq v, Eq r) => Eq (MergeRes e k v r) Source # 
Instance details

Defined in Unimap

Methods

(==) :: MergeRes e k v r -> MergeRes e k v r -> Bool #

(/=) :: MergeRes e k v r -> MergeRes e k v r -> Bool #

data MergeVal e k v r Source #

Constructors

MergeValMissing !k 
MergeValEmbed !e 
MergeValMerged !k !v !r 

Instances

Instances details
(Show e, Show k, Show v, Show r) => Show (MergeVal e k v r) Source # 
Instance details

Defined in Unimap

Methods

showsPrec :: Int -> MergeVal e k v r -> ShowS #

show :: MergeVal e k v r -> String #

showList :: [MergeVal e k v r] -> ShowS #

(Eq e, Eq k, Eq v, Eq r) => Eq (MergeVal e k v r) Source # 
Instance details

Defined in Unimap

Methods

(==) :: MergeVal e k v r -> MergeVal e k v r -> Bool #

(/=) :: MergeVal e k v r -> MergeVal e k v r -> Bool #

mergeOne :: (Coercible k Int, Eq k) => MergeOne e v r -> k -> k -> UnionMap k v -> MergeRes e k v r Source #

mergeOneLM :: (Coercible k Int, Eq k, MonadState s m) => UnionMapLens s k v -> MergeOne e v r -> k -> k -> m (MergeVal e k v r) Source #

mergeOneM :: (Coercible k Int, Eq k, MonadState (UnionMap k v) m) => MergeOne e v r -> k -> k -> m (MergeVal e k v r) Source #

mergeMany :: (Traversable f, Coercible k Int, Eq k) => MergeMany f e v r -> k -> f k -> UnionMap k v -> MergeRes e k v r Source #

mergeManyLM :: (Traversable f, Coercible k Int, Eq k, MonadState s m) => UnionMapLens s k v -> MergeMany f e v r -> k -> f k -> m (MergeVal e k v r) Source #

mergeManyM :: (Traversable f, Coercible k Int, Eq k, MonadState (UnionMap k v) m) => MergeMany f e v r -> k -> f k -> m (MergeVal e k v r) Source #

extract :: Coercible k Int => Traversal' v k -> k -> UnionMap k v -> (Maybe (k, IntLikeMap k v), UnionMap k v) Source #

Return the subgraph accessible from a given key.

extractLM :: (Coercible k Int, MonadState s m) => UnionMapLens s k v -> Traversal' v k -> k -> m (Maybe (k, IntLikeMap k v)) Source #

extractM :: (Coercible k Int, MonadState (UnionMap k v) m) => Traversal' v k -> k -> m (Maybe (k, IntLikeMap k v)) Source #