muesli-0.1.1.0: A simple document-oriented database

Copyright(c) 2015 Călin Ardelean
LicenseMIT
MaintainerCălin Ardelean <calinucs@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010
ExtensionsMultiWayIf

Database.Muesli.IdSupply

Description

Unique DocumentKey allocation functions.

Since we use IntMaps for our indexes, a (faster) auto-incremented key will be exhausted on 32 bit machines before we reach a maxBound number of documents, because deleted keys cannot be reused.

This module should be imported qualified.

Synopsis

Documentation

type IdSupply = IntMap Int Source

A map from keys to gap sizes.

empty :: IdSupply Source

Holds a single gap of size maxBound - 1, starting at address 1.

reserve :: DocumentKey -> IdSupply -> IdSupply Source

Removes a key from the supply. Used during log loading.

alloc :: IdSupply -> (DocumentKey, IdSupply) Source

Allocates a fresh key from the supply.

Favours smallest numbers. For instance, after a document is deleted and garbage collected, the DocumentKey of that document typically becomes the smallest, and thus the first available. For this reason, IdSupply will normally be small and efficient.