Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- data DiskHashRO a
- data DiskHashRW a
- htOpenRO :: forall a. Storable a => FilePath -> Int -> IO (DiskHashRO a)
- htLoadRO :: forall a. Storable a => FilePath -> Int -> IO (DiskHashRO a)
- htOpenRW :: forall a. Storable a => FilePath -> Int -> IO (DiskHashRW a)
- withDiskHashRW :: Storable a => FilePath -> Int -> (DiskHashRW a -> IO b) -> IO b
- htLookupRO :: Storable a => ByteString -> DiskHashRO a -> Maybe a
- htLookupRW :: Storable a => ByteString -> DiskHashRW a -> IO (Maybe a)
- htSizeRW :: DiskHashRW a -> IO Int
- htSizeRO :: DiskHashRO a -> Int
- htInsert :: Storable a => ByteString -> a -> DiskHashRW a -> IO Bool
- htModify :: Storable a => ByteString -> (a -> a) -> DiskHashRW a -> IO Bool
- htReserve :: Storable a => Int -> DiskHashRW a -> IO Int
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
:: 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.
:: 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
:: Storable a | |
=> FilePath | file path |
-> Int | maximum key size |
-> IO (DiskHashRW a) |
open a hash table in read-write mode
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
:: Storable a | |
=> ByteString | key |
-> DiskHashRW a | |
-> IO (Maybe a) |
Lookup by key
This is in the IO Monad to ensure ordering of operations.
htSizeRO :: DiskHashRO a -> Int Source #
Retrieve the size of the hash table
:: 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