Hashtable/dictionary/map lookup with regular expressions

前端 未结 19 1296
难免孤独
难免孤独 2021-02-01 05:36

I\'m trying to figure out if there\'s a reasonably efficient way to perform a lookup in a dictionary (or a hash, or a map, or whatever your favorite language calls it) where the

19条回答
  •  温柔的废话
    2021-02-01 06:24

    I created this exact data structure for a project once. I implemented it naively, as you suggested. I did make two immensely helpful optimizations, which may or may not be feasible for you, depending on the size of your data:

    • Memoizing the hash lookups
    • Pre-seeding the the memoization table (not sure what to call this... warming up the cache?)

    To avoid the problem of multiple keys matching the input, I gave each regex key a priority and the highest priority was used.

提交回复
热议问题