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