Copyright | (c) Alex Semin, 2015 |
---|---|
License | BSD3 |
Maintainer | alllex.semin@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Concurrent Priority Queue implemented over Haskell STM. This container allows to store items supplied with key and provides efficient way to retrive item with the smallest key.
import Control.Concurrent.STM import qualified Data.STM.PriorityQueue as PQ import Control.Monad ( forM_ ) main :: IO () main = do pq <- atomically $ (PQ.new :: STM (PQ.Impl Int Int)) let kvs = [(2, 1), (5, 3), (1, 2), (4, 5)] forM_ kvs $ \(k, v) -> atomically $ PQ.insert pq k v x <- atomically $ PQ.deleteMin pq putStrLn $ "x = " ++ show x -- prints 2
Documentation
class PriorityQueue q where Source
new :: Ord k => STM (q k v) Source
O(1). Creates empty priority queue.
insert :: Ord k => q k v -> k -> v -> STM () Source
O(log(n)). Performs insertion of an item with key. | Note: depending on the implementation time complexity may be better.
peekMin :: Ord k => q k v -> STM v Source
O(1). Returns an item with the smallest key without removing it.
deleteMin :: Ord k => q k v -> STM v Source
O(log(n)). Returns an item with the smallest key and removes it. | Note: depending on the implementation time complexity may be better.
tryDeleteMin :: Ord k => q k v -> STM (Maybe v) Source
O(log(n)). Tries to delete item and returns if transaction fails. | Note: depending on the implementation time complexity may be better.