Skip to content

Commit 96a8dec

Browse files
authored
Delete findWithDefault for Strict Map and IntMap (#1020)
They are redundant because they have the same strictness characteristics as the lazy versions.
1 parent 8d52e0d commit 96a8dec

File tree

2 files changed

+2
-48
lines changed

2 files changed

+2
-48
lines changed

containers/src/Data/IntMap/Strict/Internal.hs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ import Data.IntMap.Internal
316316
, isSubmapOf
317317
, isSubmapOfBy
318318
, lookup
319+
, findWithDefault
319320
, lookupLE
320321
, lookupGE
321322
, lookupLT
@@ -358,28 +359,6 @@ import Utils.Containers.Internal.BitUtil
358359
import Utils.Containers.Internal.StrictPair
359360
import qualified Data.Foldable as Foldable
360361

361-
{--------------------------------------------------------------------
362-
Query
363-
--------------------------------------------------------------------}
364-
365-
-- | \(O(\min(n,W))\). The expression @('findWithDefault' def k map)@
366-
-- returns the value at key @k@ or returns @def@ when the key is not an
367-
-- element of the map.
368-
--
369-
-- > findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x'
370-
-- > findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a'
371-
372-
-- See IntMap.Internal.Note: Local 'go' functions and capturing]
373-
findWithDefault :: a -> Key -> IntMap a -> a
374-
findWithDefault def !k = go
375-
where
376-
go (Bin p l r) | nomatch k p = def
377-
| left k p = go l
378-
| otherwise = go r
379-
go (Tip kx x) | k == kx = x
380-
| otherwise = def
381-
go Nil = def
382-
383362
{--------------------------------------------------------------------
384363
Construction
385364
--------------------------------------------------------------------}

containers/src/Data/Map/Strict/Internal.hs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ import Data.Map.Internal
386386
, keysSet
387387
, link
388388
, lookup
389+
, findWithDefault
389390
, lookupGE
390391
, lookupGT
391392
, lookupIndex
@@ -473,32 +474,6 @@ import qualified Data.Foldable as Foldable
473474
-- narrow conditions and at a relatively high cost. It does not seem
474475
-- worth the price.
475476

476-
{--------------------------------------------------------------------
477-
Query
478-
--------------------------------------------------------------------}
479-
480-
-- | \(O(\log n)\). The expression @('findWithDefault' def k map)@ returns
481-
-- the value at key @k@ or returns default value @def@
482-
-- when the key is not in the map.
483-
--
484-
-- > findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x'
485-
-- > findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a'
486-
487-
-- See Map.Internal.Note: Local 'go' functions and capturing
488-
findWithDefault :: Ord k => a -> k -> Map k a -> a
489-
findWithDefault def k = k `seq` go
490-
where
491-
go Tip = def
492-
go (Bin _ kx x l r) = case compare k kx of
493-
LT -> go l
494-
GT -> go r
495-
EQ -> x
496-
#if __GLASGOW_HASKELL__
497-
{-# INLINABLE findWithDefault #-}
498-
#else
499-
{-# INLINE findWithDefault #-}
500-
#endif
501-
502477
{--------------------------------------------------------------------
503478
Construction
504479
--------------------------------------------------------------------}

0 commit comments

Comments
 (0)