Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating an indexed file

Status
Not open for further replies.

ars100

Programmer
Mar 15, 2003
2
US
Hi,
Can someone tell me what is the best way to create indexed file to do searching. If I want to do searching on multiple keys, sorting the file will not help.
I'm beginner in Java programming, trying to do some searching programs in Unix.

Thanks a million for your help.

Ars.
 
The basic concept of an index is to contain the "key" and a "pointer" to the matching record in the main data repository.

Each index entry contains the combination "key,pointer". The entire index data set is sorted by the "key" values, that is how you will perform a search on the "key".

The "key" is the information you will be searching on. The "pointer" needs to be whatever you need to locate the actual data block in it's original data repository.

So if you need to locate data using different sets of "key" information you would create an index data set for each of the "key" types.

By example lets say you had a file that was delimited using commas for fields and CR for records containing the fields

Code:
FirstName,LastName,.... other information....CR
FirstName,LastName,.... other information....CR

Then you might want the following three indexed data sets
FirstName
LastName
LastName+FirstName

So in the first case your index file might look like this:

Ars100,3401

Where [3401] is the file position to the first byte in that record. The index file is sorted by the first field and possibly read into an array at runtime for performance. A simple binary search could be used on the array.

hope that helps
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top