Safe Haskell | Safe-Inferred |
---|
- data AllocFailure
- data Statistics = Statistics {}
- percentFree :: Statistics -> Double
- percentUsed :: Statistics -> Double
- class IdAllocator a where
- type Id a
- alloc :: Failure AllocFailure m => a -> m (Id a, a)
- free :: Failure AllocFailure m => Id a -> a -> m a
- statistics :: a -> Statistics
- allocMany :: (IdAllocator a, Failure AllocFailure m) => Int -> a -> m ([Id a], a)
- freeMany :: (IdAllocator a, Failure AllocFailure m) => [Id a] -> a -> m a
- class IdAllocator a => RangeAllocator a where
- allocRange :: Failure AllocFailure m => Int -> a -> m (Range (Id a), a)
- freeRange :: Failure AllocFailure m => Range (Id a) -> a -> m a
Allocation errors
data AllocFailure Source
Failure type for allocators.
Allocator statistics
percentFree :: Statistics -> DoubleSource
Percentage of currently available identifiers.
percentFree s = numFree s / numAvailable s percentFree s + percentUsed s = 1
percentUsed :: Statistics -> DoubleSource
Percentage of identifiers currently in use.
percentUsed s = numUsed s / numAvailable s percentUsed s + percentFree s = 1
Allocator classes
class IdAllocator a whereSource
IdAllocator provides an interface for allocating and releasing identifiers that correspond to server resources, such as node, buffer and bus ids.
alloc :: Failure AllocFailure m => a -> m (Id a, a)Source
Allocate a new identifier and return the changed allocator.
free :: Failure AllocFailure m => Id a -> a -> m aSource
Free a previously allocated identifier and return the changed allocator.
Freeing an identifier that hasn't been allocated with this allocator may trigger a failure.
statistics :: a -> StatisticsSource
Return usage statistics.
allocMany :: (IdAllocator a, Failure AllocFailure m) => Int -> a -> m ([Id a], a)Source
Allocate a number of (not necessarily consecutive) IDs with the given allocator.
Returns the list of IDs and the modified allocator.
freeMany :: (IdAllocator a, Failure AllocFailure m) => [Id a] -> a -> m aSource
Free a number of IDs with the given allocator.
Returns the modified allocator.
class IdAllocator a => RangeAllocator a whereSource
RangeAllocator provides an interface for allocating and releasing ranges of consecutive identifiers.
allocRange :: Failure AllocFailure m => Int -> a -> m (Range (Id a), a)Source
Allocate n consecutive identifiers and return the changed allocator.
freeRange :: Failure AllocFailure m => Range (Id a) -> a -> m aSource
Free a range of previously allocated identifiers and return the changed allocator.