concurrent-supply-0.1.8: A fast concurrent unique identifier supply with a pure API

Copyright | (C) 2011-2013 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | provisional
Portability | portable
Safe Haskell | Trustworthy
Language | Haskell2010

Control.Concurrent.Supply

Contents

- Variables
- Unboxed API

Description

A fast unique identifier supply with local pooling and replay support.

One often has a desire to generate a bunch of integer identifiers within a single process that are unique within that process. You could use UUIDs, but they can be expensive to generate; you don't want to have your threads contending for a single external counter if the identifier is not going to be used outside the process.

`concurrent-supply` builds a tree-like structure which can be split; you can make smaller unique supplies and then you allocate from your supplies locally. Internally it pulls from a unique supply one block at a time as you walk into parts of the tree that haven't been explored.

Synopsis

- data Supply
- newSupply :: IO Supply
- freshId :: Supply -> (Int, Supply)
- splitSupply :: Supply -> (Supply, Supply)
- freshId# :: Supply -> (# Int#, Supply #)
- splitSupply# :: Supply -> (# Supply, Supply #)

# Documentation

data Supply Source #

A user managed globally unique variable supply.

#### Instances

Instances details

Show Supply Source # |
Instance details Defined in Control.Concurrent.Supply Methods showsPrec :: Int -> Supply -> ShowS Source # show :: Supply -> String Source # showList :: [Supply] -> ShowS Source #
Eq Supply Source # |
Instance details Defined in Control.Concurrent.Supply Methods (==) :: Supply -> Supply -> Bool Source # (/=) :: Supply -> Supply -> Bool Source #
Ord Supply Source # |
Instance details Defined in Control.Concurrent.Supply Methods compare :: Supply -> Supply -> Ordering Source # (<) :: Supply -> Supply -> Bool Source # (<=) :: Supply -> Supply -> Bool Source # (>) :: Supply -> Supply -> Bool Source # (>=) :: Supply -> Supply -> Bool Source # max :: Supply -> Supply -> Supply Source # min :: Supply -> Supply -> Supply Source #
Hashable Supply Source # |
Instance details Defined in Control.Concurrent.Supply Methods hashWithSalt :: Int -> Supply -> Int Source # hash :: Supply -> Int Source #

# Variables

newSupply :: IO Supply Source #

Grab a new supply. Any two supplies obtained with newSupply are guaranteed to return disjoint sets of identifiers. Replaying the same sequence of operations on the same Supply will yield the same results.

freshId :: Supply -> (Int, Supply) Source #

Obtain a fresh Id from a Supply.

splitSupply :: Supply -> (Supply, Supply) Source #

Split a supply into two supplies that will return disjoint identifiers

# Unboxed API

freshId# :: Supply -> (# Int#, Supply #) Source #

An unboxed version of freshId

splitSupply# :: Supply -> (# Supply, Supply #) Source #

An unboxed version of splitSupply