Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
A left-unique relation.
Synopsis
- data BiMultimap a b
- empty :: (Ord a, Ord b) => BiMultimap a b
- isEmpty :: BiMultimap a b -> Bool
- memberDom :: Ord a => a -> BiMultimap a b -> Bool
- lookupDom :: Ord a => a -> BiMultimap a b -> Set b
- lookupRan :: Ord b => b -> BiMultimap a b -> Maybe a
- unsafeLookupRan :: Ord b => b -> BiMultimap a b -> a
- lookupPreimage :: (Ord a, Ord b) => b -> BiMultimap a b -> Set b
- unsafeTraverseDom :: forall a b m x. (Monad m, Ord b, Ord x) => (a -> m b) -> BiMultimap a x -> m (BiMultimap b x)
- filter :: (Ord a, Ord b) => (a -> b -> Bool) -> BiMultimap a b -> BiMultimap a b
- filterDom :: (Ord a, Ord b) => (a -> Bool) -> BiMultimap a b -> BiMultimap a b
- filterDomain :: (Ord a, Ord b) => (a -> NESet b -> Bool) -> BiMultimap a b -> BiMultimap a b
- restrictDom :: (Ord a, Ord b) => Set a -> BiMultimap a b -> BiMultimap a b
- restrictRan :: (Ord a, Ord b) => Set b -> BiMultimap a b -> BiMultimap a b
- withoutDom :: (Ord a, Ord b) => Set a -> BiMultimap a b -> BiMultimap a b
- withoutRan :: (Ord a, Ord b) => Set b -> BiMultimap a b -> BiMultimap a b
- domain :: BiMultimap a b -> Map a (NESet b)
- range :: BiMultimap a b -> Map b a
- unsafeFromDomain :: Ord b => Map a (NESet b) -> BiMultimap a b
- fromRange :: (Ord a, Ord b) => Map b a -> BiMultimap a b
- dom :: BiMultimap a b -> Set a
- ran :: BiMultimap a b -> Set b
- toRelation :: (Ord a, Ord b) => BiMultimap a b -> Relation a b
- insert :: (Ord a, Ord b) => a -> b -> BiMultimap a b -> BiMultimap a b
- unsafeInsert :: (Ord a, Ord b) => a -> b -> BiMultimap a b -> BiMultimap a b
- unsafeUnion :: (Ord a, Ord b) => BiMultimap a b -> BiMultimap a b -> BiMultimap a b
Documentation
data BiMultimap a b Source #
A left-unique relation.
"Left-unique" means that for all (x, y)
in the relation, y
is related only to x
.
Instances
(Show a, Show b) => Show (BiMultimap a b) Source # | |
Defined in Unison.Util.BiMultimap showsPrec :: Int -> BiMultimap a b -> ShowS # show :: BiMultimap a b -> String # showList :: [BiMultimap a b] -> ShowS # | |
(Eq a, Eq b) => Eq (BiMultimap a b) Source # | |
Defined in Unison.Util.BiMultimap (==) :: BiMultimap a b -> BiMultimap a b -> Bool # (/=) :: BiMultimap a b -> BiMultimap a b -> Bool # | |
(Ord a, Ord b) => Ord (BiMultimap a b) Source # | |
Defined in Unison.Util.BiMultimap compare :: BiMultimap a b -> BiMultimap a b -> Ordering # (<) :: BiMultimap a b -> BiMultimap a b -> Bool # (<=) :: BiMultimap a b -> BiMultimap a b -> Bool # (>) :: BiMultimap a b -> BiMultimap a b -> Bool # (>=) :: BiMultimap a b -> BiMultimap a b -> Bool # max :: BiMultimap a b -> BiMultimap a b -> BiMultimap a b # min :: BiMultimap a b -> BiMultimap a b -> BiMultimap a b # |
Basic queries
isEmpty :: BiMultimap a b -> Bool Source #
Is a left-unique relation empty?
Lookup
lookupDom :: Ord a => a -> BiMultimap a b -> Set b Source #
Look up the set of b
related to an a
.
O(log a).
unsafeLookupRan :: Ord b => b -> BiMultimap a b -> a Source #
Look up the a
related to a b
.
O(log b).
lookupPreimage :: (Ord a, Ord b) => b -> BiMultimap a b -> Set b Source #
Look up the preimage of a b
, that is, the set of b
that are related to the same a
as the input b
.
/O(log a + log b)
Mapping / traversing
unsafeTraverseDom :: forall a b m x. (Monad m, Ord b, Ord x) => (a -> m b) -> BiMultimap a x -> m (BiMultimap b x) Source #
Traverse over the domain a left-unique relation.
The caller is responsible for maintaining left-uniqueness.
Filtering
filter :: (Ord a, Ord b) => (a -> b -> Bool) -> BiMultimap a b -> BiMultimap a b Source #
Filter a left-unique relation, keeping only members (a, b)
that satisfy a predicate.
filterDom :: (Ord a, Ord b) => (a -> Bool) -> BiMultimap a b -> BiMultimap a b Source #
Filter a left-unique relation, keeping only members (a, b)
whose a
satisfies a predicate.
filterDomain :: (Ord a, Ord b) => (a -> NESet b -> Bool) -> BiMultimap a b -> BiMultimap a b Source #
Filter a left-unique relation, keeping only members (a, b)
whose a
and set of b
satisfies a predicate.
restrictDom :: (Ord a, Ord b) => Set a -> BiMultimap a b -> BiMultimap a b Source #
Restrict a left-unique relation to only those (a, b)
members whose a
is in the given set.
restrictRan :: (Ord a, Ord b) => Set b -> BiMultimap a b -> BiMultimap a b Source #
Restrict a left-unique relation to only those (a, b)
members whose b
is in the given set.
withoutDom :: (Ord a, Ord b) => Set a -> BiMultimap a b -> BiMultimap a b Source #
Restrict a left-unique relation to only those (a, b)
members whose a
is not in the given set.
withoutRan :: (Ord a, Ord b) => Set b -> BiMultimap a b -> BiMultimap a b Source #
Restrict a left-unique relation to only those (a, b)
members whose b
is not in the given set.
Maps
range :: BiMultimap a b -> Map b a Source #
O(1).
unsafeFromDomain :: Ord b => Map a (NESet b) -> BiMultimap a b Source #
Construct a left-unique relation from a mapping from its left-elements to set-of-right-elements. The caller is responsible for ensuring that no right-element is mapped to by two different left-elements.
fromRange :: (Ord a, Ord b) => Map b a -> BiMultimap a b Source #
Construct a left-unique relation from a mapping from its right-elements to its left-elements.
Sets
dom :: BiMultimap a b -> Set a Source #
Returns the domain of the relation, as a Set, in its entirety.
O(a).
ran :: BiMultimap a b -> Set b Source #
Returns the range of the relation, as a Set, in its entirety.
O(a).
Relations
toRelation :: (Ord a, Ord b) => BiMultimap a b -> Relation a b Source #
Convert a left-unique relation to a relation (forgetting its left-uniqueness).
Insert
insert :: (Ord a, Ord b) => a -> b -> BiMultimap a b -> BiMultimap a b Source #
Insert a pair into a left-unique relation, maintaining left-uniqueness, preferring the latest inserted element.
That is, if a left-unique relation already contains the pair (x, y)
, then inserting the pair (z, y)
will cause
the (x, y)
pair to be deleted.
unsafeInsert :: (Ord a, Ord b) => a -> b -> BiMultimap a b -> BiMultimap a b Source #
Like insert x y
, but the caller is responsible maintaining left-uniqueness.
Union
unsafeUnion :: (Ord a, Ord b) => BiMultimap a b -> BiMultimap a b -> BiMultimap a b Source #
Union two left-unique relations together.
The caller is responsible for maintaining left-uniqueness.