summaryrefslogtreecommitdiff
path: root/src/GF/Data
diff options
context:
space:
mode:
authorbringert <unknown>2005-10-26 17:47:16 +0000
committerbringert <unknown>2005-10-26 17:47:16 +0000
commitf3bd409b1bd44f86d994a77704be56e8fd603675 (patch)
tree6eda15d05660f7b4069d4670a2eb938fd16c6c6f /src/GF/Data
parenta01248d1c94c2abfe4ade142ab1d62c76724bce2 (diff)
Made removeIdenticalRules faster by using sortNubBy instead of nubBy.
Diffstat (limited to 'src/GF/Data')
-rw-r--r--src/GF/Data/Utilities.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/GF/Data/Utilities.hs b/src/GF/Data/Utilities.hs
index fbe6c6a27..d7e6be2f0 100644
--- a/src/GF/Data/Utilities.hs
+++ b/src/GF/Data/Utilities.hs
@@ -4,9 +4,9 @@
-- Stability : (stable)
-- Portability : (portable)
--
--- > CVS $Date: 2005/09/22 16:56:05 $
+-- > CVS $Date: 2005/10/26 18:47:16 $
-- > CVS $Author: bringert $
--- > CVS $Revision: 1.5 $
+-- > CVS $Revision: 1.6 $
--
-- Basic functions not in the standard libraries
-----------------------------------------------------------------------------
@@ -76,6 +76,10 @@ safeInit xs = init xs
sortNub :: Ord a => [a] -> [a]
sortNub = map head . group . sort
+-- | Like 'nubBy', but more efficient as it uses sorting internally.
+sortNubBy :: (a -> a -> Ordering) -> [a] -> [a]
+sortNubBy f = map head . groupBy (compareEq f) . sortBy f
+
-- | Take the union of a list of lists.
unionAll :: Eq a => [[a]] -> [a]
unionAll = nub . concat
@@ -89,6 +93,14 @@ lookup' x = fromJust . lookup x
find' :: (a -> Bool) -> [a] -> a
find' p = fromJust . find p
+-- * equality functions
+
+-- | Use an ordering function as an equality predicate.
+compareEq :: (a -> a -> Ordering) -> a -> a -> Bool
+compareEq f x y = case f x y of
+ EQ -> True
+ _ -> False
+
-- * ordering functions
compareBy :: Ord b => (a -> b) -> a -> a -> Ordering