Copyright | (c) Andrea Bellandi 2014 |
---|---|
License | GPL-3 |
Maintainer | bellaz89@gmai.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
FrequencyQueue.IO
Contents
Description
This module export the IO interface of FrequencyQueue.
- data FrequencyQueue a
- newFrequencyQueue :: Int -> IO (FrequencyQueue a)
- cloneFrequencyQueue :: FrequencyQueue a -> IO (FrequencyQueue a)
- length :: FrequencyQueue a -> IO Int
- probabilityUnit :: FrequencyQueue a -> IO Int
- pushBack :: FrequencyQueue a -> a -> Int -> IO ()
- popBack :: FrequencyQueue a -> IO (Maybe (a, Int))
- popBackMax :: FrequencyQueue a -> IO (Maybe (a, Int))
- popBackMin :: FrequencyQueue a -> IO (Maybe (a, Int))
- getRandom :: FrequencyQueue a -> IO (Maybe (a, Int))
- getRandomPop :: FrequencyQueue a -> IO (Maybe (a, Int))
- mapWprobability :: ((a, Int) -> (b, Int)) -> FrequencyQueue a -> IO (FrequencyQueue b)
- foldWprobability :: (b -> (a, Int) -> b) -> b -> FrequencyQueue a -> IO b
- popBackUnsafe :: FrequencyQueue a -> IO (a, Int)
- popBackMaxUnsafe :: FrequencyQueue a -> IO (a, Int)
- popBackMinUnsafe :: FrequencyQueue a -> IO (a, Int)
- getRandomUnsafe :: FrequencyQueue a -> IO (a, Int)
- getRandomPopUnsafe :: FrequencyQueue a -> IO (a, Int)
Types
data FrequencyQueue a
FrequencyQueue the basic type of the Library
Instances
Functor FrequencyQueue | |
Foldable FrequencyQueue |
Functions
Creation functions
newFrequencyQueue :: Int -> IO (FrequencyQueue a)
Create a new FrequencyQueue with a seed
cloneFrequencyQueue :: FrequencyQueue a -> IO (FrequencyQueue a)
Make a clone of the FrequencyQueue Passed
Basic properties
length :: FrequencyQueue a -> IO Int
Return the number of elements in the queue
probabilityUnit :: FrequencyQueue a -> IO Int
Return the sum of all elements' probabilities passed to the queue
Pop-push functions
pushBack :: FrequencyQueue a -> a -> Int -> IO ()
Push an element a in the queue with a corresponding relative probability
popBack :: FrequencyQueue a -> IO (Maybe (a, Int))
Pop an element of the queue. Return Nothing if the queue is empty
popBackMax :: FrequencyQueue a -> IO (Maybe (a, Int))
Pop the element of the queue that have the biggest relative probability. Return Nothing if the queue is empty
popBackMin :: FrequencyQueue a -> IO (Maybe (a, Int))
Pop the element of the queue that have the smallest relative probability. Return Nothing if the queue is empty
getRandom :: FrequencyQueue a -> IO (Maybe (a, Int))
Return a random element from the queue using its relative probability. Return Nothing if the queue is empty
getRandomPop :: FrequencyQueue a -> IO (Maybe (a, Int))
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 -> IO (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 -> IO 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 -> IO (a, Int)
Pop an element of the queue. Fail if empty
popBackMaxUnsafe :: FrequencyQueue a -> IO (a, Int)
Pop the element of the queue that have the biggest relative probability. Fail if empty
popBackMinUnsafe :: FrequencyQueue a -> IO (a, Int)
Pop the element of the queue that have the smallest relative probability. Fail if empty
getRandomUnsafe :: FrequencyQueue a -> IO (a, Int)
Pop the element of the queue that have the smallest relative probability. Fail if empty
getRandomPopUnsafe :: FrequencyQueue a -> IO (a, Int)
Pop a random element from the queue using its relative probability. Fail if empty