HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

ModuleAgda-2.7.0.1Haskell2010

Agda.Utils.BiMap

Partly invertible finite maps.

Time complexities are given under the assumption that all relevant instance functions, as well as arguments of function type, take constant time, and "n" is the number of keys involved in the operation.

  • 1 type
  • 1 class
  • 32 values
  • PackageAgda-2.7.0.1
  • Exports34
  • LanguageHaskell2010
  • LicenceMIT
  • SourceBiMap.hs
classclass HasTag a where
#

Partial injections from a type to some tag type.

The idea is that tag should be injective on its domain: if tag x = tag y = Just i, then x = y. However, this property does not need to hold globally. The preconditions of the BiMap operations below specify for which sets of values tag must be injective.

Associated types

  • type family Tag a

Methods

Instances3HasTag
valuetagInjectiveFor :: (Eq v, Eq (Tag v), HasTag v) => [v] -> Bool
#

Checks if the function tag is injective for the values in the given list for which the function is defined.

datadata BiMap k v
#

Finite maps from k to v, with a way to quickly get from v to k for certain values of type v (those for which tag is defined).

Every value of this type must satisfy biMapInvariant.

Constructors

Instances9Eq, Ord, Show, Generic, NFData, Null, …
valuealterM
  1. :: (Ord k, Ord (Tag v), HasTag v, Monad m)
  2. => Maybe v -> m (Maybe v)
  3. -> k
  4. -> BiMap k v
  5. -> m (BiMap k v)
#

Modifies the value at the given position, if any. If the function returns Nothing, then the value is removed. O(log n).

The precondition for alterM f k m is that, if the value v is inserted into m, and tag v is defined, then no key other than k may map to a value v' for which tag v' = tag v.

valuemapWithKeyPrecondition
  1. :: (Eq k, Eq v, Eq (Tag v), HasTag v)
  2. => k -> v -> v
  3. -> BiMap k v
  4. -> Bool
#

The precondition for mapWithKey f m: For any two distinct mappings k₁ ↦ v₁, k₂ ↦ v₂ in m for which the tags of f k₁ v₁ and f k₂ v₂ are defined the values of f must be distinct (f k₁ v₁ ≠ f k₂ v₂). Furthermore tag must be injective for { f k v | (k, v) ∈ m }.

valuetoList :: BiMap k v -> [(k, v)]
#

Conversion to lists of pairs, with the keys in ascending order. O(n).

valuekeys :: BiMap k v -> [k]
#

The keys, in ascending order. O(n).

valueelems :: BiMap k v -> [v]
#

The values, ordered according to the corresponding keys. O(n).