Skip to content

Instantly share code, notes, and snippets.

@dminuoso

dminuoso/f.hs Secret

Created December 21, 2021 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dminuoso/37edae34ce73428fbb691bcd34e9868a to your computer and use it in GitHub Desktop.
Save dminuoso/37edae34ce73428fbb691bcd34e9868a to your computer and use it in GitHub Desktop.
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