Repository : ssh://darcs.haskell.org//srv/darcs/packages/containers On branch : master
http://hackage.haskell.org/trac/ghc/changeset/f461aea96e8294a93264fcd09152f2ebef1cd531 >--------------------------------------------------------------- commit f461aea96e8294a93264fcd09152f2ebef1cd531 Author: Milan Straka <[email protected]> Date: Mon Dec 5 22:14:46 2011 +0100 Int{Set.Map}.delete{Min,Max} doesn't fail on empty. Make Int{Map,Set}.delete{Min,Max} behave like {Map,Set}.delete{Min,Max}. * Old behaviour: Int{Set,Map}.delete{Min,Max} empty ==> error * New behaviour: Int{Set,Map}.delete{Min,Max} empty == empty >--------------------------------------------------------------- Data/IntMap/Base.hs | 4 ++-- Data/IntSet.hs | 4 ++-- tests/intmap-properties.hs | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Data/IntMap/Base.hs b/Data/IntMap/Base.hs index c8c96c2..0ca3480 100644 --- a/Data/IntMap/Base.hs +++ b/Data/IntMap/Base.hs @@ -987,12 +987,12 @@ findMax (Bin _ m l r) -- | /O(log n)/. Delete the minimal key. An error is thrown if the IntMap is already empty. -- Note, this is not the same behavior Map. deleteMin :: IntMap a -> IntMap a -deleteMin = maybe (error "deleteMin: empty map has no minimal element") snd . minView +deleteMin = maybe Nil snd . minView -- | /O(log n)/. Delete the maximal key. An error is thrown if the IntMap is already empty. -- Note, this is not the same behavior Map. deleteMax :: IntMap a -> IntMap a -deleteMax = maybe (error "deleteMax: empty map has no maximal element") snd . maxView +deleteMax = maybe Nil snd . maxView {-------------------------------------------------------------------- diff --git a/Data/IntSet.hs b/Data/IntSet.hs index ff66b47..4f5c3dd 100644 --- a/Data/IntSet.hs +++ b/Data/IntSet.hs @@ -675,11 +675,11 @@ findMax (Bin _ m l r) -- | /O(min(n,W))/. Delete the minimal element. deleteMin :: IntSet -> IntSet -deleteMin = maybe (error "deleteMin: empty set has no minimal element") snd . minView +deleteMin = maybe Nil snd . minView -- | /O(min(n,W))/. Delete the maximal element. deleteMax :: IntSet -> IntSet -deleteMax = maybe (error "deleteMax: empty set has no maximal element") snd . maxView +deleteMax = maybe Nil snd . maxView {---------------------------------------------------------------------- Map diff --git a/tests/intmap-properties.hs b/tests/intmap-properties.hs index 534b829..93d9eb9 100644 --- a/tests/intmap-properties.hs +++ b/tests/intmap-properties.hs @@ -614,10 +614,12 @@ test_findMax = findMax (fromList [(5,"a"), (3,"b")]) @?= (5,"a") test_deleteMin :: Assertion test_deleteMin = do deleteMin (fromList [(5,"a"), (3,"b"), (7,"c")]) @?= fromList [(5,"a"), (7,"c")] + deleteMin (empty :: SMap) @?= empty test_deleteMax :: Assertion test_deleteMax = do deleteMax (fromList [(5,"a"), (3,"b"), (7,"c")]) @?= fromList [(3,"b"), (5,"a")] + deleteMin (empty :: SMap) @?= empty test_deleteFindMin :: Assertion test_deleteFindMin = deleteFindMin (fromList [(5,"a"), (3,"b"), (10,"c")]) @?= ("b", fromList[(5,"a"), (10,"c")]) _______________________________________________ Cvs-libraries mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-libraries
