Google
 
Site navigation: [ Home | Theory | Java | Moodle courses | Resource wiki | About ]

Fully-indexed file organization

7.1.5
Fully-indexed file organization

 

 

 

 

 

 

 

 

 

 

Thus index[1] contains the value 5 - the first title in the file alphabetically.

If it was an author index, what would index[1] contain?

 

 

 

 

 

 

 

 

 

 

 

I hope you answered 2

Ideally, all data files would be sequential (the records maintained in order of some key field) to allow binary search.

However, this can require shifting large amounts of data when a new record is inserted and, you can't order data on more than one field .

If you are keeping a list of library books , for example, you might want to search by author, title or keyword. If the file were to be sequential you would probably organise it by book number anyway. Consider the following file: 

Record number

Book number

Title

Author

Year

1

1001

The Time of my Life

Jasper, Michael

1945

2

1013

Christopher Columbus

Andrews, Julie

1492

3

1015

Secret Garden

Quentin, Hiaphon

1978

4

1024

UWC Handbook

Benzene, Jorgen

1996

5

1029

Andrew The Analyst

Zimlicz, Jasmin

1992

The records have been added in no book number order, but it is possible to maintain an index on any of the other fields. For example, for the title :

Index element
Title position

Record number

Book number

Title
 

Author
 

Year
 

1
5

1

1001

The Time of my Life

Jasper, Michael

1945

2
2

2

1013

Christopher Columbus

Andrews, Julie

1492

3
3

3

1015

Secret Garden

Quentin, Hiaphon

1978

4
1

4

1024

UWC Handbook

Benzene, Jorgen

1996

5
4

5

1029

Andrew The Analyst

Zimlicz, Jasmin

1992

 In order to output the records in title order the following kind of algorithm might be used:

   i = 1
   While not eof(Datafile) do
     MoveTo(Datafile(,Index(i))
     read(datafile, CDRecord Output(CD number, Title, Author, Year)
     i = i + 1
   enddo

The code assumes that the array, Index, has been set-up to contain the order of records by Title, as shown. This code moves the file pointer to the selected record, reads the record and outputs the data in title order.

If index lists are held on other fields, Year or Author, for example, it is equally easy to output records in different orders. The list of indexes can be held in memory (using an array) or held in files (index files). This avoids the need to load the whole data file into memory. 

related: [ Topic 7 home | previous: partially-indexed files | next: direct access files ]

See the pupil\java\files directory for examples of using fully indexed files. See the Java Page on files for some more programming examples on this topic (not yet, just a reminder to me to do it).

 

 


 
The site is partly financed by advertising revenue, partly by online teaching activities and partly by donations. If you or your organisation feel these resouces have been useful to you, please consider a donation, $9.95 is suggested. Please report any issues with the site, such as broken links, via the feedback page, thanks.

Questions or problems related to this web site should be addressed to Richard Jones who asserts his right to be identified as the author and owner of these materials - unless otherwise indicated. Please feel free to use the material presented here and to create links to it for non-commercial purposes; an acknowledgement of the source is required by the Creative Commons licence. Use of materials from this site is conditional upon your having read the additional terms of use on the about page and the Creative Commons Licence. View privacy policy.

Creative Commons License


This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. © 2001 - 2009 Richard Jones, PO BOX 246, Cambridge, New Zealand;
This page was last modified: May 31, 2009