Copyright | (c) Andrea Bellandi 2014 |
---|---|
License | GPL-3 |
Maintainer | [email protected] |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
FrequencyQueue
Contents
Description
This module export the interface of FrequencyQueue.
- data FrequencyQueue a
- newFrequencyQueue :: Int -> FrequencyQueue a
- length :: FrequencyQueue a -> Int
- probabilityUnit :: FrequencyQueue a -> Int
- pushBack :: FrequencyQueue a -> a -> Int -> FrequencyQueue a
- popBack :: FrequencyQueue a -> Maybe ((a, Int), FrequencyQueue a)
- popBackMax :: FrequencyQueue a -> Maybe ((a, Int), FrequencyQueue a)
- popBackMin :: FrequencyQueue a -> Maybe ((a, Int), FrequencyQueue a)
- getRandom :: FrequencyQueue a -> Maybe ((a, Int), FrequencyQueue a)
- getRandomPop :: FrequencyQueue a -> Maybe ((a, Int), FrequencyQueue a)
- mapWprobability :: ((a, Int) -> (b, Int)) -> FrequencyQueue a -> FrequencyQueue b
- foldWprobability :: (b -> (a, Int) -> b) -> b -> FrequencyQueue a -> b
- popBackUnsafe :: FrequencyQueue a -> ((a, Int), FrequencyQueue a)
- popBackMaxUnsafe :: FrequencyQueue a -> ((a, Int), FrequencyQueue a)
- popBackMinUnsafe :: FrequencyQueue a -> ((a, Int), FrequencyQueue a)
- getRandomUnsafe :: FrequencyQueue a -> ((a, Int), FrequencyQueue a)
- getRandomPopUnsafe :: FrequencyQueue a -> ((a, Int), FrequencyQueue a)
Types
data FrequencyQueue a
FrequencyQueue the basic type of the Library
Instances
Functor FrequencyQueue | |
Foldable FrequencyQueue |
Functions
Creation functions
newFrequencyQueue :: Int -> FrequencyQueue a
Create a new FrequencyQueue with a seed
Basic properties
length :: FrequencyQueue a -> Int
Return the number of elements in the queue
probabilityUnit :: FrequencyQueue a -> Int
Return the sum of all elements' probabilities passed to the queue
Pop-push functions
pushBack :: FrequencyQueue a -> a -> Int -> FrequencyQueue a
Push an element a in the queue with a corresponding relative probability
popBack :: FrequencyQueue a -> Maybe ((a, Int), FrequencyQueue a)
Pop an element of the queue. Return Nothing if the queue is empty
popBackMax :: FrequencyQueue a -> Maybe ((a, Int), FrequencyQueue a)
Pop the element of the queue that have the biggest relative probability. Return Nothing if the queue is empty
popBackMin :: FrequencyQueue a -> Maybe ((a, Int), FrequencyQueue a)
Pop the element of the queue that have the smallest relative probability. Return Nothing if the queue is empty
getRandom :: FrequencyQueue a -> Maybe ((a, Int), FrequencyQueue a)
Return a random element from the queue using its relative probability. Return Nothing if the queue is empty
getRandomPop :: FrequencyQueue a -> Maybe ((a, Int), FrequencyQueue a)
Pop a random element from the queue using its relative probability. Return Nothing if the queue is empty
Iterative functions
mapWprobability :: ((a, Int) -> (b, Int)) -> FrequencyQueue a -> FrequencyQueue b
Return a new queue with the elements and relative probability mapped by the function provided
foldWprobability :: (b -> (a, Int) -> b) -> b -> FrequencyQueue a -> b
Return a folded value made by an initial value b and a folding function evaluated on the entire queue.
Unsafe interface
popBackUnsafe :: FrequencyQueue a -> ((a, Int), FrequencyQueue a)
Pop an element of the queue. Fail if empty
popBackMaxUnsafe :: FrequencyQueue a -> ((a, Int), FrequencyQueue a)
Pop the element of the queue that have the biggest relative probability. Fail if empty
popBackMinUnsafe :: FrequencyQueue a -> ((a, Int), FrequencyQueue a)
Pop the element of the queue that have the smallest relative probability. Fail if empty
getRandomUnsafe :: FrequencyQueue a -> ((a, Int), FrequencyQueue a)
Pop the element of the queue that have the smallest relative probability. Fail if empty
getRandomPopUnsafe :: FrequencyQueue a -> ((a, Int), FrequencyQueue a)
Pop a random element from the queue using its relative probability. Fail if empty