search List for string .StartsWith()

后端 未结 10 1756
终归单人心
终归单人心 2021-01-19 00:13

I have a

List

with 1500 strings. I am now using the following code to pull out only string that start with the string prefix

10条回答
  •  春和景丽
    2021-01-19 00:18

    1500 is usually too few:

    • you could search it in parallel with a simple divide and conquer of the problem. Search each half of the list in two (or divide into three, four, ..., parts) different jobs/threads.

    • Or store the strings in a (not binary) tree instead. Will be O(log n).

    • sorted in alphabetical order you can do a binary search (sort of the same as the previous one)

提交回复
热议问题