hashtables: Mutable hash tables in the ST monad

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Warnings:

This package provides a couple of different implementations of mutable hash tables in the ST monad, as well as a typeclass abstracting their common operations, and a set of wrappers to use the hash tables in the IO monad.

QUICK START: documentation for the hash table operations is provided in the Data.HashTable.Class module, and the IO wrappers (which most users will probably prefer) are located in the Data.HashTable.IO module.

This package currently contains three hash table implementations:

  1. Data.HashTable.ST.Cuckoo contains an implementation of "cuckoo hashing" as introduced by Pagh and Rodler in 2001 (see http://en.wikipedia.org/wiki/Cuckoo_hashing). Cuckoo hashing has worst-case O(1) lookups and can reach a high "load factor", in which the table can perform acceptably well even when approaching 90% full. Randomized testing shows this implementation of cuckoo hashing to be slightly faster on insert and slightly slower on lookup than Data.HashTable.ST.Basic, while being more space efficient by about a half-word per key-value mapping. Cuckoo hashing, like the basic hash table implementation using linear probing, can suffer from long delays when the table is resized.

  2. Data.HashTable.ST.Basic contains a basic open-addressing hash table using linear probing as the collision strategy. On a pure speed basis it should currently be the fastest available Haskell hash table implementation for lookups, although it has a higher memory overhead than the other tables and can suffer from long delays when the table is resized because all of the elements in the table need to be rehashed.

  3. Data.HashTable.ST.Linear contains a linear hash table (see http://en.wikipedia.org/wiki/Linear_hashing), which trades some insert and lookup performance for higher space efficiency and much shorter delays when expanding the table. In most cases, benchmarks show this table to be currently slightly faster than Data.HashTable from the Haskell base library.

It is recommended to create a concrete type alias in your code when using this package, i.e.:

import qualified Data.HashTable.IO as H

type HashTable k v = H.BasicHashTable k v

foo :: IO (HashTable Int Int)
foo = do
    ht <- H.new
    H.insert ht 1 1
    return ht

Firstly, this makes it easy to switch to a different hash table implementation, and secondly, using a concrete type rather than leaving your functions abstract in the HashTable class should allow GHC to optimize away the typeclass dictionaries.

This package accepts a couple of different cabal flags:

Please send bug reports to https://github.com/gregorycollins/hashtables/issues.


[Skip to Readme]

Properties

Versions 1.0.0.0, 1.0.1.0, 1.0.1.1, 1.0.1.2, 1.0.1.3, 1.0.1.4, 1.0.1.5, 1.0.1.6, 1.0.1.7, 1.0.1.8, 1.1.0.0, 1.1.0.1, 1.1.0.2, 1.1.2.0, 1.1.2.1, 1.2.0.0, 1.2.0.1, 1.2.0.2, 1.2.1.0, 1.2.1.1, 1.2.2.0, 1.2.2.1, 1.2.3.0, 1.2.3.1, 1.2.3.2, 1.2.3.3, 1.2.3.4, 1.2.4.0, 1.2.4.1, 1.2.4.2, 1.3, 1.3.1, 1.4.0, 1.4.0, 1.4.1
Change log changelog.md
Dependencies base (>=4.7 && <5), ghc-prim, hashable (>=1.4 && <1.6), primitive, vector (>=0.7 && <0.14) [details]
License BSD-3-Clause
Copyright (c) 2011-2014, Google, Inc., 2016-present contributors
Author Gregory Collins
Maintainer greg@gregorycollins.net, mgoremeier@gmail.com, erikd@mega-nerd.com
Category Data
Home page http://github.com/gregorycollins/hashtables
Source repo head: git clone https://github.com/gregorycollins/hashtables.git
Uploaded by ErikDeCastroLopo at 2024-11-19T03:50:24Z

Modules

[Index] [Quick Jump]

Flags

Manual Flags

NameDescriptionDefault
debug

if on, spew debugging output to stdout

Disabled
detailed-profiling

add detailed profiling information to profiled build-depends

Disabled
Automatic Flags
NameDescriptionDefault
unsafe-tricks

turn on unsafe GHC tricks

Enabled
bounds-checking

if on, use bounds-checking array accesses

Disabled
sse42

if on, use SSE 4.2 extensions to search cache lines very efficiently. The portable flag forces this off.

Disabled
portable

if on, use only pure Haskell code and no GHC extensions.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for hashtables-1.4.0

[back to package description]

This package provides a couple of different implementations of mutable hash tables in the ST monad, as well as a typeclass abstracting their common operations, and a set of wrappers to use the hash tables in the IO monad.

Quick start: documentation for the hash table operations is provided in the Data.HashTable.Class module, and the IO wrappers are located in the Data.HashTable.IO module.

This package currently contains three hash table implementations:

  1. Data.HashTable.ST.Basic contains a basic open-addressing hash table using linear probing as the collision strategy. On a pure speed basis it should currently be the fastest available Haskell hash table implementation for lookups, although it has a higher memory overhead than the other tables and can suffer from long delays when the table is resized because all of the elements in the table need to be rehashed.

  2. Data.HashTable.ST.Cuckoo contains an implementation of "cuckoo hashing" as introduced by Pagh and Rodler in 2001 (see [http://en.wikipedia.org/wiki/Cuckoo\_hashing](http://en.wikipedia.org/wiki/Cuckoo_hashing)). Cuckoo hashing has worst-case /O(1)/ lookups and can reach a high "load factor", in which the table can perform acceptably well even when more than 90% full. Randomized testing shows this implementation of cuckoo hashing to be slightly faster on insert and slightly slower on lookup than Data.Hashtable.ST.Basic, while being more space efficient by about a half-word per key-value mapping. Cuckoo hashing, like the basic hash table implementation using linear probing, can suffer from long delays when the table is resized.

  3. Data.HashTable.ST.Linear contains a linear hash table (see [http://en.wikipedia.org/wiki/Linear\_hashing](http://en.wikipedia.org/wiki/Linear_hashing)), which trades some insert and lookup performance for higher space efficiency and much shorter delays when expanding the table. In most cases, benchmarks show this table to be currently slightly faster than Data.HashTable from the Haskell base library.

It is recommended to create a concrete type alias in your code when using this package, i.e.:

import qualified Data.HashTable.IO as H

type HashTable k v = H.BasicHashTable k v

foo :: IO (HashTable Int Int)
foo = do
    ht <- H.new
    H.insert ht 1 1
    return ht

Firstly, this makes it easy to switch to a different hash table implementation, and secondly, using a concrete type rather than leaving your functions abstract in the HashTable class should allow GHC to optimize away the typeclass dictionaries.

This package accepts a couple of different cabal flags: