0

I want to search a collection of strings to find the most specific match from left to right. Each string can have some associated data that must be returned when a match occurs. Matches must be returned in the order of specificness. That is I should be able to iterate through matches in most specific to least specific order (other way is also ok).

For example for the set of string, data tuples:

"abc", data_1
"xyz", data_2
"abcpqr", data_3
"abcpqrstu", data_4
"xyzpqr", data_2

If I search for abcpqr, I should get following in most specific to least specific order:

"abcpqr", data_3
"abc", data_1

For abcpqrstu:

"abcpqrstu" : data_4
"abcpqr", data_3
"abc", data_1

For abcpq:

"abc", data_1

Can I use a suffix tree or any other data structure to do this?

peter
  • 95
  • 8

0 Answers0