Quick search if word exists in dictionary text file

I have a large text file (~ 10mb) that has more or less every dictionary in a particular language, and each word is a new line.

I want to do a very quick search to see if a word exists in a file - What is the fastest way to do this without scrolling through each line?

It is sorted and I can do all the preprocessing I want.

I was considering the possibility of doing some kind of binary search, but I did not know how to do this, since all my lines are not a fixed number of bytes (and therefore, I do not know where to stream the stream). And it is amazing that I could not find a tool to make a fixed width for me.

Any suggestions? Thank!

+3
source share
2 answers

I would suggest creating Trie from a dictionary. This gives you a very quick search to see if the word is there.

+6
source

Three is a good bet if you don't mind using some more storage: http://en.wikipedia.org/wiki/Trie

+1
source

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


All Articles