Heap.dcl 2.08 KB
Newer Older
Jurriën Stutterheim's avatar
Jurriën Stutterheim committed
1 2 3 4 5 6 7
definition module Data.Heap

from StdOverloaded import class < (..)
import StdClass
from Data.Maybe import :: Maybe
from StdFunc import o
import qualified Data.List as L
8
from Data.Monoid import class Monoid, class Semigroup
Jurriën Stutterheim's avatar
Jurriën Stutterheim committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

/**
 * Ported from Edward Kmett's Data.Heap by Jurriën Stutterheim 15-08-2014
 */

:: Heap a
  = Empty
  | Heap !Int (a -> a -> Bool) !(Tree a)

:: Tree a = Node Int a !(Forest a)

:: Forest a
  = Cons !(Tree a) !(Forest a)
  | Nil

instance == (Heap a)

instance < (Heap a)

28 29 30 31
instance Semigroup (Heap a)

instance Monoid (Heap a)

Jurriën Stutterheim's avatar
Jurriën Stutterheim committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
:: Entry p a = Entry p a

null :: (Heap a) -> Bool

size :: (Heap a) -> Int

//empty :: Heap a
empty :== Empty

//singleton :: a -> Heap a | Ord a
singleton x :== singletonWith (<=) x

//singletonWith :: (a a -> Bool) a -> Heap a
singletonWith f a :== Heap 1 f (Node 0 a Nil)

//insert :: a (Heap a) -> (Heap a) | Ord a
insert :== insertWith (<=)

insertWith :: (a a -> Bool) a (Heap a) -> Heap a

union :: (Heap a) (Heap a) -> Heap a

replicate :: a Int -> Heap a | Ord a

uncons :: (Heap a) -> Maybe (a, Heap a) | Ord a

//viewMin :: (Heap a) -> Maybe (a, Heap a) | Ord a
viewMin :== uncons

minimum :: (Heap a) -> a

trees :: (Forest a) -> [Tree a]

deleteMin :: (Heap a) -> Heap a

map :: (a -> b) (Heap a) -> Heap b | Ord b

mapMonotonic :: (a -> b) (Heap a) -> Heap b | Ord b

filter :: (a -> Bool) (Heap a) -> Heap a

partition :: (a -> Bool) (Heap a) -> (Heap a, Heap a)

split :: a (Heap a) -> (Heap a, Heap a, Heap a)

take :== withList o 'L'.take

drop :== withList o 'L'.drop

splitAt :== splitWithList o 'L'.splitAt

break :== splitWithList o 'L'.break

span :== splitWithList o 'L'.span

takeWhile :== withList o 'L'.takeWhile

dropWhile :== withList o 'L'.dropWhile

nub :: (Heap a) -> Heap a

concatMap :: (a -> Heap b) (Heap a) -> Heap b | Ord b

group :: (Heap a) -> Heap (Heap a)

groupBy :: (a a -> Bool) (Heap a) -> Heap (Heap a)

intersect :: (Heap a) (Heap a) -> Heap a

intersectWith :: (a a -> b) (Heap a) (Heap a) -> Heap b | Ord b

withList :: ([a] -> [a]) (Heap a) -> Heap a

splitWithList :: ([a] -> ([a], [a])) (Heap a) -> (Heap a, Heap a)