Ticket #5242: 0003-Added-IntMap.differenceKeysSet-for-removing-an-IntSe.patch

File 0003-Added-IntMap.differenceKeysSet-for-removing-an-IntSe.patch, 2.2 KB (added by liyang, 3 years ago)

forgot to export differenceKeysSet

  • Data/IntMap.hs

    From e6497426df0a84ab458e7c2a1d1f839b4e02d8f3 Mon Sep 17 00:00:00 2001
    From: Liyang HU <git@liyang.hu>
    Date: Tue, 7 Jun 2011 15:47:39 +0900
    Subject: [PATCH 3/5] Added IntMap.differenceKeysSet for removing an IntSet of keys
    
    ---
     Data/IntMap.hs |   29 +++++++++++++++++++++++++++++
     1 files changed, 29 insertions(+), 0 deletions(-)
    
    diff --git a/Data/IntMap.hs b/Data/IntMap.hs
    index fe0b353..dc32a7a 100644
    a b module Data.IntMap ( 
    9797            , difference 
    9898            , differenceWith 
    9999            , differenceWithKey 
     100            , differenceKeysSet 
    100101 
    101102            -- ** Intersection 
    102103            , intersection 
    module Data.IntMap ( 
    176177import Prelude hiding (lookup,map,filter,foldr,foldl,null) 
    177178import Data.Bits  
    178179import qualified Data.IntSet as IntSet 
     180import qualified Data.IntSet.Internal as IntSet 
    179181import Data.Monoid (Monoid(..)) 
    180182import Data.Maybe (fromMaybe) 
    181183import Data.Typeable 
    difference Nil _ = Nil 
    744746difference t (Tip k _) = delete k t 
    745747difference t Nil       = t 
    746748 
     749-- | /O(n+m)/. Difference between a map and a set of keys. 
     750-- 
     751-- > differenceKeysSet a (keysSet b) == difference a b 
     752 
     753differenceKeysSet :: IntMap a -> IntSet.IntSet -> IntMap a 
     754differenceKeysSet t1@(Bin p1 m1 l1 r1) t2@(IntSet.Bin p2 m2 l2 r2) 
     755  | shorter m1 m2  = difference1 
     756  | shorter m2 m1  = difference2 
     757  | p1 == p2       = bin p1 m1 (differenceKeysSet l1 l2) (differenceKeysSet r1 r2) 
     758  | otherwise      = t1 
     759  where 
     760    difference1 | nomatch p2 p1 m1  = t1 
     761                | zero p2 m1        = bin p1 m1 (differenceKeysSet l1 t2) r1 
     762                | otherwise         = bin p1 m1 l1 (differenceKeysSet r1 t2) 
     763 
     764    difference2 | nomatch p1 p2 m2  = t1 
     765                | zero p1 m2        = differenceKeysSet t1 l2 
     766                | otherwise         = differenceKeysSet t1 r2 
     767 
     768differenceKeysSet t1@(Tip k _) t2 
     769  | IntSet.member k t2  = Nil 
     770  | otherwise           = t1 
     771 
     772differenceKeysSet Nil _             = Nil 
     773differenceKeysSet t (IntSet.Tip k)  = delete k t 
     774differenceKeysSet t IntSet.Nil      = t 
     775 
    747776-- | /O(n+m)/. Difference with a combining function. 
    748777-- 
    749778-- > let f al ar = if al == "b" then Just (al ++ ":" ++ ar) else Nothing