-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Thread-safe hash tables for multi-cores! -- -- Please see the README on GitHub at -- https://github.com/pwrobinson/concurrent-hashtable#readme @package concurrent-hashtable @version 0.1.0 -- | 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 module Data.HashTable.Internal data MigrationStatus NotStarted :: MigrationStatus Ongoing :: MigrationStatus Finished :: MigrationStatus -- | Used for chain-hashing. data Chain k v Chain :: TVar [(k, v)] -> TVar MigrationStatus -> Chain k v -- | stores the [_itemsTV] :: Chain k v -> TVar [(k, v)] -- | used internally for resizing [_migrationStatusTV] :: Chain k v -> TVar MigrationStatus newChainIO :: () => IO (Chain k v) -- | A thread-safe hash table that supports dynamic resizing. data HashTable k v HashTable :: TVar (Vector (Chain k v)) -> IORef Int -> Config k -> HashTable k v -- | vector of linked lists [_chainsVecTV] :: HashTable k v -> TVar (Vector (Chain k v)) [_totalLoad] :: HashTable k v -> IORef Int [_config] :: HashTable k v -> Config k -- | Configuration options that may affect the performance of the hash -- table data Config k Config :: Float -> Float -> Int -> (k -> Int) -> Config k -- | scale factor for resizing [_scaleFactor] :: Config k -> Float -- | load threshold for initiating resizing. [_threshold] :: Config k -> Float -- | maximum number of worker threads used during resizing [_numResizeWorkers] :: Config k -> Int [_hashFunc] :: Config k -> k -> Int -- | 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 mkDefaultConfig :: Hashable k => IO (Config k) -- | 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 new :: Eq k => Int -> Config k -> 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. newWithDefaults :: (Eq k, Hashable k) => Int -> IO (HashTable k v) -- | Returns the size of the vector representing the hash table. readSizeIO :: HashTable k v -> IO Int -- | Returns the size of the vector representing the hash table. readSize :: HashTable k v -> STM Int -- | Resizes the hash table by scaling it according to the _scaleFactor in -- the configuration. resize :: Eq k => HashTable k v -> IO () -- | Lookup the value for a key in the hash table. lookup :: Eq k => HashTable k v -> k -> IO (Maybe v) -- | Used internally. An action to be executed atomically for the given -- chain. type STMAction k v a = TVar [(k, v)] -> STM (Maybe a) -- | Used internally by insert, insertIfNotExists, -- delete, update genericModify :: Eq k => HashTable k v -> k -> STMAction k v a -> IO a insert :: Eq k => HashTable k v -> k -> v -> 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. insertIfNotExists :: Eq k => HashTable k v -> k -> v -> IO Bool delete :: Eq k => HashTable k v -> k -> IO Bool -- | Atomically increment/decrement the table load value by adding the -- provided integer value to the current value. atomicallyChangeLoad :: Eq k => HashTable k v -> Int -> IO () getAssocs :: Eq k => HashTable k v -> STM [(k, v)] deleteFirstKey :: Eq a => a -> [(a, b)] -> [(a, b)] -- | Get the chain for the given key. readChainForKeyIO :: HashTable k v -> k -> IO (Chain k v) -- | Get the chain for the given key. readChainForKey :: HashTable k v -> k -> STM (Chain k v) -- | Get the chain for the given index (warning: bounds are not checked) readChainForIndexIO :: HashTable k v -> Int -> IO (Chain k v) -- | Get the chain for the given index (warning: bounds are not checked) readChainForIndex :: HashTable k v -> Int -> STM (Chain k v) debug :: Show a => a -> IO () instance GHC.Classes.Eq (Data.HashTable.Internal.Chain k v) instance GHC.Classes.Eq Data.HashTable.Internal.MigrationStatus instance GHC.Show.Show Data.HashTable.Internal.MigrationStatus instance GHC.Show.Show (Data.HashTable.Internal.Config k) -- | 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 module Data.HashTable -- | A thread-safe hash table that supports dynamic resizing. data HashTable k v -- | Used for chain-hashing. data Chain k v -- | stores the _itemsTV :: Chain k v -> TVar [(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 new :: Eq k => Int -> Config k -> 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. newWithDefaults :: (Eq k, Hashable k) => Int -> IO (HashTable k v) -- | 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 mkDefaultConfig :: Hashable k => IO (Config k) -- | Configuration options that may affect the performance of the hash -- table data Config k Config :: Float -> Float -> Int -> (k -> Int) -> Config k -- | scale factor for resizing [_scaleFactor] :: Config k -> Float -- | load threshold for initiating resizing. [_threshold] :: Config k -> Float -- | maximum number of worker threads used during resizing [_numResizeWorkers] :: Config k -> Int [_hashFunc] :: Config k -> k -> Int -- | Lookup the value for a key in the hash table. lookup :: Eq k => HashTable k v -> k -> IO (Maybe v) insert :: Eq k => HashTable k v -> k -> v -> 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. insertIfNotExists :: Eq k => HashTable k v -> k -> v -> IO Bool delete :: Eq k => HashTable k v -> k -> IO Bool getAssocs :: Eq k => HashTable k v -> STM [(k, v)]