HashSet of Strings taking up too much memory, suggestions…?

前端 未结 8 1845
闹比i
闹比i 2020-12-29 08:44

I am currently storing a list of words (around 120,000) in a HashSet, for the purpose of using as a list to check enetered words against to see if they are spelt correctly,

8条回答
  •  一整个雨季
    2020-12-29 09:22

    One way to save memory to save memory is to use a radix tree. This is better than a trie as the prefixes are not stored redundantly.

    As your dictionary is fixed another way is to build a perfect hash function for it. Your hash set does not need buckets (and the associated overhead) as there cannot be collisions. Every implementation of a hash table/hash set that uses open addressing can be used for this (like google collection's ImmutableSet).

提交回复
热议问题