Chapter VI

30
Chapter VI Random File Organization 1 Prepared by: Perla P. Cosme

description

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 - PowerPoint PPT Presentation

Transcript of Chapter VI

Page 1: Chapter VI

Prepared by: Perla P. Cosme 1

Chapter VI

Random File Organization

Page 2: Chapter VI

2

Topic Outline

1. Addressing Techniquesa. Direct Mapping

a.1 Absolute Addressing a.2 Relative Addressing

b. Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree

c. Address Calculation or Hashing2. Address Calculation3. Rehashing Strategies

Prepared by: Perla P. Cosme

This is where we focus our attention

Page 3: Chapter VI

3

Topic Outline

1. Addressing Techniquesa. Direct Mapping

a.1 Absolute Addressing a.2 Relative Addressing

b. Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree

c. Address Calculation or Hashing2. Address Calculation3. Rehashing Strategies

Prepared by: Perla P. Cosme

Page 4: Chapter VI

Prepared by: Perla P. Cosme 4

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.

Page 5: Chapter VI

5

Topic Outline

1. Addressing Techniquesa. Direct Mapping

a.1 Absolute Addressing a.2 Relative Addressing

b. Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree

c. Address Calculation or Hashing2. Address Calculation3. Rehashing Strategies

Prepared by: Perla P. Cosme

Page 6: Chapter VI

Prepared by: Perla P. Cosme 6

Absolute Addressing

• 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.

Key value = address

Page 7: Chapter VI

Prepared by: Perla P. Cosme 7

Absolute Addressing

• Advantages– Simple– Given a record’s key value, no

processing time is required to determine the record’s location

Page 8: Chapter VI

Prepared by: Perla P. Cosme 8

Absolute AddressingDisadvantages

– 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.

Page 9: Chapter VI

9

Topic Outline1. Addressing Techniques

a. Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing

b. Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree

c. Address Calculation or Hashing2. Address Calculation3. Rehashing Strategies

Prepared by: Perla P. Cosme

Page 10: Chapter VI

Prepared by: Perla P. Cosme 10

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

Page 11: Chapter VI

Prepared by: Perla P. Cosme 11

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.

Page 12: Chapter VI

Prepared by: Perla P. Cosme 12

Relative Addressing

Advantages:1. The mapping function is very simple.2. Given the record’s key value, essentially no

processing time is required to determine the record’s location on secondary storage.

3. Relative addresses are not (nearly) device-dependent as compared with absolute addressing.

Page 13: Chapter VI

Prepared by: Perla P. Cosme 13

Relative Addressing

Disadvantage:Relative addressing is address-space-dependent.

Page 14: Chapter VI

14

Topic Outline1. Addressing Techniques

a. Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing

b. Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree

c. Address Calculation or Hashing2. Address Calculation3. Rehashing Strategies

Prepared by: Perla P. Cosme

Page 15: Chapter VI

Prepared by: Perla P. Cosme 15

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.

Page 16: Chapter VI

Prepared by: Perla P. Cosme 16

Directory Look-up

It is intended to keep a table or directory of key value and address 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.

Page 17: Chapter VI

Prepared by: Perla P. Cosme 17

Directory Look-upThe 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.

Page 18: Chapter VI

Prepared by: Perla P. Cosme 18

Directory Look-up

There are two ways on how to keep the directory lookup, namely;

1. directory structure as a table or 2. directory structure as a tree.

Page 19: Chapter VI

Prepared by: Perla P. Cosme 19

A Directory Table

Key Address Rel. Adr. Relative File

APE I-1 1 COWBAT N 2 ZEBRACAT 3 3 CAT

::

::

::

COW 1 I-1 APEDOG I+1 I ELLEEL I I+1 DOG

::

::

::

ZEBRA 2 N BAT

Page 20: Chapter VI

20

Topic Outline1. Addressing Techniques

a. Direct Mapping a.1 Absolute Addressing a.2 Relative Addressing

b. Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree

c. Address Calculation or Hashing2. Address Calculation3. Rehashing Strategies

Prepared by: Perla P. Cosme

Page 21: Chapter VI

Prepared by: Perla P. Cosme 21

Directory Tree

APE, I-1 BAT, N CAT, 3COW, 1 DOG, I+1 EEL, I ZEBRA, 2

Rel. Adr. Relative File1 COW

2 ZEBRA

3 CAT

:

I-1 APE

I ELL

I+1 DOG

:

N BAT

Page 22: Chapter VI

Prepared by: Perla P. Cosme 22

Directory Look-upAdvantages:1. A record’s location can be determined with essentially

no processing, once the key value is found in the directory.

2. Keys can be represented in intuitively understandable forms, since they are translated “internally” to addresses.

3. 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.

Page 23: Chapter VI

23

Topic Outline

1. Addressing Techniquesb. Direct Mapping

a.1 Absolute Addressing a.2 Relative Addressing

c. Directory Look-up b.1 Directory Structure as a Table b.2 Directory Structure as a Tree

c. Address Calculation or Hashing2. Address Calculation3. Rehashing Strategies

Prepared by: Perla P. Cosme

Page 24: Chapter VI

Prepared by: Perla P. Cosme 24

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.

Page 25: Chapter VI

Prepared by: Perla P. Cosme 25

Address Calculation Technique

The identification of the address of the record is based on some formula or equation which is called hashing function.

Page 26: Chapter VI

Prepared by: Perla P. Cosme 26

Address Calculation Techniques

Advantages:1. Natural key values can be used, since they are

translated “internally” to addresses.2. 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.

Page 27: Chapter VI

Prepared by: Perla P. Cosme 27

Address Calculation Techniques

Disadvantages:1. The processing time required to apply the

hash function.2. The processing time and I/O accesses

required to resolve collisions.

Page 28: Chapter VI

Prepared by: Perla P. Cosme 28

Address Calculation or Hashing

Other names or synonyms of Address Calculation

1. scatter storage techniques2. randomizing techniques3. key-to-address transformation

methods4. direct addressing techniques5. hash table methods6. hashing

This is similar with

Direct Addressing

This is where we focus our

discussion.

Page 29: Chapter VI

Prepared by: Perla P. Cosme 29

Question: What is the role of a hash (or hashing) function in

Random File Organization?

Answer/ Explanation:1. The computed value using the hash function will serve

as the random address of the record in a relative position.

2. 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.

3. The random placement of the records is the ultimate objective of RFO

Page 30: Chapter VI

Prepared by: Perla P. Cosme 30

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