Ticket #5242: 0005-Added-IntMap.fromSet-to-convert-from-an-IntSet-of-ke.patch

File 0005-Added-IntMap.fromSet-to-convert-from-an-IntSet-of-ke.patch, 1.7 KB (added by liyang, 4 years ago)
  • Data/IntMap.hs

    From be31a6b9c8e86ff6b84d189317209c4d69062e6a Mon Sep 17 00:00:00 2001
    From: Liyang HU <[email protected]>
    Date: Fri, 10 Jun 2011 11:04:53 +0900
    Subject: [PATCH 5/5] Added IntMap.fromSet to convert from an IntSet of keys
    
    * removed export of differenceKeysSet
    * replaced with RULES "IntMap.difference/fromSet"
    ---
     Data/IntMap.hs |   11 ++++++++++-
     1 files changed, 10 insertions(+), 1 deletions(-)
    
    diff --git a/Data/IntMap.hs b/Data/IntMap.hs
    index dc32a7a..845c5c5 100644
    a b module Data.IntMap ( 
    9797            , difference
    9898            , differenceWith
    9999            , differenceWithKey
    100             , differenceKeysSet
    101100
    102101            -- ** Intersection
    103102            , intersection
    module Data.IntMap ( 
    120119            , elems
    121120            , keys
    122121            , keysSet
     122            , fromSet
    123123            , assocs
    124124
    125125            -- ** Lists
    differenceKeysSet Nil _ = Nil 
    773773differenceKeysSet t (IntSet.Tip k)  = delete k t
    774774differenceKeysSet t IntSet.Nil      = t
    775775
     776{-# RULES
     777"IntMap.difference/fromSet" forall m f s.
     778    difference m (fromSet f s) = differenceKeysSet m s
     779  #-}
     780
    776781-- | /O(n+m)/. Difference with a combining function.
    777782--
    778783-- > let f al ar = if al == "b" then Just (al ++ ":" ++ ar) else Nothing
    keys 
    14651470keysSet :: IntMap a -> IntSet.IntSet
    14661471keysSet m = IntSet.fromDistinctAscList (keys m)
    14671472
     1473-- | /O(n)/. Build an IntMap from an IntSet, using the supplied function to
     1474-- generate the values.
     1475fromSet :: (Key -> a) -> IntSet.IntSet -> IntMap a
     1476fromSet f = fromAscList . fmap (\ k -> (k, f k)) . IntSet.toAscList
    14681477
    14691478-- | /O(n)/. Return all key\/value pairs in the map in ascending key order.
    14701479--