HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Modulevector-hashtables-0.1.2.1Haskell2010

Data.Vector.Hashtables.Internal

Contents
  1. Combine
  2. Difference and intersection
  3. List conversions
  4. Extras
Synopsis
newtypenewtype Dictionary s (ks :: Type -> Type -> Type) k (vs :: Type -> Type -> Type) v

Single-element mutable array of Dictionary_ with primitive state token parameterized with state, keys and values types.

Different flavors of MVector could be used for keys and values. It's preferable to use Data.Vector.Unboxed.Mutable or Data.Vector.Storable.Mutable if possible. Otherwise, if you must use boxed vectors, consider employing strict ones from strict-containers to eliminate potential accumulation of thunks.

Example
Example4 expressions
import qualified Data.Vector.Storable.Mutable as VMimport qualified Data.Vector.Unboxed.Mutable  as UMimport Data.Vector.Hashtablestype HashTable k v = Dictionary (PrimState IO) VM.MVector k UM.MVector v

Constructors

datadata FrozenDictionary (ks :: Type -> Type) k (vs :: Type -> Type) v

Represents immutable dictionary as collection of immutable arrays and vectors. See unsafeFreeze and unsafeThaw for conversions from/to mutable dictionary.

Instances3Eq, Ord, Show
  • (Eq (ks k), Eq (vs v)) => Eq (FrozenDictionary ks k vs v)Defined in vector-hashtables-0.1.2.1 · Data.Vector.Hashtables.Internal
  • (Ord (ks k), Ord (vs v)) => Ord (FrozenDictionary ks k vs v)Defined in vector-hashtables-0.1.2.1 · Data.Vector.Hashtables.Internal
  • (Show (ks k), Show (vs v)) => Show (FrozenDictionary ks k vs v)Defined in vector-hashtables-0.1.2.1 · Data.Vector.Hashtables.Internal
valueupsert
  1. :: (MVector ks k, MVector vs v, PrimMonad m, Hashable k, Eq k)
  2. => Dictionary (PrimState m) ks k vs v
  3. -> Maybe v -> v
  4. -> k
  5. -> m ()

O(1) in the best case, O(n) in the worst case. The expression (upsert ht f k) updates or inserts the value x at k.

It's a responsibility of MVector vs to force evaluation of the updated value. Unboxed / storable vectors do it automatically. If you use boxed vectors, consider employing strict ones from strict-containers to eliminate potential accumulation of thunks.

let f _ = "c"
ht <- fromList [(5,"a"), (3,"b")]
upsert ht f 7
toList ht
[(3, "b"), (5, "a"), (7, "c")]
ht <- fromList [(5,"a"), (3,"b")]
upsert ht f 5
toList ht
[(3, "b"), (5, "c")]
valuealter
  1. :: (MVector ks k, MVector vs v, DeleteEntry ks, DeleteEntry vs, PrimMonad m, Hashable k, Eq k)
  2. => Dictionary (PrimState m) ks k vs v
  3. -> Maybe v -> Maybe v
  4. -> k
  5. -> m ()

O(1) in the best case, O(n) in the worst case. The expression (alter ht f k) alters the value x at k, or absence thereof. alter can be used to insert, delete, or update a value in a Dictionary.

It's a responsibility of MVector vs to force evaluation of the updated value. Unboxed / storable vectors do it automatically. If you use boxed vectors, consider employing strict ones from strict-containers to eliminate potential accumulation of thunks.

let f _ = Nothing
ht <- fromList [(5,"a"), (3,"b")]
alter ht f 7
toList ht
[(3, "b"), (5, "a")]
ht <- fromList [(5,"a"), (3,"b")]
alter ht f 5
toList ht
[(3 "b")]
let f _ = Just "c"
ht <- fromList [(5,"a"), (3,"b")]
alter ht f 7
toList ht
[(3, "b"), (5, "a"), (7, "c")]
ht <- fromList [(5,"a"), (3,"b")]
alter ht f 5
toList ht
[(3, "b"), (5, "c")]

Combine

Difference and intersection

valuedifferenceWith
  1. :: (MVector ks k, MVector vs v, MVector vs w, PrimMonad m, Hashable k, Eq k)
  2. => v -> w -> Maybe v
  3. -> Dictionary (PrimState m) ks k vs v
  4. -> Dictionary (PrimState m) ks k vs w
  5. -> m (Dictionary (PrimState m) ks k vs v)

O(n) in the best case, O(n * m) in the worst case. Difference with a combining function. When two equal keys are encountered, the combining function is applied to the values of these keys. If it returns Nothing, the element is discarded (proper set difference). If it returns (Just y), the element is updated with a new value y.

List conversions

Extras

This data is auto-generated by GenPrimes.hs. The vector contains tuples (p, m, s) such that p is prime and (assuming 64-bit architecture) for every n >= 0 it holds that n `quot` p = (n * m) `shiftR` (64 + s), enabling faster computation of remainders.

datadata FastRem

For 64-bit architectures frmPrime is a prime number such that for each n >= 0 it holds that n `quot` frmPrime = (n * _frmMulHi) `shiftR` (64 + s).

Instances3Eq, Ord, Show
  • Eq FastRemDefined in vector-hashtables-0.1.2.1 · Data.Vector.Hashtables.Internal
  • Ord FastRemDefined in vector-hashtables-0.1.2.1 · Data.Vector.Hashtables.Internal
  • Show FastRemDefined in vector-hashtables-0.1.2.1 · Data.Vector.Hashtables.Internal