In this case, consider the following data structure:
Dictionary tree (DictTree)
typedef struct _dict_tree_
{
struct _dict_tree_ * dt[TREENODENUM];
char c ;
char flag ;
}DT ;
The specific operation is
The so-called 26-fork tree is stored according to the child nodes corresponding to each letter.
Then read the words line by line and insert them into the tree, for example:
Word: abandon
The order of insertion into the tree is
a->b->a->n->d->o->n
Insert the child node corresponding to this tree for each letter
Based on your question, it seems that these words have been sorted? If it is in order, it can be done according to the dichotomy method. First read the total number of lines in the file, then search by the first character, then by the second character, and so on. The advantage of this algorithm is that it does not need to read all the files into memory.
In this case, consider the following data structure: Dictionary tree (DictTree)
The specific operation is
The so-called 26-fork tree is stored according to the child nodes corresponding to each letter. Then read the words line by line and insert them into the tree, for example: Word: abandon The order of insertion into the tree is a->b->a->n->d->o->n Insert the child node corresponding to this tree for each letter
The search is to follow the letters to determine whether the child node is empty
If preprocessing of txt files is allowed, it can be achieved using inverted index.
If the txt file is only checked once and never used again, then no.
Based on your question, it seems that these words have been sorted? If it is in order, it can be done according to the dichotomy method. First read the total number of lines in the file, then search by the first character, then by the second character, and so on. The advantage of this algorithm is that it does not need to read all the files into memory.
If you modify the question, this txt file is 1T in size. How can I fix it better? If you don't have enough reputation, you can't change it.