Reputation: 4553
I'm writing an android application which stores a set of ~50.000 strings, and I need input on how to best store them.
My objective is to be able to query with low latency for a list of
strings matching a pattern (like Hello W*
or *m Aliv*
), but avoid
a huge initialization time.
I thought of the following 2 ways:
Are my "imagine"s correct or horribly wrong? Which way would be best?
Upvotes: 1
Views: 241
Reputation: 20426
I would definitely stick to SQLite. It's really fast in the both initialization and querying. SQLite runs in application process, thus there is almost no time penalties on initialization. A query is normally fired in a background thread to not block main thread. It will be very fast on 50.000 records and you won't load all data in memory, which is also important.
Upvotes: 1
Reputation: 975
If you want quick (as in instant) search times, what you need is a full-text index of your strings. Fortunately, SQLite has some full-text search support with the FTS extension. SQLite is part of the Android APIs and the initialisation time is totally negligible. What you you do have to watch is that the index (the .sqlite file) has to either be shipped with your app in the .apk, or be re-created the first time it opens (and that can take quite some time)
Upvotes: 5
Reputation: 1944
your string no are 50 in this case you can use java collection database will be time taking.
Upvotes: -1
Reputation: 9434
Look at data structures like a patricia trie (http://en.wikipedia.org/wiki/Radix_tree) or a Ternary Search Tree (http://en.wikipedia.org/wiki/Ternary_search_tree). They will dramatically reduce your search time and depending on the amount of overlap in your strings may actually reduce the memory requirements. The Java collections are good for many purposes but are not optimal for large sets of short strings.
Upvotes: 1