Skip to content

Commit

Permalink
Hlint cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bhickey committed Mar 15, 2010
1 parent c58c936 commit 5819a0e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Data/Heap/Binary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data (Ord n) => BinaryHeap n =

instance (Ord n, Show n) => Show (BinaryHeap n) where
show Leaf = "Leaf"
show (Node n _ h1 h2) = "Node " ++ (show n) ++ " (" ++ (show h1) ++ " " ++ (show h2) ++ ")"
show (Node n _ h1 h2) = "Node " ++ show n ++ " (" ++ show h1 ++ " " ++ show h2 ++ ")"

rank :: (Ord n) => BinaryHeap n -> Int
rank Leaf = 0
Expand All @@ -35,10 +35,10 @@ merge :: (Ord a) => BinaryHeap a -> BinaryHeap a -> BinaryHeap a
merge Leaf n = n
merge n Leaf = n
merge h1@(Node n1 d1 h1l h1r) h2@(Node n2 d2 _ _) =
if (n1<n2 || (n1==n2 && d1<=d2))
if n1<n2 || (n1==n2 && d1<=d2)
then if rank h1l < rank h1r
then (Node n1 (d1 + d2) (merge h1l h2) h1r)
else (Node n1 (d1 + d2) h1l (merge h1r h2))
then Node n1 (d1 + d2) (merge h1l h2) h1r
else Node n1 (d1 + d2) h1l (merge h1r h2)
else merge h2 h1

-- | /O(lg n)/.
Expand All @@ -53,15 +53,15 @@ null _ = False
-- | /O(n lg n)/.
toList :: (Ord a) => BinaryHeap a -> [a]
toList Leaf = []
toList h@(Node _ _ _ _) = (head h):(toList $ tail h)
toList h@(Node _ _ _ _) = head h : toList (tail h)

-- | /O(n)/. 'fromList' constructs a binary heap from an unsorted list.
fromList :: (Ord a) => [a] -> BinaryHeap a
fromList [] = Leaf
fromList l = mergeList (map singleton l)
where mergeList [a] = a
mergeList x = mergeList (mergePairs x)
mergePairs (a:b:c) = (merge a b):(mergePairs c)
mergePairs (a:b:c) = merge a b : mergePairs c
mergePairs x = x

-- | /O(1)/. 'head' returns the element root of the heap.
Expand Down

0 comments on commit 5819a0e

Please sign in to comment.