uhc-util-0.1.5.6: UHC utilities

Safe HaskellNone
LanguageHaskell98

UHC.Util.RelMap

Description

Relation via pair of maps for domain and range, for faster lookup in 2 directions. Incomplete w.r.t. corresponding UHC.Util.Rel

Synopsis

Documentation

data Rel a b Source

Relation, represented as 2 maps from domain to range and the inverse, thus allowing faster lookup at the expense of some set like operations more expensive.

Instances

(Ord b, Ord a, Binary a, Binary b) => Binary (Rel a b) 
(Ord b, Ord a, Serialize a, Serialize b) => Serialize (Rel a b) 

empty :: Rel a b Source

Empty relation

toDomList :: Rel a b -> [(a, [b])] Source

As assocation list where each domain value only occurs once and the range as list

toRngList :: Rel a b -> [([a], b)] Source

As assocation list where each range value only occurs once and the domain as list

toList :: Rel a b -> [(a, b)] Source

As assocation list

fromList :: (Ord a, Ord b) => [(a, b)] -> Rel a b Source

From association list

singleton :: (Ord a, Ord b) => a -> b -> Rel a b Source

Singleton relation

dom :: (Ord a, Ord b) => Rel a b -> Set a Source

Domain of relation

rng :: (Ord a, Ord b) => Rel a b -> Set b Source

Range of relation

restrictDom :: (Ord a, Ord b) => (a -> Bool) -> Rel a b -> Rel a b Source

Filter on domain

restrictRng :: (Ord a, Ord b) => (b -> Bool) -> Rel a b -> Rel a b Source

Filter on range

mapDom :: (Ord b, Ord x) => (a -> x) -> Rel a b -> Rel x b Source

Map domain

mapRng :: (Ord a, Ord x) => (b -> x) -> Rel a b -> Rel a x Source

Map range

union :: (Ord a, Ord b) => Rel a b -> Rel a b -> Rel a b Source

Union

unions :: (Ord a, Ord b) => [Rel a b] -> Rel a b Source

Union of list of relations

insert :: (Ord a, Ord b) => a -> b -> Rel a b -> Rel a b Source

Insert

deleteDom :: (Ord a, Ord b) => a -> Rel a b -> Rel a b Source

Delete at domain

delete :: (Ord a, Ord b) => a -> Rel a b -> Rel a b Source

Delete at domain

deleteRng :: (Ord a, Ord b) => b -> Rel a b -> Rel a b Source

Delete at range

applyDomMbSet :: Ord a => Rel a b -> a -> Maybe (Set b) Source

Apply relation as a function, possible yielding a non empty set

applyRngMbSet :: Ord b => Rel a b -> b -> Maybe (Set a) Source

Apply relation as an inverse function, possible yielding a non empty set

applyDomSet :: Ord a => Rel a b -> a -> Set b Source

Apply relation as a function, yielding a possibly empty set

applyRngSet :: Ord b => Rel a b -> b -> Set a Source

Apply relation as an inverse function, yielding a possibly empty set

applyDom :: Ord a => Rel a b -> a -> Maybe b Source

Apply relation as a function, aka lookup, picking an arbitrary value in case of multiples

applyRng :: Ord b => Rel a b -> b -> Maybe a Source

Apply relation as an inverse function, aka lookup, picking an arbitrary value in case of multiples

apply :: Ord a => Rel a b -> a -> [b] Source

Apply relation as a function

applyInverse :: Ord b => Rel a b -> b -> [a] Source

Apply relation as an inverse function

lookupDom :: Ord a => a -> Rel a b -> Maybe b Source

Alias for apply in more conventional terms

lookupRng :: Ord b => b -> Rel a b -> Maybe a Source

Alias for apply in more conventional terms

lookup :: Ord a => a -> Rel a b -> Maybe b Source

Alias for apply in more conventional terms

lookupInverse :: Ord b => b -> Rel a b -> Maybe a Source

Alias for apply in more conventional terms

toDomMap :: Ord a => Rel a b -> Map a [b] Source

As a Map keyed on domain

toRngMap :: Ord b => Rel a b -> Map b [a] Source

As a Map keyed on range