Created
December 17, 2008 05:30
-
-
Save smly/36950 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (tails,sort) | |
-- build suffix array | |
build :: Ord a => [a] -> [[a]] | |
build = sort.tails | |
-- binary search | |
bs [] str = False | |
bs [x] str = cmp str x | |
bs xs str | |
| cmp str x = True | |
| str < x = bs l str | |
| otherwise = bs r str | |
where (l,x:r) = splitAt (length xs `div` 2) xs | |
-- partial compare | |
cmp str x = (length x >= length str) && (subcmp str x) | |
subcmp [] _ = True | |
subcmp (s:ss) (n:ns) | |
| s == n = subcmp ss ns | |
| otherwise = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment