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

  • 4 types
  • 4 classes
  • 51 values

Documentation

0 declarations

Usage

Example6 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 vht <- initialize 0 :: IO (HashTable Int Int)insert ht 0 1

Types

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

Construction

Basic interface

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

Union

Difference

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.

Intersection

Conversions

Mutable

List

Low-level interface

classclass Monad m => PrimMonad (m :: Type -> Type) where
#

Class of monads which can perform primitive state-transformer actions.

Associated types

Methods

Instances18PrimMonad, …
datadata RealWorld
#

RealWorld is deeply magical. It is primitive, but it is not unlifted (hence ptrArg). We never manipulate values of type RealWorld; it's only used in the type system, to parameterise State#.

familytype family PrimState (m :: Type -> Type)
#

State token type.

Instances18PrimState, …
classclass PrimMonad m => PrimBase (m :: Type -> Type) where
#

Class of primitive monads for state-transformer actions.

Unlike PrimMonad, this typeclass requires that the Monad be fully expressed as a state transformer, therefore disallowing other monad transformers on top of the base IO or ST.

Methods

Instances4PrimBase
  • PrimBase IODefined in primitive-0.9.1.0 · Control.Monad.Primitive
  • PrimBase (ST s)Defined in primitive-0.9.1.0 · Control.Monad.Primitive
  • PrimBase (ST s)Defined in primitive-0.9.1.0 · Control.Monad.Primitive
  • PrimBase m => PrimBase (IdentityT m)Defined in primitive-0.9.1.0 · Control.Monad.Primitive
valuekeepAlive
  1. :: PrimBase m
  2. => a

    Value x to keep alive while computation k runs.

  3. -> m r

    Computation k

  4. -> m r
#

Keep value x alive until computation k completes. Warning: This primop exists for completeness, but it is difficult to use correctly. Prefer keepAliveUnlifted if the value to keep alive is simply a wrapper around an unlifted type (e.g. ByteArray).

valuetouch :: PrimMonad m => a -> m ()
#

Ensure that the value is considered alive by the garbage collection. Warning: GHC has optimization passes that can erase touch if it is certain that an exception is thrown afterward. Prefer keepAlive.

valueunsafeInlineIO :: IO a -> a
#

Generally, do not use this function. It is the same as accursedUnutterablePerformIO from bytestring and is well behaved under narrow conditions. See the documentation of that function to get an idea of when this is sound. In most cases GHC.IO.Unsafe.unsafeDupablePerformIO should be preferred.