summaryrefslogtreecommitdiff
path: root/lib/CommandLine.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CommandLine.hs')
-rw-r--r--lib/CommandLine.hs65
1 files changed, 1 insertions, 64 deletions
diff --git a/lib/CommandLine.hs b/lib/CommandLine.hs
index 4897b21..6bd42ea 100644
--- a/lib/CommandLine.hs
+++ b/lib/CommandLine.hs
@@ -37,6 +37,7 @@ import Numeric.Interval (Interval(..), singleton, (...), inf, sup, hull)
37import qualified Numeric.Interval as I 37import qualified Numeric.Interval as I
38import Numeric.Interval.Bounded 38import Numeric.Interval.Bounded
39import SuperOrd 39import SuperOrd
40import Data.List.Merge
40 41
41-- trace :: String -> a -> a 42-- trace :: String -> a -> a
42-- trace _ x = x 43-- trace _ x = x
@@ -120,51 +121,6 @@ packBits bs = sum $ zipWith (\b n -> if b then n else 0) bs $ iterate (*2) 1
120 -} 121 -}
121 122
122 123
123-- | mergeData
124--
125-- > mergeData compare [1,3,5] [2,2,4,6] ==> [(1,LT),(2,GT),(1,LT),(1,GT),(1,LT),(1,GT)]
126--
127-- Given a comparison function and two sorted lists, 'mergeData' will return
128-- a RLE compressed (run-length encoded) list of the comparison results
129-- encountered while merging the lists.
130--
131-- This data is enough information to perform the merge without doing the
132-- comparisons or to reverse a merged list back to two sorted lists.
133--
134-- When one list is exausted, the length of the remaining list is returned as
135-- a run-length for LT or GT depending on whether the left list or the right
136-- list has elements.
137mergeData :: (a -> a -> Ordering) -> [a] -> [a] -> [(Int,Ordering)]
138mergeData comp (x:xs) (y:ys)
139 | comp x y == LT = case mergeData comp xs (y:ys) of
140 (n,LT):ys -> let n'=n+1 in n' `seq` (n',LT):ys
141 ys -> (1,LT):ys
142 | comp x y == EQ = case mergeData comp xs ys of
143 (n,EQ):ys -> let n'=n+1 in n' `seq` (n',EQ):ys
144 ys -> (1,EQ):ys
145 | comp x y == GT = case mergeData comp (x:xs) ys of
146 (n,GT):ys -> let n'=n+1 in n' `seq` (n',GT):ys
147 ys -> (1,GT):ys
148mergeData comp [] [] = []
149mergeData comp [] ys = (length ys, GT) : []
150mergeData comp xs [] = (length xs, LT) : []
151
152mergeLists :: [(Int,Ordering)] -> (a -> a -> a) -> [a] -> [a] -> [a]
153mergeLists ((n,LT):os) f xs ys = ls ++ mergeLists os f xs' ys
154 where
155 (ls,xs') = splitAt n xs
156mergeLists ((n,EQ):os) f xs ys = es ++ mergeLists os f xs' ys'
157 where
158 (les,xs') = splitAt n xs
159 (res,ys') = splitAt n ys
160 es = zipWith f les res
161mergeLists ((n,GT):os) f xs ys = gs ++ mergeLists os f xs ys'
162 where
163 (gs,ys') = splitAt n ys
164mergeLists [] f [] ys = ys
165mergeLists [] f xs [] = xs
166mergeLists [] f xs ys = error "xs ++ ys"
167
168{- 124{-
169computeMask :: Int -> Ordering -> Ordering -> [(Int,Ordering)] -> Integer 125computeMask :: Int -> Ordering -> Ordering -> [(Int,Ordering)] -> Integer
170computeMask k w t [] = 0 126computeMask k w t [] = 0
@@ -207,21 +163,6 @@ mergeIntegers [] f !x !0 = x
207mergeIntegers [] f !x !y = error "x .|. y" 163mergeIntegers [] f !x !y = error "x .|. y"
208-} 164-}
209 165
210splitLists :: [(Int,Ordering)] -> [a] -> ([a],[a])
211splitLists ((n,LT):os) xs = (ls ++ lls, rrs)
212 where
213 (ls,xs') = splitAt n xs
214 (lls,rrs) = splitLists os xs'
215splitLists ((n,EQ):os) xs = (es ++ lls, es ++ rrs)
216 where
217 (es,xs') = splitAt n xs
218 (lls,rrs) = splitLists os xs'
219splitLists ((n,GT):os) xs = (lls, rs ++ rrs)
220 where
221 (rs,xs') = splitAt n xs
222 (lls,rrs) = splitLists os xs'
223splitLists [] xs = (xs,xs)
224
225{- 166{-
226mergeBy :: Show a => (a -> a -> Ordering) -> [a] -> [a] 167mergeBy :: Show a => (a -> a -> Ordering) -> [a] -> [a]
227 -> ( (Integer -> Integer -> Integer) -> Integer -> Integer -> Integer 168 -> ( (Integer -> Integer -> Integer) -> Integer -> Integer -> Integer
@@ -452,10 +393,6 @@ removeIntersection [] ys = ([],ys)
452removeIntersection xs [] = (xs,[]) 393removeIntersection xs [] = (xs,[])
453 394
454 395
455-- ordinary sorted list merge.
456mergeL :: Ord a => [a] -> [a] -> [a]
457mergeL as bs = mergeLists (mergeData compare as bs) const as bs
458
459-- | runArgs 396-- | runArgs
460-- 397--
461-- (os,us) - named arguments(options, name-value pairs), and unnamed arguments 398-- (os,us) - named arguments(options, name-value pairs), and unnamed arguments