-
-
Save dminuoso/dc8cccaff1e72592b4f285153fbe4605 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
longestSuffix :: Domain -> DomTrie -> Maybe Domain | |
longestSuffix (Domain labels) table = | |
(Domain . reverse) <$> go (reverse labels) table Nothing | |
where | |
go [] _ r = r | |
go (x:xs) (DomTrie b table) (Just ts) | |
= case M.lookup x table of | |
Just sub | b -> go xs sub (Just (x:ts)) | |
| otherwise -> go xs sub (Just ts) | |
Nothing -> Just ts | |
go (x:xs) (DomTrie b table) Nothing | |
= case M.lookup x table of | |
Just sub | b -> go xs sub (Just [x]) | |
| otherwise -> go xs sub Nothing | |
Nothing -> Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment