Search code examples
javacollectionstreemap

Java prefix TreeMap


I have a lot of regexp rules more than(10k) and I would like to know which rules match for a particular string. I need collection where I can store this regex rules efficiently in order to detect which rules can be apply for a string.

I don't want to iterate all rules and decide which is good and which isn't. Are there any good algorithms for this problem?


Solution

  • Finally, I could resolve this problem, I created a regex rule container treeMap. I split regexpes into smaler parts where a regexpt part is appliable just for a single char, and that small regexp part would be a tree map node.

    By using this treemap every match request costs just log(n).