diff options
Diffstat (limited to 'src/compiler/GF/Data')
| -rw-r--r-- | src/compiler/GF/Data/Graph.hs | 2 | ||||
| -rw-r--r-- | src/compiler/GF/Data/Operations.hs | 4 | ||||
| -rw-r--r-- | src/compiler/GF/Data/Relation.hs | 2 | ||||
| -rw-r--r-- | src/compiler/GF/Data/TrieMap.hs | 99 | ||||
| -rw-r--r-- | src/compiler/GF/Data/Utilities.hs | 19 |
5 files changed, 6 insertions, 120 deletions
diff --git a/src/compiler/GF/Data/Graph.hs b/src/compiler/GF/Data/Graph.hs index bfb289860..797325bbb 100644 --- a/src/compiler/GF/Data/Graph.hs +++ b/src/compiler/GF/Data/Graph.hs @@ -24,7 +24,7 @@ module GF.Data.Graph ( Graph(..), Node, Edge, NodeInfo , reverseGraph, mergeGraphs, renameNodes ) where -import GF.Data.Utilities +--import GF.Data.Utilities import Data.List import Data.Maybe diff --git a/src/compiler/GF/Data/Operations.hs b/src/compiler/GF/Data/Operations.hs index b70df6a90..06e54775e 100644 --- a/src/compiler/GF/Data/Operations.hs +++ b/src/compiler/GF/Data/Operations.hs @@ -60,10 +60,10 @@ module GF.Data.Operations (-- * misc functions ) where import Data.Char (isSpace, toUpper, isSpace, isDigit) -import Data.List (nub, sortBy, sort, deleteBy, nubBy, partition, (\\)) +import Data.List (nub, partition, (\\)) import qualified Data.Map as Map import Data.Map (Map) -import Control.Monad (liftM,liftM2, MonadPlus, mzero, mplus) +import Control.Monad (liftM,liftM2) import GF.Data.ErrM import GF.Data.Relation diff --git a/src/compiler/GF/Data/Relation.hs b/src/compiler/GF/Data/Relation.hs index b888a0fd7..195faf96f 100644 --- a/src/compiler/GF/Data/Relation.hs +++ b/src/compiler/GF/Data/Relation.hs @@ -26,7 +26,7 @@ module GF.Data.Relation (Rel, mkRel, mkRel' , topologicalSort, findCycles) where import Data.Foldable (toList) -import Data.List +--import Data.List import Data.Maybe import Data.Map (Map) import qualified Data.Map as Map diff --git a/src/compiler/GF/Data/TrieMap.hs b/src/compiler/GF/Data/TrieMap.hs deleted file mode 100644 index 996d91ec7..000000000 --- a/src/compiler/GF/Data/TrieMap.hs +++ /dev/null @@ -1,99 +0,0 @@ -module GF.Data.TrieMap
- ( TrieMap
-
- , empty
- , singleton
-
- , lookup
-
- , null
- , compose
- , decompose
-
- , insertWith
-
- , union, unionWith
- , unions, unionsWith
-
- , elems
- , toList
- , fromList, fromListWith
-
- , map
- , mapWithKey
- ) where
-
-import Prelude hiding (lookup, null, map)
-import qualified Data.Map as Map
-import Data.List (foldl')
-
-data TrieMap k v = Tr (Maybe v) (Map.Map k (TrieMap k v))
-
-empty = Tr Nothing Map.empty
-
-singleton :: [k] -> a -> TrieMap k a
-singleton [] v = Tr (Just v) Map.empty
-singleton (k:ks) v = Tr Nothing (Map.singleton k (singleton ks v))
-
-lookup :: Ord k => [k] -> TrieMap k a -> Maybe a
-lookup [] (Tr mb_v m) = mb_v
-lookup (k:ks) (Tr mb_v m) = Map.lookup k m >>= lookup ks
-
-null :: TrieMap k v -> Bool
-null (Tr Nothing m) = Map.null m
-null _ = False
-
-compose :: Maybe v -> Map.Map k (TrieMap k v) -> TrieMap k v
-compose mb_v m = Tr mb_v m
-
-decompose :: TrieMap k v -> (Maybe v, Map.Map k (TrieMap k v))
-decompose (Tr mb_v m) = (mb_v,m)
-
-insertWith :: Ord k => (v -> v -> v) -> [k] -> v -> TrieMap k v -> TrieMap k v
-insertWith f [] v0 (Tr mb_v m) = case mb_v of
- Just v -> Tr (Just (f v0 v)) m
- Nothing -> Tr (Just v0 ) m
-insertWith f (k:ks) v0 (Tr mb_v m) = case Map.lookup k m of
- Nothing -> Tr mb_v (Map.insert k (singleton ks v0) m)
- Just tr -> Tr mb_v (Map.insert k (insertWith f ks v0 tr) m)
-
-union :: Ord k => TrieMap k v -> TrieMap k v -> TrieMap k v
-union = unionWith (\a b -> a)
-
-unionWith :: Ord k => (v -> v -> v) -> TrieMap k v -> TrieMap k v -> TrieMap k v
-unionWith f (Tr mb_v1 m1) (Tr mb_v2 m2) =
- let mb_v = case (mb_v1,mb_v2) of
- (Nothing,Nothing) -> Nothing
- (Just v ,Nothing) -> Just v
- (Nothing,Just v ) -> Just v
- (Just v1,Just v2) -> Just (f v1 v2)
- m = Map.unionWith (unionWith f) m1 m2
- in Tr mb_v m
-
-unions :: Ord k => [TrieMap k v] -> TrieMap k v
-unions = foldl union empty
-
-unionsWith :: Ord k => (v -> v -> v) -> [TrieMap k v] -> TrieMap k v
-unionsWith f = foldl (unionWith f) empty
-
-elems :: TrieMap k v -> [v]
-elems tr = collect tr []
- where
- collect (Tr mb_v m) xs = maybe id (:) mb_v (Map.fold collect xs m)
-
-toList :: TrieMap k v -> [([k],v)]
-toList tr = collect [] tr []
- where
- collect ks (Tr mb_v m) xs = maybe id (\v -> (:) (ks,v)) mb_v (Map.foldWithKey (\k -> collect (k:ks)) xs m)
-
-fromListWith :: Ord k => (v -> v -> v) -> [([k],v)] -> TrieMap k v
-fromListWith f xs = foldl' (\trie (ks,v) -> insertWith f ks v trie) empty xs
-
-fromList :: Ord k => [([k],v)] -> TrieMap k v
-fromList xs = fromListWith const xs
-
-map :: (a -> b) -> TrieMap k a -> TrieMap k b
-map f (Tr mb_v m) = Tr (fmap f mb_v) (Map.map (map f) m)
-
-mapWithKey :: ([k] -> a -> b) -> TrieMap k a -> TrieMap k b
-mapWithKey f (Tr mb_v m) = Tr (fmap (f []) mb_v) (Map.mapWithKey (\k -> mapWithKey (f . (k:))) m)
diff --git a/src/compiler/GF/Data/Utilities.hs b/src/compiler/GF/Data/Utilities.hs index f953938c8..792f7aa4a 100644 --- a/src/compiler/GF/Data/Utilities.hs +++ b/src/compiler/GF/Data/Utilities.hs @@ -12,12 +12,12 @@ ----------------------------------------------------------------------------- -module GF.Data.Utilities where +module GF.Data.Utilities(module GF.Data.Utilities, module PGF.Utilities) where import Data.Maybe import Data.List import Control.Monad (MonadPlus(..),liftM) -import qualified Data.Set as Set +import PGF.Utilities -- * functions on lists @@ -68,17 +68,6 @@ safeInit :: [a] -> [a] safeInit [] = [] safeInit xs = init xs --- | Like 'nub', but O(n log n) instead of O(n^2), since it uses a set to lookup previous things. --- The result list is stable (the elements are returned in the order they occur), and lazy. --- Requires that the list elements can be compared by Ord. --- Code ruthlessly taken from http://hpaste.org/54411 -nub' :: Ord a => [a] -> [a] -nub' = loop Set.empty - where loop _ [] = [] - loop seen (x : xs) - | Set.member x seen = loop seen xs - | otherwise = x : loop (Set.insert x seen) xs - -- | Sorts and then groups elements given an ordering of the -- elements. sortGroupBy :: (a -> a -> Ordering) -> [a] -> [[a]] @@ -108,10 +97,6 @@ buildMultiMap :: Ord a => [(a,b)] -> [(a,[b])] buildMultiMap = map (\g -> (fst (head g), map snd g) ) . sortGroupBy (compareBy fst) --- | Replace all occurences of an element by another element. -replace :: Eq a => a -> a -> [a] -> [a] -replace x y = map (\z -> if z == x then y else z) - -- * equality functions -- | Use an ordering function as an equality predicate. |
