310 likes | 467 Views
Chapter VI. Random File Organization. Topic Outline. Addressing Techniques Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree Address Calculation or Hashing Address Calculation
E N D
Chapter VI Random File Organization Prepared by: Perla P. Cosme
Topic Outline • Addressing Techniques • Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing • Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree • Address Calculation or Hashing • Address Calculation • Rehashing Strategies This is where we focus our attention Prepared by: Perla P. Cosme
Topic Outline • Addressing Techniques • Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing • Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree • Address Calculation or Hashing • Address Calculation • Rehashing Strategies Prepared by: Perla P. Cosme
Direct Mapping Techniques This mapping technique is the simplest for translating a record key to a storage address. It makes use of some of the physical and logical characteristics of the storage devices used. Some of this characteristics would include the cylinder no., sector no. , track no., the record’s key, etc. Prepared by: Perla P. Cosme
Topic Outline • Addressing Techniques • Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing • Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree • Address Calculation or Hashing • Address Calculation • Rehashing Strategies Prepared by: Perla P. Cosme
Absolute Addressing Key value = address • The key value supplied by a human being or program user is the same as the record’s actual address. • The address maybe a combination of cylinder #, surface #, record #, sector #, etc. • When the record is first stored on the file, the target location of the record is determined by the user. • When the record is later to be retrieved, the absolute location must be known and supplied again by the user. Prepared by: Perla P. Cosme
Absolute Addressing • Advantages • Simple • Given a record’s key value, no processing time is required to determine the record’s location Prepared by: Perla P. Cosme
Absolute Addressing Disadvantages • Logical and physical considerations are not independent; the user must know exactly how the records are stored physically. • It is device-dependent. Should it be desirable to upgrade or change the device upon which the file reside, key values must also be changed. • It is address space-dependent. Should it be reorganized on the same device, the key values need to be changed. Usually, this is incurred during enlarging the address space, consolidating free space, collecting “garbage” space or decreasing address space. Prepared by: Perla P. Cosme
Topic Outline • Addressing Techniques • Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing • Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree • Address Calculation or Hashing • Address Calculation • Rehashing Strategies Prepared by: Perla P. Cosme
Relative Addressing This addressing mode tries to remove some of the disadvantages of absolute addressing. It uses the mapping function defined as, key value = relative address Prepared by: Perla P. Cosme
Relative Addressing A relative address can be supplied to a channel program for translation to an absolute address. The relative address of a record in a file is the record’s ordinal number in the file. A file with space for n records has records with relative addresses from the set {1, 2, 3, …, N-1, N} the ith record has a relative address of i. Prepared by: Perla P. Cosme
Relative Addressing Advantages: • The mapping function is very simple. • Given the record’s key value, essentially no processing time is required to determine the record’s location on secondary storage. • Relative addresses are not (nearly) device-dependent as compared with absolute addressing. Prepared by: Perla P. Cosme
Relative Addressing Disadvantage: Relative addressing is address-space-dependent. Prepared by: Perla P. Cosme
Topic Outline • Addressing Techniques • Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing • Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree • Address Calculation or Hashing • Address Calculation • Rehashing Strategies Prepared by: Perla P. Cosme
Directory Look-up The use of a table or a tree-like structure facilitates the reference of the location of a record. The table contains vital information such as the relative position of the record and also the record’s key value. The tree-like structure enables a fast search by arranging the records in a Binary Search Tree manner. Prepared by: Perla P. Cosme
Directory Look-up It is intended to keep a table or directory of key valueandaddress pairs (or key value and relative address pairs). In order to find a record on a relative file, one locates its key value in the directory and then the indicated address is used to find the record on storage. Prepared by: Perla P. Cosme
Directory Look-up The directory is implemented as an array of key value and address records (see figure on the next page). The directory entries are sorted by key value so that a binary rather than sequential search can be used to locate a target entry more rapidly. Note that the relative file entries are not in sorted order. Prepared by: Perla P. Cosme
Directory Look-up There are two ways on how to keep the directory lookup, namely; • directory structure as a tableor • directory structure as a tree. Prepared by: Perla P. Cosme
A Directory Table Prepared by: Perla P. Cosme
Topic Outline • Addressing Techniques • Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing • Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree • Address Calculation or Hashing • Address Calculation • Rehashing Strategies Prepared by: Perla P. Cosme
Directory Tree Prepared by: Perla P. Cosme
Directory Look-up Advantages: • A record’s location can be determined with essentially no processing, once the key value is found in the directory. • Keys can be represented in intuitively understandable forms, since they are translated “internally” to addresses. • Logical-physical independence is achieved, because the key values are address-space-dependent. If the relative file is reorganized, address entries in the directory must be changed, but the key values will not be affected. Prepared by: Perla P. Cosme
Topic Outline • Addressing Techniques • Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing • Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree • Address Calculation or Hashing • Address Calculation • Rehashing Strategies Prepared by: Perla P. Cosme
Address Calculation Technique The main idea is to perform a calculation on the key value such that the result is a relative address. This technique can be used in conjunction with the directory look-up scheme. The function must translate a relatively large domain of possible key values to a relatively small range of relative address values. Prepared by: Perla P. Cosme
Address Calculation Technique The identification of the address of the record is based on some formula or equation which is called hashing function. Prepared by: Perla P. Cosme
Address Calculation Techniques Advantages: • Natural key values can be used, since they are translated “internally” to addresses. • Logical-physical independence is achieved because the key values are address-space independent. If the relative file is reorganized, the hash function may need to be changed, but the key values will not be affected. Prepared by: Perla P. Cosme
Address Calculation Techniques Disadvantages: • The processing time required to apply the hash function. • The processing time and I/O accesses required to resolve collisions. Prepared by: Perla P. Cosme
Address Calculation or Hashing Other names or synonyms of Address Calculation • scatter storage techniques • randomizing techniques • key-to-address transformation methods • direct addressing techniques • hash table methods • hashing This is similar with Direct Addressing This is where we focus our discussion. Prepared by: Perla P. Cosme
Question: What is the role of a hash (or hashing) function in Random File Organization? Answer/ Explanation: • The computed value using the hash function will serve as the random address of the record in a relative position. • If you subject each record (within a file) in a hash function, each of these records will soon be randomly distributed across a relative position. • The random placement of the records is the ultimate objective of RFO Prepared by: Perla P. Cosme
After we have presented the different addressing techniques, let’s take a closer on the different strategies to randomize the relative addresses of records. Coming up next .... Hashing techniques Prepared by: Perla P. Cosme