longest prefix match algorithm