Longest Prefix Match

Algorithm has been written up here: algorithm.pdf