Presentation is loading. Please wait.

Presentation is loading. Please wait.

©Brooks/Cole, 2003 Chapter 13 File Structures. ©Brooks/Cole, 2003 Understand the file access methods. Describe the characteristics of a sequential file.

Similar presentations


Presentation on theme: "©Brooks/Cole, 2003 Chapter 13 File Structures. ©Brooks/Cole, 2003 Understand the file access methods. Describe the characteristics of a sequential file."— Presentation transcript:

1 ©Brooks/Cole, 2003 Chapter 13 File Structures

2 ©Brooks/Cole, 2003 Understand the file access methods. Describe the characteristics of a sequential file. After reading this chapter, the reader should be able to: O BJECTIVES Describe the characteristics of an indexed file. Describe the characteristics of a hashed file. Distinguish between a text file and a binary file.

3 ©Brooks/Cole, 2003 ACCESSMETHODSACCESSMETHODS 13.1

4 Figure 13-1 Taxonomy ( 分類 ) of file structures

5 ©Brooks/Cole, 2003 SEQUENTIALFILESSEQUENTIALFILES 13.2

6 Figure 13-2 Sequential file A sequential file is one in which records can only be accessed sequentially, one after another, from beginning to end.

7 ©Brooks/Cole, 2003 While Not EOF { Read the next record Process the record } Program 13.1 Processing records in a sequential file The following code show how to access all records in a sequential file.

8 Updating sequential files Files involved in updating: New master file The file contains the most current data Old master file The permanent file that should be updates Transaction file It contains changes to be applied to the master file Error report file The error report contains a listing of all errors discovered during the update process and is presented to the user for corrective action

9 ©Brooks/Cole, 2003 Figure 13-3 Updating a sequential file--process

10 ©Brooks/Cole, 2003 Figure 13-4 Updating process

11 ©Brooks/Cole, 2003 INDEXEDFILESINDEXEDFILES 13.3

12 Indexed files An indexed file is made of a data file, which is a sequential file, and an index. Mapping in an indexed file Figure 13-5

13 ©Brooks/Cole, 2003 Index files To access a record in the file: The entire index file is loaded into main memory. The entries are search to find the desired key. The address of the record is retrieved. Using the address, the data record is retrieved and passed to the user.

14 ©Brooks/Cole, 2003 Figure 13-6 Logical view of an indexed file

15 ©Brooks/Cole, 2003 HASHEDFILESHASHEDFILES 13.4

16 Figure 13-7 Mapping in a hashed file Hashed files In an indexed file, the index maps the key to the address. An hashed file uses a function to accomplish this mapping. The hashed file eliminates the need for an extra file (index).

17 ©Brooks/Cole, 2003 Hashing method For key-address mapping, you can select one of several hashing methods: Direct method (Fig. 13.8) key=address Modulo division method (Fig. 13.9) address = key % list_size +1 Digit extraction method Other methods

18 ©Brooks/Cole, 2003 Figure 13-8 Direct hashing method

19 ©Brooks/Cole, 2003 Figure 13-9 Modulo division method

20 ©Brooks/Cole, 2003 Digit extraction method For example: 125870  158 122801  128 121267  112 … 123413  134

21 ©Brooks/Cole, 2003 Figure 13-10 Collision The set of keys that hash to the same address in our list are called synonyms ( 同名 ).

22 ©Brooks/Cole, 2003 Collision A collision is the event that occurs when a hashing algorithm produces an address for an insertion key, and that address is already occupied. Collision resolution ( 解答 ) Open addressing Linked list resolution Bucket hashing Combination approaches

23 ©Brooks/Cole, 2003 Figure 13-11 Open addressing resolution

24 ©Brooks/Cole, 2003 Figure 13-12 Linked list resolution

25 ©Brooks/Cole, 2003 Figure 13-13 Bucket ( 桶狀物 ) hashing resolution A bucket is a node that can accommodate ( 容納 ) more than one record.

26 ©Brooks/Cole, 2003 TEXTVERSUSBINARYTEXTVERSUSBINARY 13.5

27 Figure 13-14 Text and binary interpretations of a file

28 ©Brooks/Cole, 2003 Text versus binary A text file is a file of characters. It can not contain integers, floating-point numbers, or any other data structures in their internal memory format. Example: the data sent to the printer A binary file is a collection of data stored in the internal format of computer.

29 ©Brooks/Cole, 2003 Key terms Access method Auxiliary storage device Binary file Bucket hashing Collision Collision resolution Data file Digit extraction hashing Direct hashing Disk Division remainder hashing Error report file Hashed file Index Indexed file Key Linked list Linked list resolution Modulo division New master file Old master file Open addressing resolution Random access Secondary storage device Sequential access Sequential file Storage device Synonym Tape Text file Transaction file


Download ppt "©Brooks/Cole, 2003 Chapter 13 File Structures. ©Brooks/Cole, 2003 Understand the file access methods. Describe the characteristics of a sequential file."

Similar presentations


Ads by Google