Skip to content

Commit df285a4

Browse files
committed
Array.shrink: Allow shrinking to length 0
At least in the context of `Array.filter` this seems useful and valid.
1 parent 13cf308 commit df285a4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Data/HashMap/Internal/Array.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ import qualified Prelude
114114
if (_k_) < 0 || (_k_) >= (_len_) then error ("Data.HashMap.Internal.Array." ++ (_func_) ++ ": bounds error, offset " ++ show (_k_) ++ ", length " ++ show (_len_)) else
115115
# define CHECK_OP(_func_,_op_,_lhs_,_rhs_) \
116116
if not ((_lhs_) _op_ (_rhs_)) then error ("Data.HashMap.Internal.Array." ++ (_func_) ++ ": Check failed: _lhs_ _op_ _rhs_ (" ++ show (_lhs_) ++ " vs. " ++ show (_rhs_) ++ ")") else
117+
# define CHECK_GE(_func_,_lhs_,_rhs_) CHECK_OP(_func_,>=,_lhs_,_rhs_)
117118
# define CHECK_GT(_func_,_lhs_,_rhs_) CHECK_OP(_func_,>,_lhs_,_rhs_)
118119
# define CHECK_LE(_func_,_lhs_,_rhs_) CHECK_OP(_func_,<=,_lhs_,_rhs_)
119120
# define CHECK_EQ(_func_,_lhs_,_rhs_) CHECK_OP(_func_,==,_lhs_,_rhs_)
120121
#else
121122
# define CHECK_BOUNDS(_func_,_len_,_k_)
122123
# define CHECK_OP(_func_,_op_,_lhs_,_rhs_)
124+
# define CHECK_GE(_func_,_lhs_,_rhs_)
123125
# define CHECK_GT(_func_,_lhs_,_rhs_)
124126
# define CHECK_LE(_func_,_lhs_,_rhs_)
125127
# define CHECK_EQ(_func_,_lhs_,_rhs_)
@@ -222,7 +224,7 @@ new_ n = new n undefinedElem
222224
-- | The returned array is the same as the array given, as it is shrunk in place.
223225
shrink :: MArray s a -> Int -> ST s (MArray s a)
224226
shrink mary _n@(I# n#) =
225-
CHECK_GT("shrink", _n, (0 :: Int))
227+
CHECK_GE("shrink", _n, (0 :: Int))
226228
CHECK_LE("shrink", _n, (unsafeLengthM mary))
227229
ST $ \s -> case Exts.shrinkSmallMutableArray# (unMArray mary) n# s of
228230
s' -> (# s', mary #)

0 commit comments

Comments
 (0)