diskhash-0.0.4.2: Disk-based hash table

Safe HaskellNone
LanguageHaskell2010

Data.DiskHash

Description

Disk based hash table

The Haskell interface has two types, distinguishing between read-only and read-write hash tables. Operations on the RW variant are in the IO monad, while operations on RO tables are all pure (after the htOpenRO call, naturally). Using read-write hashtables with more than one thread is undefined behaviour, but the read-only variant is perfectly thread safe.

All data structures are strict (naturally: they write to disk).

The Haskell API can be used to access diskhashes created from other languages as long as the types are compatible.

Synopsis

Documentation

data DiskHashRO a Source #

Represents a read-only diskhash storing type a

data DiskHashRW a Source #

Represents a read-write diskhash storing type a

htOpenRO Source #

Arguments

:: Storable a 
=> FilePath

file path

-> Int

maximum key size

-> IO (DiskHashRO a) 

open a hash table in read-only mode

The maxk argument can be 0, in which case the value of the maximum key will be taken from the disk file. If not zero, then it is checked against the value on disk and an exception is raised if there is a mismatch.

htLoadRO Source #

Arguments

:: Storable a 
=> FilePath

file path

-> Int

maximum key size

-> IO (DiskHashRO a) 

open a hash table in read-only mode and load it into memory

The maxk argument can be 0, in which case the value of the maximum key will be taken from the disk file. If not zero, then it is checked against the value on disk and an exception is raised if there is a mismatch.

Since: 0.0.4.0

htOpenRW Source #

Arguments

:: Storable a 
=> FilePath

file path

-> Int

maximum key size

-> IO (DiskHashRW a) 

open a hash table in read-write mode

withDiskHashRW Source #

Arguments

:: Storable a 
=> FilePath

file path

-> Int

maximum key size

-> (DiskHashRW a -> IO b) 
-> IO b 

Open a hash table in read-write mode and pass it to an action

Once the action is is complete, the hashtable is closed (and sync'ed to disk).

htLookupRO :: Storable a => ByteString -> DiskHashRO a -> Maybe a Source #

Lookup by key

This is a pure operation

htLookupRW Source #

Arguments

:: Storable a 
=> ByteString

key

-> DiskHashRW a 
-> IO (Maybe a) 

Lookup by key

This is in the IO Monad to ensure ordering of operations.

htSizeRW :: DiskHashRW a -> IO Int Source #

Retrieve the size of the hash table

htSizeRO :: DiskHashRO a -> Int Source #

Retrieve the size of the hash table

htInsert Source #

Arguments

:: Storable a 
=> ByteString

key

-> a

value

-> DiskHashRW a

hash table

-> IO Bool

True if inserted, False if not

insert an element into the hash table

Returns whether an insertion took place (if an object with that key already exists, no insertion is made).

This operation can fail (throwing an exception) if space could not be allocated. You can pre-allocate space using htReserve.

htModify :: Storable a => ByteString -> (a -> a) -> DiskHashRW a -> IO Bool Source #

Modify a value

htReserve :: Storable a => Int -> DiskHashRW a -> IO Int Source #

Reserve space in the hash table

Reserving space can ensure that any subsequent htInsert calls will not fail.

If the operation fails, an exception is raised