concurrent-hashtable-0.1.1: Thread-safe hash tables for multi-cores!

Copyright(c) Peter Robinson
LicenseBSD3 (see the file LICENSE)
MaintainerPeter Robinson <pwr@lowerbound.io>
Stabilityprovisional
Portabilitynon-portable (requires concurrency, stm)
Safe HaskellNone
LanguageHaskell2010

Data.HashTable

Description

You can find benchmarks and more information about the internals of this package here: https://lowerbound.io/blog/2019-10-24_concurrent_hash_table_performance.html

Synopsis

Documentation

data HashTable k v Source #

A thread-safe hash table that supports dynamic resizing.

data Chain k v Source #

Used for chain-hashing.

Instances
Eq (Chain k v) Source # 
Instance details

Defined in Data.HashTable.Internal

Methods

(==) :: Chain k v -> Chain k v -> Bool #

(/=) :: Chain k v -> Chain k v -> Bool #

_itemsTV :: Chain k v -> TVar [(k, v)] Source #

stores the

new Source #

Arguments

:: Eq k 
=> Int

Initial size of the hash table

-> Config k 
-> IO (HashTable k v) 

Creates a new hash table with an initial size. See newWithDefaults for more details. You probably either want to use newWithDefaults instead or something like this: > mkDefaultConfig { _field = myValue } >>= new 10

newWithDefaults Source #

Arguments

:: (Eq k, Hashable k) 
=> Int

Initial size of the hash table

-> IO (HashTable k v) 

Creates a new hash table with the given initial vector size, scale factor 2.0, a resizing load threshold of 0.75, and we use as many threads for resizing as we have cores available. This will use a hash function with a (single) random salt, so if you need security, you MUST supply your own hash function. To be replaced by universal hashing in future versions.

mkDefaultConfig :: Hashable k => IO (Config k) Source #

Default configuration: scale factor = 2.0; resizing threshold = 0.75; number of worker threads for resizing = getNumCapabilities; hash function = use hashWithSalt with a random salt

data Config k Source #

Configuration options that may affect the performance of the hash table

Constructors

Config 

Fields

Instances
Show (Config k) Source # 
Instance details

Defined in Data.HashTable.Internal

Methods

showsPrec :: Int -> Config k -> ShowS #

show :: Config k -> String #

showList :: [Config k] -> ShowS #

lookup :: Eq k => HashTable k v -> k -> IO (Maybe v) Source #

Lookup the value for the key in the hash table if it exists.

insert Source #

Arguments

:: Eq k 
=> HashTable k v 
-> k

key

-> v

value

-> IO Bool 

insertIfNotExists Source #

Arguments

:: Eq k 
=> HashTable k v 
-> k

key

-> v

value

-> IO Bool 

Inserts a key and value pair into the hash table only if the key does not exist yet. Returns True if the insertion was successful, i.e., the hash table did not contain this key before. To get the same behaviour as insert, use insert. If you want to update an entry only if it exists, use update.

delete Source #

Arguments

:: Eq k 
=> HashTable k v 
-> k

key of entry that will be deleted

-> IO Bool 

Deletes the entry for the given key from the hash table. Returns True if and only if an entry was deleted from the table.

getAssocs :: Eq k => HashTable k v -> STM [(k, v)] Source #