Skip to content

Commit

Permalink
BWT: Haskell ver. Simplified sortBy (compare on fst) to sort.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxinyu95 committed Jun 23, 2011
1 parent 647cf17 commit e1656ba
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions transform/BWT/src/BWT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ bwt' :: (Ord a)=> [a] -> ([a], Int)
bwt' s = (l, i) where
l = map (\i->s !! ((i-1) `mod` n)) ids
(Just i) = elemIndex 0 ids
ids = map snd $ sortBy (compare `on` fst) $ zip rots [0..]
ids = map snd $ sort $ zip rots [0..]
rots = init $ zipWith (++) (tails s) (inits s) -- only non-empties
n = length s

-- O( n^2 ) if (!!) takes O(n) time
ibwt' :: (Ord a) => ([a], Int) -> [a]
ibwt' (r, i) = fst $ iterate f ([], i) !! n where
t = map snd $ sortBy (compare `on` fst) $ zip r [0..]
t = map snd $ sort $ zip r [0..]
f (s, j) = let j' = t !! j in (s++[r !! j'], j')
n = length r

Expand Down

0 comments on commit e1656ba

Please sign in to comment.