Browse files

Rename 'IsEmm' 'IsKey' and 'CanSplit' 'SubKey' as these are more accu…

…rate names.
  • Loading branch information...
1 parent 4a837ac commit a4f6deef19e17d6f2fb10e6a661e397a7422261c @bovinespirit committed Oct 22, 2012
Showing with 41 additions and 41 deletions.
  1. +16 −16 Data/EnumMapMap/Base.hs
  2. +3 −3 Data/EnumMapMap/Lazy.hs
  3. +3 −3 Data/EnumMapMap/Strict.hs
  4. +19 −19 Data/EnumMapSet/Base.hs
View
32 Data/EnumMapMap/Base.hs
@@ -26,11 +26,11 @@ module Data.EnumMapMap.Base(
-- * Split/Join Keys
IsSplit(..),
Plus,
- CanSplit(..),
+ SubKey(..),
-- * Internal
-- ** IsEMM
EMM(..),
- IsEmm(..),
+ IsKey(..),
EnumMapMap(..),
-- ** SKey
HasSKey(..),
@@ -151,7 +151,7 @@ instance (IsSplit t n, Enum k) => IsSplit (k :& t) (N n) where
type family Plus k1 k2 :: *
type instance Plus (k1 :& t) k2 = k1 :& Plus t k2
-class CanSplit k1 k2 v where
+class SubKey k1 k2 v where
type Result k1 k2 v :: *
-- | Lookup up the value at a key in the 'EnumMapMap'.
--
@@ -165,11 +165,11 @@ class CanSplit k1 k2 v where
-- > emm2 = fromList [(3 :& 2 :& K 1, "a"), (3 :& 2 :& K 4, "a")]
-- > lookup (3 :& K 2) emm2 == Just $ fromList [(K 1, "a"), (K 4, "a")]
--
- lookup :: (IsEmm k1, IsEmm k2) =>
+ lookup :: (IsKey k1, IsKey k2) =>
k1 -> EnumMapMap k2 v -> Maybe (Result k1 k2 v)
-instance (Enum k, IsEmm t1, IsEmm t2, CanSplit t1 t2 v) =>
- CanSplit (k :& t1) (k :& t2) v where
+instance (Enum k, IsKey t1, IsKey t2, SubKey t1 t2 v) =>
+ SubKey (k :& t1) (k :& t2) v where
type Result (k :& t1) (k :& t2) v = Result t1 t2 v
lookup (key' :& nxt) (KCC emm) = key `seq` go emm
where
@@ -202,7 +202,7 @@ instance (HasSKey t) => HasSKey (k :& t) where
toS (k :& t) = (:&) k $! toS t
toK (k :& t) = (:&) k $! toK t
-class (Eq k) => IsEmm k where
+class (Eq k) => IsKey k where
-- | A map of keys to values. The keys are 'Enum' types but are stored as 'Int's
-- so any keys with the same 'Int' value are treated as the same. The aim is to
-- provide typesafe indexing.
@@ -228,7 +228,7 @@ class (Eq k) => IsEmm k where
-- > emm = empty :: EnumMapMap (Int :& Int :& K ID) Bool)
-- > emm == joinKey $ splitKey d2 emm
--
- joinKey :: (IsEmm (Plus k k2)) =>
+ joinKey :: (IsKey (Plus k k2)) =>
EnumMapMap k (EnumMapMap k2 v)
-> EnumMapMap (Plus k k2) v
joinKey = removeEmpties . unsafeJoinKey
@@ -348,7 +348,7 @@ class (Eq k) => IsEmm k where
equal :: Eq v => EnumMapMap k v -> EnumMapMap k v -> Bool
nequal :: Eq v => EnumMapMap k v -> EnumMapMap k v -> Bool
-instance (Eq k, Enum k, IsEmm t, HasSKey t) => IsEmm (k :& t) where
+instance (Eq k, Enum k, IsKey t, HasSKey t) => IsKey (k :& t) where
data EnumMapMap (k :& t) v = KCC (EMM k (EnumMapMap t v))
emptySubTrees e@(KCC emm) =
@@ -484,7 +484,7 @@ insertWith_ f !key' val emm = key `seq` go emm
-- | 'alter_' is used to walk down the tree to find the 'EnumMapMap' to actually
-- change. If the new 'EnumMapMap' is null then it's removed from the containing
-- 'EMM'.
-alter_ :: (IsEmm b) =>
+alter_ :: (IsKey b) =>
(EnumMapMap b v -> EnumMapMap b v)
-> Key
-> EMM a (EnumMapMap b v)
@@ -579,7 +579,7 @@ mergeWithKey' bin' f g1 g2 = go
-- Eq
-instance (Eq v, IsEmm k) => Eq (EnumMapMap k v) where
+instance (Eq v, IsKey k) => Eq (EnumMapMap k v) where
t1 == t2 = equal t1 t2
t1 /= t2 = nequal t1 t2
@@ -603,11 +603,11 @@ nequalE (Tip kx x) (Tip ky y)
nequalE Nil Nil = False
nequalE _ _ = True
-instance (IsEmm k) => Functor (EnumMapMap k)
+instance (IsKey k) => Functor (EnumMapMap k)
where
fmap = map
-instance (IsEmm k) => Monoid (EnumMapMap k v) where
+instance (IsKey k) => Monoid (EnumMapMap k v) where
mempty = empty
mappend = union
mconcat = unions
@@ -651,7 +651,7 @@ join p1 t1 p2 t2
p = mask p1 m
{-# INLINE join #-}
-joinD :: (IsEmm b) =>
+joinD :: (IsKey b) =>
Prefix -> EMM a (EnumMapMap b v)
-> Prefix -> EMM a (EnumMapMap b v)
-> EMM a (EnumMapMap b v)
@@ -675,7 +675,7 @@ bin p m l r = Bin p m l r
{--------------------------------------------------------------------
@binD@ assures that we never have empty trees in the next level
--------------------------------------------------------------------}
-binD :: (IsEmm b) =>
+binD :: (IsKey b) =>
Prefix -> Mask
-> EMM a (EnumMapMap b v)
-> EMM a (EnumMapMap b v)
@@ -691,7 +691,7 @@ binD p m l@(Tip _ y) r
binD p m l r = Bin p m l r
{-# INLINE binD #-}
-tip :: (IsEmm b) => Key -> EnumMapMap b v -> EMM a (EnumMapMap b v)
+tip :: (IsKey b) => Key -> EnumMapMap b v -> EMM a (EnumMapMap b v)
tip k val
| null val = Nil
| otherwise = Tip k val
View
6 Data/EnumMapMap/Lazy.hs
@@ -103,7 +103,7 @@ import qualified Data.EnumMapSet.Base as EMS
newtype K k = K k
deriving (Show, Eq)
-instance (Enum k, Eq k) => IsEmm (K k) where
+instance (Enum k, Eq k) => IsKey (K k) where
data EnumMapMap (K k) v = KEC (EMM k v)
emptySubTrees e@(KEC emm) =
@@ -284,7 +284,7 @@ instance IsSplit (k :& t) Z where
type Tail (k :& t) Z = t
splitKey Z (KCC emm) = KEC $ emm
-instance (Enum k1, k1 ~ k2) => CanSplit (K k1) (k2 :& t2) v where
+instance (Enum k1, k1 ~ k2) => SubKey (K k1) (k2 :& t2) v where
type Result (K k1) (k2 :& t2) v = EnumMapMap t2 v
lookup (K key') (KCC emm) = key `seq` go emm
where
@@ -298,7 +298,7 @@ instance (Enum k1, k1 ~ k2) => CanSplit (K k1) (k2 :& t2) v where
go Nil = Nothing
key = fromEnum key'
-instance (Enum k) => CanSplit (K k) (K k) v where
+instance (Enum k) => SubKey (K k) (K k) v where
type Result (K k) (K k) v = v
lookup (K key') (KEC emm) = key `seq` go emm
where
View
6 Data/EnumMapMap/Strict.hs
@@ -104,7 +104,7 @@ import qualified Data.EnumMapSet.Base as EMS
newtype K k = K k
deriving (Show, Eq)
-instance (Enum k, Eq k) => IsEmm (K k) where
+instance (Enum k, Eq k) => IsKey (K k) where
data EnumMapMap (K k) v = KEC (EMM k v)
emptySubTrees e@(KEC emm) =
@@ -285,7 +285,7 @@ instance IsSplit (k :& t) Z where
type Tail (k :& t) Z = t
splitKey Z (KCC emm) = KEC $ emm
-instance (Enum k1, k1 ~ k2) => CanSplit (K k1) (k2 :& t2) v where
+instance (Enum k1, k1 ~ k2) => SubKey (K k1) (k2 :& t2) v where
type Result (K k1) (k2 :& t2) v = EnumMapMap t2 v
lookup (K key') (KCC emm) = key `seq` go emm
where
@@ -299,7 +299,7 @@ instance (Enum k1, k1 ~ k2) => CanSplit (K k1) (k2 :& t2) v where
go Nil = Nothing
key = fromEnum key'
-instance (Enum k) => CanSplit (K k) (K k) v where
+instance (Enum k) => SubKey (K k) (K k) v where
type Result (K k) (K k) v = v
lookup (K key') (KEC emm) = key `seq` go emm
where
View
38 Data/EnumMapSet/Base.hs
@@ -65,7 +65,7 @@ import GHC.Prim (indexInt8OffAddr#)
#include "MachDeps.h"
import Data.EnumMapMap.Base ((:&)(..),
- IsEmm,
+ IsKey,
EnumMapMap,
Prefix, Nat, Mask,
branchMask, mask,
@@ -96,7 +96,7 @@ data EMS k = Bin {-# UNPACK #-} !Prefix {-# UNPACK #-} !Mask
| Nil
deriving (Show)
-instance (Enum k, Eq k) => IsEmm (S k) where
+instance (Enum k, Eq k) => IsKey (S k) where
data EnumMapMap (S k) v = KSC (EMS k)
emptySubTrees e@(KSC emm) =
@@ -293,13 +293,13 @@ instance (Enum k, Eq k) => IsEmm (S k) where
GHC will inline away all the empty parameters.
---------------------------------------------------------------------}
-null :: (IsEmm k) => EnumMapSet k -> Bool
+null :: (IsKey k) => EnumMapSet k -> Bool
null = EMM.null
-size :: (IsEmm k) => EnumMapSet k -> Int
+size :: (IsKey k) => EnumMapSet k -> Int
size = EMM.size
-member ::(IsEmm k) => k -> EnumMapSet k -> Bool
+member ::(IsKey k) => k -> EnumMapSet k -> Bool
member = EMM.member
-- | Lookup a subtree in an 'EnumMapSet'.
@@ -308,24 +308,24 @@ member = EMM.member
-- > lookup (1 :& K 2) ems == fromList [K 3, K 4]
-- > lookup (1 :& 2 :& K 3) -- ERROR: Use 'member' to check for a key.
--
-lookup :: (EMM.CanSplit k1 k2 (), IsEmm k1, IsEmm k2) =>
+lookup :: (EMM.SubKey k1 k2 (), IsKey k1, IsKey k2) =>
k1 -> EnumMapSet k2 -> Maybe (EMM.Result k1 k2 ())
lookup = EMM.lookup
-empty :: (IsEmm k) => EnumMapSet k
+empty :: (IsKey k) => EnumMapSet k
empty = EMM.empty
-singleton :: (IsEmm k) => k -> EnumMapSet k
+singleton :: (IsKey k) => k -> EnumMapSet k
singleton !key = EMM.singleton key ()
-insert :: (IsEmm k) => k -> EnumMapSet k -> EnumMapSet k
+insert :: (IsKey k) => k -> EnumMapSet k -> EnumMapSet k
insert !key = EMM.insert key ()
-delete :: (IsEmm k) => k -> EnumMapSet k -> EnumMapSet k
+delete :: (IsKey k) => k -> EnumMapSet k -> EnumMapSet k
delete = EMM.delete
-- This function has not been optimised in any way.
-foldr :: (IsEmm k) => (k -> t -> t) -> t -> EnumMapSet k -> t
+foldr :: (IsKey k) => (k -> t -> t) -> t -> EnumMapSet k -> t
foldr f = EMM.foldrWithKey go
where
go k _ z = f k z
@@ -334,31 +334,31 @@ foldr f = EMM.foldrWithKey go
--
-- It's worth noting that the size of the result may be smaller if,
-- for some @(x,y)@, @x \/= y && f x == f y@
-map :: (IsEmm k1, IsEmm k2) =>
+map :: (IsKey k1, IsKey k2) =>
(k1 -> k2) -> EnumMapSet k1 -> EnumMapSet k2
map f = fromList . List.map f . toList
-union :: (IsEmm k) => EnumMapSet k -> EnumMapSet k -> EnumMapSet k
+union :: (IsKey k) => EnumMapSet k -> EnumMapSet k -> EnumMapSet k
union = EMM.union
-difference :: (IsEmm k) => EnumMapSet k -> EnumMapSet k -> EnumMapSet k
+difference :: (IsKey k) => EnumMapSet k -> EnumMapSet k -> EnumMapSet k
difference = EMM.difference
-intersection :: (IsEmm k) => EnumMapSet k -> EnumMapSet k -> EnumMapSet k
+intersection :: (IsKey k) => EnumMapSet k -> EnumMapSet k -> EnumMapSet k
intersection = EMM.intersection
{---------------------------------------------------------------------
Lists
---------------------------------------------------------------------}
-fromList :: IsEmm k => [k] -> EnumMapSet k
+fromList :: IsKey k => [k] -> EnumMapSet k
fromList xs
= foldlStrict (\t x -> insert x t) empty xs
-toList :: IsEmm k => EnumMapSet k -> [k]
+toList :: IsKey k => EnumMapSet k -> [k]
toList = foldr (:) []
-keys :: IsEmm k => EnumMapSet k -> [k]
+keys :: IsKey k => EnumMapSet k -> [k]
keys = toList
{---------------------------------------------------------------------
@@ -370,7 +370,7 @@ instance EMM.HasSKey (S k) where
toS (S _) = undefined
toK (S _) = undefined
-instance (Enum k1, k1 ~ k2) => EMM.CanSplit (S k1) (k2 :& t2) () where
+instance (Enum k1, k1 ~ k2) => EMM.SubKey (S k1) (k2 :& t2) () where
type Result (S k1) (k2 :& t2) () = EnumMapSet t2
lookup (S key') (EMM.KCC emm) = key `seq` go emm
where

0 comments on commit a4f6dee

Please sign in to comment.