Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to create an index on a text file using data structures and algorithms
Posted
Updated 13-Nov-11 23:34pm
v2
Comments
Debojyoti Majumder 14-Nov-11 5:16am    
Please specify the problem in detail...
BillWoodruff 14-Nov-11 5:34am    
Although we have many "psychics" here, I think we need to know exactly what you mean by index in order to provide useful responses.

As a question, that doesn't really work: what is an index on a text file?

Do you mean an index, as in a book index - an alphabetical list of names, subjects, etc., with references to the places where they occur, typically found at the end of a book?

If so, then first read the file, convert it into each separate word, together with an offset from the start of the file. Then sort them and remove duplicates, keeping each offset together.


Do you mean an index to each line in the file?
If so, then read the file, break it into lines, and build up a cumulative list of the offsets from the start of the file.

Do do you mean something else?


Be aware though, that you may have to treat the file as bytes rather than text, or the offsets may be different depending on what system produced the file - newline is not always the same length!
 
Share this answer
 
Create an index class, or use a generic type. Read each word or token from the file and, if required, add the token and its location to the index. Repeat until all text has been processed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900