Super fast autocomplete using binary search in a sorted file (300,000 lines)

In my Android app, I want to have an autocomplete input field. The number of elements will be around 300,000. The best solution seems to be to put the elements in a file (on sdcard), one element per line, each line will have the same number of characters so that I can search for a specific line number. If the user enters something in the text box, I would have a binary search (via RandomAccessFile) file and show the sentences.

I want autocomplete to be super fast (ideally up to 100 ms, but I think it's impossible), what optimizations can I do?

Update 1: I will convert user input to lowercase English characters (az) with spaces. Thus, "A / b" will be converted to "a b", and then a search will be performed.

Uodate 2: Now I realized that I need an extra thing - look for source substrings.

+3
source share
11 answers

What you are looking for is called TRIE

http://forums.sun.com/thread.jspa?threadID=5295936

, , . , no node , node; , . node , node, . node, , .

+6

SQLite?
, - , .

+5

Trie - , , , tr13 , . ( ), , , . UTF-8, . , ints (vints) , String-to-int ( int).

+3

RandomAccessFile . , , .

, , , , .

+2
+1

, .

+1

, . , apache lucene Android. , ( → android sql lite). - lucene .

+1

, ( X X ), ,

() ( , , , ).

+1

100 - . , .

, .

N (4, ?) 32 , . 32 , .

32 , , . 512- 8- , 64 .. .

, .

+1

Old thread, but THIS WHAT NEEDS : Stringsearch library

I used it for my Wordlist Pro application for Android, and it is very fast.

+1
source

I could also do something like this (below is a pre-processed file):

aa - line 1
ab - line 17
.
.
zz - line 299819 

If the user enters something starting with aa, I would read lines 1 through 17 and search them sequentially

0
source

Source: https://habr.com/ru/post/1764914/


All Articles