Way to store a large dictionary with low memory footprint + fast lookups (on Android)

前端 未结 7 1054
醉话见心
醉话见心 2021-01-30 23:17

I\'m developing an android word game app that needs a large (~250,000 word dictionary) available. I need:

  • reasonably fast look ups e.g. constant time preferable, n
7条回答
  •  耶瑟儿~
    2021-01-30 23:59

    I am assuming that you want to check if given word belongs to dictionary.

    Have a look at bloom filter.

    The bloom filter can do "does X belong to predefined set" type of queries with very small storage requirements. If the answer to query is yes, it has small (and adjustable) probability to be wrong, if the answer to query is no, then the answer guaranteed to be correct.

    According the Wikipedia article you could need less than 4 MB space for your dictionary of 250 000 words with 1% error probability.

    The bloom filter will correctly answer "is in dictionary" if the word actually is contained in dictionary. If dictionary does not have the word, the bloom filter may falsely give answer "is in dictionary" with some small probability.

提交回复
热议问题