parameterized-utils-2.1.11.0: Classes and data structures for working with data-kind indexed types

Copyright | (c) Galois Inc 2014-2019
Maintainer | Joe Hendrix <jhendrix@galois.com>
Safe Haskell | Trustworthy
Language | Haskell2010

Data.Parameterized.HashTable

Description

This module provides a `ST`-based hashtable for parameterized keys and values.

NOTE: This API makes use of `unsafeCoerce` to implement the parameterized hashtable abstraction. This should be type-safe provided that the `TestEquality` instance on the key type is implemented soundly.

Synopsis

- data HashTable s (key :: k -> Type) (val :: k -> Type)
- new :: forall {k} s (key :: k -> Type) (val :: k -> Type). ST s (HashTable s key val)
- newSized :: forall {k1} s (k2 :: k1 -> Type) (v :: k1 -> Type). Int -> ST s (HashTable s k2 v)
- clone :: forall {k} (key :: k -> Type) s (val :: k -> Type). (HashableF key, TestEquality key) => HashTable s key val -> ST s (HashTable s key val)
- lookup :: forall {k} key s val (tp :: k). (HashableF key, TestEquality key) => HashTable s key val -> key tp -> ST s (Maybe (val tp))
- insert :: forall k key s val (tp :: k). (HashableF key, TestEquality key) => HashTable s key val -> key tp -> val tp -> ST s ()
- member :: forall k key s (val :: k -> Type) (tp :: k). (HashableF key, TestEquality key) => HashTable s key val -> key tp -> ST s Bool
- delete :: forall k key s (val :: k -> Type) (tp :: k). (HashableF key, TestEquality key) => HashTable s key val -> key tp -> ST s ()
- clear :: forall k (key :: k -> Type) s (val :: k -> Type). (HashableF key, TestEquality key) => HashTable s key val -> ST s ()
- class HashableF (f :: k -> Type) where
  - hashWithSaltF :: forall (tp :: k). Int -> f tp -> Int
  - hashF :: forall (tp :: k). f tp -> Int
- data RealWorld

# Documentation

data HashTable s (key :: k -> Type) (val :: k -> Type) Source #

A hash table mapping nonces to values.

new :: forall {k} s (key :: k -> Type) (val :: k -> Type). ST s (HashTable s key val) Source #

Create a new empty table.

newSized :: forall {k1} s (k2 :: k1 -> Type) (v :: k1 -> Type). Int -> ST s (HashTable s k2 v) Source #

Create a new empty table to hold `n` elements.

clone :: forall {k} (key :: k -> Type) s (val :: k -> Type). (HashableF key, TestEquality key) => HashTable s key val -> ST s (HashTable s key val) Source #

Create a hash table that is a copy of the current one.

lookup :: forall {k} key s val (tp :: k). (HashableF key, TestEquality key) => HashTable s key val -> key tp -> ST s (Maybe (val tp)) Source #

Lookup value of key in table.

insert :: forall k key s val (tp :: k). (HashableF key, TestEquality key) => HashTable s key val -> key tp -> val tp -> ST s () Source #

Insert new key and value mapping into table.

member :: forall k key s (val :: k -> Type) (tp :: k). (HashableF key, TestEquality key) => HashTable s key val -> key tp -> ST s Bool Source #

Return true if the key is in the hash table.

delete :: forall k key s (val :: k -> Type) (tp :: k). (HashableF key, TestEquality key) => HashTable s key val -> key tp -> ST s () Source #

Delete an element from the hash table.

clear :: forall k (key :: k -> Type) s (val :: k -> Type). (HashableF key, TestEquality key) => HashTable s key val -> ST s () Source #

class HashableF (f :: k -> Type) where Source #

A parameterized type that is hashable on all instances.

Minimal complete definition

hashWithSaltF

Methods

hashWithSaltF :: forall (tp :: k). Int -> f tp -> Int Source #

hashF :: forall (tp :: k). f tp -> Int Source #

Hash with default salt.

#### Instances

Instances details

HashableF NatRepr Source # |
Instance details Defined in Data.Parameterized.NatRepr.Internal Methods hashWithSaltF :: forall (tp :: Nat). Int -> NatRepr tp -> Int Source # hashF :: forall (tp :: Nat). NatRepr tp -> Int Source #
HashableF PeanoRepr Source # |
Instance details Defined in Data.Parameterized.Peano Methods hashWithSaltF :: forall (tp :: Peano). Int -> PeanoRepr tp -> Int Source # hashF :: forall (tp :: Peano). PeanoRepr tp -> Int Source #
HashableF BoolRepr Source # |
Instance details Defined in Data.Parameterized.BoolRepr Methods hashWithSaltF :: forall (tp :: Bool). Int -> BoolRepr tp -> Int Source # hashF :: forall (tp :: Bool). BoolRepr tp -> Int Source #
HashableF SymbolRepr Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods hashWithSaltF :: forall (tp :: Symbol). Int -> SymbolRepr tp -> Int Source # hashF :: forall (tp :: Symbol). SymbolRepr tp -> Int Source #
HashableF (Nonce :: k -> Type) Source # |
Instance details Defined in Data.Parameterized.Nonce.Unsafe Methods hashWithSaltF :: forall (tp :: k). Int -> Nonce tp -> Int Source # hashF :: forall (tp :: k). Nonce tp -> Int Source #
Hashable a => HashableF (Const a :: k -> Type) Source # |
Instance details Defined in Data.Parameterized.Classes Methods hashWithSaltF :: forall (tp :: k). Int -> Const a tp -> Int Source # hashF :: forall (tp :: k). Const a tp -> Int Source #
HashableF (Index ctx :: k -> Type) Source # |
Instance details Defined in Data.Parameterized.Context.Unsafe Methods hashWithSaltF :: forall (tp :: k). Int -> Index ctx tp -> Int Source # hashF :: forall (tp :: k). Index ctx tp -> Int Source #
HashableF (Nonce s :: k -> Type) Source # |
Instance details Defined in Data.Parameterized.Nonce Methods hashWithSaltF :: forall (tp :: k). Int -> Nonce s tp -> Int Source # hashF :: forall (tp :: k). Nonce s tp -> Int Source #
(HashableF f, TestEquality f) => HashableF (Assignment f :: Ctx k -> Type) Source # |
Instance details Defined in Data.Parameterized.Context.Unsafe Methods hashWithSaltF :: forall (tp :: Ctx k). Int -> Assignment f tp -> Int Source # hashF :: forall (tp :: Ctx k). Assignment f tp -> Int Source #

data RealWorld Source #

`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#`.