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

Modulevector-hashtables-0.1.2.0Haskell2010

Data.Vector.Hashtables.Internal

  • 5 types
  • 1 class
  • 52 values
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.0 · Data.Vector.Hashtables.Internal
  • (Ord (ks k), Ord (vs v)) => Ord (FrozenDictionary ks k vs v)Defined in vector-hashtables-0.1.2.0 · Data.Vector.Hashtables.Internal
  • (Show (ks k), Show (vs v)) => Show (FrozenDictionary ks k vs v)Defined in vector-hashtables-0.1.2.0 · Data.Vector.Hashtables.Internal
value(!.~) :: Vector v a => v a -> Int -> a
#

Infix version of unsafeIndex.

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

O(1) in the best case, O(n) in the worst case. Lookup the index of a key, which is its zero-based index in the sequence sorted by keys. The index is a number from 0 up to, but not including, the size of the dictionary.

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

3 declarations

Difference and intersection

5 declarations
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

2 declarations

Extras

4 declarations

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.0 · Data.Vector.Hashtables.Internal
  • Ord FastRemDefined in vector-hashtables-0.1.2.0 · Data.Vector.Hashtables.Internal
  • Show FastRemDefined in vector-hashtables-0.1.2.0 · Data.Vector.Hashtables.Internal