-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Asymptotically optimal Brodal/Okasaki heaps.
--   
--   Asymptotically optimal Brodal/Okasaki bootstrapped skew-binomial heaps
--   from the paper "Optimal Purely Functional Priority Queues",
--   extended with a Foldable interface.
@package heaps
@version 0.4.1

-- | An efficient, asymptotically optimal, implementation of a priority
--   queues extended with support for efficient size, and Foldable
--   
--   Note: Since many function names (but not the type name) clash
--   with Prelude names, this module is usually imported
--   qualified, e.g.
--   
--   
--   import Data.Heap (Heap)
--   import qualified Data.Heap as Heap
--   
--   
--   The implementation of Heap is based on bootstrapped skew
--   binomial heaps as described by:
--   
--   
--   
- G. Brodal and C. Okasaki , "Optimal Purely Functional Priority
--   Queues", Journal of Functional Programming 6:839-857
--   (1996)
--   
--   
--   All time bounds are worst-case.
module Data.Heap

-- | A min-heap of values of type a.
data Heap a

-- | Explicit priority/payload tuples. Useful to build a priority queue
--   using a Heap, since the payload is ignored in the Eq/Ord
--   instances.
--   
--   
--   myHeap = fromList [Entry 2 "World", Entry 1 "Hello", Entry 3 "!"]
--   
--   ==> foldMap payload myHeap ≡ "HelloWorld!"
--   
data Entry p a
Entry :: p -> a -> Entry p a
[priority] :: Entry p a -> p
[payload] :: Entry p a -> a

-- | O(1). The empty heap
--   
--   
--   empty ≡ fromList []
--   
--   
--   
--   >>> size empty
--   0
--   
empty :: Heap a

-- | O(1). Is the heap empty?
--   
--   
--   >>> null empty
--   True
--   
--   
--   
--   >>> null (singleton "hello")
--   False
--   
null :: Heap a -> Bool

-- | O(1). The number of elements in the heap.
--   
--   
--   >>> size empty
--   0
--   
--   >>> size (singleton "hello")
--   1
--   
--   >>> size (fromList [4,1,2])
--   3
--   
size :: Heap a -> Int

-- | O(1). A heap with a single element
--   
--   
--   singleton x ≡ fromList [x]
--   singleton x ≡ insert x empty
--   
--   
--   
--   >>> size (singleton "hello")
--   1
--   
singleton :: Ord a => a -> Heap a

-- | O(1). Insert a new value into the heap.
--   
--   
--   >>> insert 2 (fromList [1,3])
--   fromList [1,2,3]
--   
--   
--   
--   insert x empty ≡ singleton x
--   size (insert x xs) ≡ 1 + size xs
--   
insert :: Ord a => a -> Heap a -> Heap a

-- | O(1). Assumes the argument is a non-null heap.
--   
--   
--   >>> minimum (fromList [3,1,2])
--   1
--   
minimum :: Heap a -> a

-- | O(log n). Delete the minimum key from the heap and return the
--   resulting heap.
--   
--   
--   >>> deleteMin (fromList [3,1,2])
--   fromList [2,3]
--   
deleteMin :: Heap a -> Heap a

-- | O(log n). Adjust the minimum key in the heap and return the
--   resulting heap.
--   
--   
--   >>> adjustMin (+1) (fromList [1,2,3])
--   fromList [2,2,3]
--   
adjustMin :: (a -> a) -> Heap a -> Heap a

-- | O(1). Meld the values from two heaps into one heap.
--   
--   
--   >>> union (fromList [1,3,5]) (fromList [6,4,2])
--   fromList [1,2,6,4,3,5]
--   
--   >>> union (fromList [1,1,1]) (fromList [1,2,1])
--   fromList [1,1,1,2,1,1]
--   
union :: Heap a -> Heap a -> Heap a

-- | Provides both O(1) access to the minimum element and O(log
--   n) access to the remainder of the heap. This is the same operation
--   as viewMin
--   
--   
--   >>> uncons (fromList [2,1,3])
--   Just (1,fromList [2,3])
--   
uncons :: Heap a -> Maybe (a, Heap a)

-- | Same as uncons
viewMin :: Heap a -> Maybe (a, Heap a)

-- | O(n). Map a monotone increasing function over the heap.
--   Provides a better constant factor for performance than map, but
--   no checking is performed that the function provided is monotone
--   increasing. Misuse of this function can cause a Heap to violate the
--   heap property.
--   
--   
--   >>> mapMonotonic (+1) (fromList [1,2,3])
--   fromList [2,3,4]
--   
--   >>> mapMonotonic (*2) (fromList [1,2,3])
--   fromList [2,4,6]
--   
mapMonotonic :: Ord b => (a -> b) -> Heap a -> Heap b

-- | O(n). Map a function over the heap, returning a new heap
--   ordered appropriately for its fresh contents
--   
--   
--   >>> map negate (fromList [3,1,2])
--   fromList [-3,-1,-2]
--   
map :: Ord b => (a -> b) -> Heap a -> Heap b

-- | O(n). Returns the elements in the heap in some arbitrary, very
--   likely unsorted, order.
--   
--   
--   >>> toUnsortedList (fromList [3,1,2])
--   [1,3,2]
--   
--   
--   
--   fromList . toUnsortedList ≡ id
--   
toUnsortedList :: Heap a -> [a]

-- | O(n). Build a heap from a list of values.
--   
--   
--   fromList . toList ≡ id
--   toList . fromList ≡ sort
--   
fromList :: Ord a => [a] -> Heap a

-- | O(n log n). Perform a heap sort
sort :: Ord a => [a] -> [a]

-- | O(n log n). Traverse the elements of the heap in sorted order
--   and produce a new heap using Applicative side-effects.
traverse :: (Applicative t, Ord b) => (a -> t b) -> Heap a -> t (Heap b)

-- | O(n log n). Traverse the elements of the heap in sorted order
--   and produce a new heap using Monadic side-effects.
mapM :: (Monad m, Ord b) => (a -> m b) -> Heap a -> m (Heap b)

-- | O(n). Construct heaps from each element in another heap, and
--   union them together.
--   
--   
--   >>> concatMap (\a -> fromList [a,a+1]) (fromList [1,4])
--   fromList [1,4,5,2]
--   
concatMap :: (a -> Heap b) -> Heap a -> Heap b

-- | O(n). Filter the heap, retaining only values that satisfy the
--   predicate.
--   
--   
--   >>> filter (>'a') (fromList "ab")
--   fromList "b"
--   
--   >>> filter (>'x') (fromList "ab")
--   fromList []
--   
--   >>> filter (<'a') (fromList "ab")
--   fromList []
--   
filter :: (a -> Bool) -> Heap a -> Heap a

-- | O(n). Partition the heap according to a predicate. The first
--   heap contains all elements that satisfy the predicate, the second all
--   elements that fail the predicate. See also split.
--   
--   
--   >>> partition (>'a') (fromList "ab")
--   (fromList "b",fromList "a")
--   
partition :: (a -> Bool) -> Heap a -> (Heap a, Heap a)

-- | O(n). Partition the heap into heaps of the elements that are
--   less than, equal to, and greater than a given value.
--   
--   
--   >>> split 'h' (fromList "hello")
--   (fromList "e",fromList "h",fromList "llo")
--   
split :: a -> Heap a -> (Heap a, Heap a, Heap a)

-- | O(n log n). break applied to a predicate p and
--   a heap xs returns a tuple where the first element is a heap
--   consisting of the longest prefix the least elements of xs
--   that do not satisfy p and the second element is the remainder
--   of the elements in the heap.
--   
--   
--   >>> break (\x -> x `mod` 4 == 0) (fromList [3,5,7,12,13,16])
--   (fromList [3,5,7],fromList [12,13,16])
--   
--   
--   break p is equivalent to span (not .
--   p).
break :: (a -> Bool) -> Heap a -> (Heap a, Heap a)

-- | O(n log n). span applied to a predicate p and a
--   heap xs returns a tuple where the first element is a heap
--   consisting of the longest prefix the least elements of xs that satisfy
--   p and the second element is the remainder of the elements in
--   the heap.
--   
--   
--   >>> span (\x -> x `mod` 4 == 0) (fromList [4,8,12,14,16])
--   (fromList [4,8,12],fromList [14,16])
--   
--   
--   span p xs is equivalent to (takeWhile p xs,
--   dropWhile p xs)
span :: (a -> Bool) -> Heap a -> (Heap a, Heap a)

-- | O(n log n). Return a heap consisting of the least n
--   elements of a given heap.
--   
--   
--   >>> take 3 (fromList [10,2,4,1,9,8,2])
--   fromList [1,2,2]
--   
take :: Int -> Heap a -> Heap a

-- | O(n log n). Return a heap consisting of all members of given
--   heap except for the n least elements.
drop :: Int -> Heap a -> Heap a

-- | O(n log n). Split a heap into two heaps, the first containing
--   the n least elements, the latter consisting of all members of
--   the heap except for those elements.
splitAt :: Int -> Heap a -> (Heap a, Heap a)

-- | O(n log n). takeWhile applied to a predicate p
--   and a heap xs returns a heap consisting of the longest prefix
--   the least elements of xs that satisfy p.
--   
--   
--   >>> takeWhile (\x -> x `mod` 4 == 0) (fromList [4,8,12,14,16])
--   fromList [4,8,12]
--   
takeWhile :: (a -> Bool) -> Heap a -> Heap a

-- | O(n log n). dropWhile p xs returns the suffix
--   of the heap remaining after takeWhile p xs.
--   
--   
--   >>> dropWhile (\x -> x `mod` 4 == 0) (fromList [4,8,12,14,16])
--   fromList [14,16]
--   
dropWhile :: (a -> Bool) -> Heap a -> Heap a

-- | O(n log n). Group a heap into a heap of heaps, by unioning
--   together duplicates.
--   
--   
--   >>> group (fromList "hello")
--   fromList [fromList "e",fromList "h",fromList "ll",fromList "o"]
--   
group :: Heap a -> Heap (Heap a)

-- | O(n log n). Group using a user supplied function.
groupBy :: (a -> a -> Bool) -> Heap a -> Heap (Heap a)

-- | O(n log n). Remove duplicate entries from the heap.
--   
--   
--   >>> nub (fromList [1,1,2,6,6])
--   fromList [1,2,6]
--   
nub :: Heap a -> Heap a

-- | O(n log n + m log m). Intersect the values in two heaps,
--   returning the value in the left heap that compares as equal
intersect :: Heap a -> Heap a -> Heap a

-- | O(n log n + m log m). Intersect the values in two heaps using a
--   function to generate the elements in the right heap.
intersectWith :: Ord b => (a -> a -> b) -> Heap a -> Heap a -> Heap b

-- | O(log n). Create a heap consisting of multiple copies of the
--   same value.
--   
--   
--   >>> replicate 'a' 10
--   fromList "aaaaaaaaaa"
--   
replicate :: Ord a => a -> Int -> Heap a
instance Data.Bifunctor.Bifunctor Data.Heap.Entry
instance (GHC.Internal.Data.Data.Data p, GHC.Internal.Data.Data.Data a) => GHC.Internal.Data.Data.Data (Data.Heap.Entry p a)
instance (GHC.Classes.Ord a, GHC.Internal.Data.Data.Data a) => GHC.Internal.Data.Data.Data (Data.Heap.Heap a)
instance GHC.Classes.Eq p => GHC.Classes.Eq (Data.Heap.Entry p a)
instance GHC.Classes.Eq (Data.Heap.Heap a)
instance GHC.Internal.Data.Foldable.Foldable (Data.Heap.Entry p)
instance GHC.Internal.Data.Foldable.Foldable Data.Heap.Forest
instance GHC.Internal.Data.Foldable.Foldable Data.Heap.Heap
instance GHC.Internal.Data.Foldable.Foldable Data.Heap.Tree
instance GHC.Internal.Base.Functor (Data.Heap.Entry p)
instance GHC.Internal.Base.Functor Data.Heap.Forest
instance GHC.Internal.Base.Functor Data.Heap.Tree
instance GHC.Internal.Base.Monoid (Data.Heap.Heap a)
instance GHC.Classes.Ord p => GHC.Classes.Ord (Data.Heap.Entry p a)
instance GHC.Classes.Ord (Data.Heap.Heap a)
instance (GHC.Internal.Read.Read p, GHC.Internal.Read.Read a) => GHC.Internal.Read.Read (Data.Heap.Entry p a)
instance GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Heap.Forest a)
instance (GHC.Classes.Ord a, GHC.Internal.Read.Read a) => GHC.Internal.Read.Read (Data.Heap.Heap a)
instance GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Data.Heap.Tree a)
instance GHC.Internal.Base.Semigroup (Data.Heap.Heap a)
instance (GHC.Internal.Show.Show p, GHC.Internal.Show.Show a) => GHC.Internal.Show.Show (Data.Heap.Entry p a)
instance GHC.Internal.Show.Show a => GHC.Internal.Show.Show (Data.Heap.Forest a)
instance GHC.Internal.Show.Show a => GHC.Internal.Show.Show (Data.Heap.Heap a)
instance GHC.Internal.Show.Show a => GHC.Internal.Show.Show (Data.Heap.Tree a)
instance GHC.Internal.Data.Traversable.Traversable (Data.Heap.Entry p)
