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

valueconstGrowthFactor :: Int
#

When resizing, the capacity will be multiplied by this amount.

This should be greater than one.

datadata HashMap k v where
#

A mutable hashmap with a linear interface.

Constructors

  • HashMap :: !Int -> !Int -> !RobinArr k v -> HashMap k v
    loadFactor m = size m / cap m

    Invariants: - array is non-empty - (count / capacity) <= constMaxLoadFactor.

Instances5Functor, Consumable, Dupable, Semigroup
  • Functor (HashMap k)Defined in linear-base-0.4.0 · Data.HashMap.Mutable.Linear.Internal
  • Semigroup (HashMap k v)Defined in linear-base-0.4.0 · Data.HashMap.Mutable.Linear.Internal
  • Consumable (HashMap k v)Defined in linear-base-0.4.0 · Data.HashMap.Mutable.Linear.Internal
  • Dupable (HashMap k v)Defined in linear-base-0.4.0 · Data.HashMap.Mutable.Linear.Internal
  • Keyed k => Semigroup (HashMap k v)Defined in linear-base-0.4.0 · Data.HashMap.Mutable.Linear.Internal
typetype RobinArr k v = Array (Maybe (RobinVal k v))
#

An array of Robin values

Each cell is Nothing if empty and is a RobinVal with the correct PSL otherwise.

datadata RobinVal k v
#

Robin values are triples of the key, value and PSL (the probe sequence length).

Constructors

  • RobinVal !PSL !k v
Instances1Show
  • (Show k, Show v) => Show (RobinVal k v)Defined in linear-base-0.4.0 · Data.HashMap.Mutable.Linear.Internal
valueincRobinValPSL :: RobinVal k v -> RobinVal k v
#
valuedecRobinValPSL :: RobinVal k v -> RobinVal k v
#
newtypenewtype PSL
#

A probe sequence length

Constructors

Instances4Eq, Num, Ord, Show
  • Eq PSLDefined in linear-base-0.4.0 · Data.HashMap.Mutable.Linear.Internal
  • Num PSLDefined in linear-base-0.4.0 · Data.HashMap.Mutable.Linear.Internal
  • Ord PSLDefined in linear-base-0.4.0 · Data.HashMap.Mutable.Linear.Internal
  • Show PSLDefined in linear-base-0.4.0 · Data.HashMap.Mutable.Linear.Internal
typetype Keyed k = (Eq k, Hashable k)
#

At minimum, we need to store hashable and identifiable keys

datadata ProbeResult k v where
#

The results of searching for where to insert a key.

PSL's on the constructors are the probes spent from the query, this might be different than PSL's of the cell at the returned index (in case of IndexToSwap constructor).

Constructors

  • IndexToInsert :: !PSL -> !Int -> ProbeResult k v

    An empty cell at index to insert a new element with PSL.

  • IndexToUpdate :: v -> !PSL -> !Int -> ProbeResult k v

    A matching cell at index with a PSL and a value to update.

  • IndexToSwap :: RobinVal k v -> !PSL -> !Int -> ProbeResult k v

    An occupied, richer, cell which should be evicted when inserting the new element. The swapped-out cell will then need to be inserted with a higher PSL.

valuealterF
  1. :: (Keyed k, Functor f)
  2. => Maybe v -> f (Ur (Maybe v))
  3. -> k
  4. -> HashMap k v
  5. -> f (HashMap k v)
#

The most general modification function; which can insert, update or delete a value of the key, while collecting an effect in the form of an arbitrary Functor.

valuealter
  1. :: Keyed k
  2. => Maybe v -> Maybe v
  3. -> k
  4. -> HashMap k v
  5. -> HashMap k v
#

A general modification function; which can insert, update or delete a value of the key. See alterF, for an even more general function.

valueunionWith
  1. :: Keyed k
  2. => v -> v -> v
  3. -> HashMap k v
  4. -> HashMap k v
  5. -> HashMap k v
#

Union of two maps using the provided function on conflicts.

Complexity: O(min(capacity hm1, capacity hm2)

valuecapacity :: HashMap k v %1 -> (Ur Int, HashMap k v)
#

Maximum number of elements the HashMap can store without resizing. However, for performance reasons, the HashMap might be before full.

Use shrinkToFit to reduce the wasted space.

valuetoList :: HashMap k v %1 -> Ur [(k, v)]
#

Converts a HashMap to a lazy list.

valueprobeFrom
  1. :: Keyed k
  2. => k
  3. -> PSL
  4. -> Int
  5. -> HashMap k v
  6. -> (# HashMap k v, ProbeResult k v #)
#

Given a key, psl of the probe so far, current unread index, and a full hashmap, return a probe result: the place the key already exists, a place to swap from, or an unfilled cell to write over.

valuetryInsertAtIndex
  1. :: Keyed k
  2. => HashMap k v
  3. -> Int
  4. -> RobinVal k v
  5. -> HashMap k v
#

Try to insert at a given index with a given PSL. So the probing starts from the given index (with the given PSL).

valueshiftSegmentBackward
  1. :: Keyed k
  2. => Int
  3. -> Int
  4. -> RobinArr k v
  5. -> Int
  6. -> RobinArr k v
#

Shift all cells with PSLs > 0 in a continuous segment following the deleted cell, backwards by one and decrement their PSLs.

valuegrowMapIfNecessary :: Keyed k => HashMap k v %1 -> HashMap k v
#

Makes sure that the map is not exceeding its utilization threshold (constMaxUtilization), resizes (constGrowthFactor) if necessary.

valueresize :: Keyed k => Int -> HashMap k v %1 -> HashMap k v
#

Resizes the HashMap to given capacity.

Invariant: Given capacity should be greater than the size, this is not checked.

GHC <9.2 does not allow linear case statements.

0 declarations

LambdaCase workaround does not work, because (&) does not work with

2 declarations
valuechainU :: (# a, b #) %1 -> ((# a, b #) %1 -> c) %1 -> c
#
valuechainU' :: a %1 -> (a %1 -> (# b, c #)) %1 -> (# b, c #)
#