change longest_match to a more generic method: hattrie_walk