diff options
Diffstat (limited to 'lib/CommandLine.hs')
-rw-r--r-- | lib/CommandLine.hs | 65 |
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) | |||
37 | import qualified Numeric.Interval as I | 37 | import qualified Numeric.Interval as I |
38 | import Numeric.Interval.Bounded | 38 | import Numeric.Interval.Bounded |
39 | import SuperOrd | 39 | import SuperOrd |
40 | import 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. | ||
137 | mergeData :: (a -> a -> Ordering) -> [a] -> [a] -> [(Int,Ordering)] | ||
138 | mergeData 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 | ||
148 | mergeData comp [] [] = [] | ||
149 | mergeData comp [] ys = (length ys, GT) : [] | ||
150 | mergeData comp xs [] = (length xs, LT) : [] | ||
151 | |||
152 | mergeLists :: [(Int,Ordering)] -> (a -> a -> a) -> [a] -> [a] -> [a] | ||
153 | mergeLists ((n,LT):os) f xs ys = ls ++ mergeLists os f xs' ys | ||
154 | where | ||
155 | (ls,xs') = splitAt n xs | ||
156 | mergeLists ((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 | ||
161 | mergeLists ((n,GT):os) f xs ys = gs ++ mergeLists os f xs ys' | ||
162 | where | ||
163 | (gs,ys') = splitAt n ys | ||
164 | mergeLists [] f [] ys = ys | ||
165 | mergeLists [] f xs [] = xs | ||
166 | mergeLists [] f xs ys = error "xs ++ ys" | ||
167 | |||
168 | {- | 124 | {- |
169 | computeMask :: Int -> Ordering -> Ordering -> [(Int,Ordering)] -> Integer | 125 | computeMask :: Int -> Ordering -> Ordering -> [(Int,Ordering)] -> Integer |
170 | computeMask k w t [] = 0 | 126 | computeMask k w t [] = 0 |
@@ -207,21 +163,6 @@ mergeIntegers [] f !x !0 = x | |||
207 | mergeIntegers [] f !x !y = error "x .|. y" | 163 | mergeIntegers [] f !x !y = error "x .|. y" |
208 | -} | 164 | -} |
209 | 165 | ||
210 | splitLists :: [(Int,Ordering)] -> [a] -> ([a],[a]) | ||
211 | splitLists ((n,LT):os) xs = (ls ++ lls, rrs) | ||
212 | where | ||
213 | (ls,xs') = splitAt n xs | ||
214 | (lls,rrs) = splitLists os xs' | ||
215 | splitLists ((n,EQ):os) xs = (es ++ lls, es ++ rrs) | ||
216 | where | ||
217 | (es,xs') = splitAt n xs | ||
218 | (lls,rrs) = splitLists os xs' | ||
219 | splitLists ((n,GT):os) xs = (lls, rs ++ rrs) | ||
220 | where | ||
221 | (rs,xs') = splitAt n xs | ||
222 | (lls,rrs) = splitLists os xs' | ||
223 | splitLists [] xs = (xs,xs) | ||
224 | |||
225 | {- | 166 | {- |
226 | mergeBy :: Show a => (a -> a -> Ordering) -> [a] -> [a] | 167 | mergeBy :: 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) | |||
452 | removeIntersection xs [] = (xs,[]) | 393 | removeIntersection xs [] = (xs,[]) |
453 | 394 | ||
454 | 395 | ||
455 | -- ordinary sorted list merge. | ||
456 | mergeL :: Ord a => [a] -> [a] -> [a] | ||
457 | mergeL 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 |