HFrequencyQueue-0.2.0.0: A Queue with a random (weighted) pick function

Copyright(c) Andrea Bellandi 2014
LicenseGPL-3
Maintainerbellaz89@gmai.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

FrequencyQueue.IO

Contents

Description

This module export the IO interface of FrequencyQueue.

Synopsis

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