13.07.2015 Views

13.1 through 13.5, 13.10 and 13.11

13.1 through 13.5, 13.10 and 13.11

13.1 through 13.5, 13.10 and 13.11

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13 Disk Storage, Basic File Structures, <strong>and</strong> Hashingaddress space when the mod hashing function is used. Other hash functions mayrequire M to be a power of 2.13.8.2 External Hashing for Disk FilesHashing for disk files is called external hashing. To suit the characteristics of diskstorage, the target address space is made of buckets, each of which holds multiplerecords. A bucket is either one disk block or a cluster of contiguous blocks. Thehashing function maps a key into a relative bucket number, rather than assigning anabsolute block address to the bucket. A table maintained in the file header convertsthe bucket number into the corresponding disk block address, as illustrated inFigure 13.9.The collision problem is less severe with buckets, because as many records as will fitin a bucket can hash to the same bucket without causing problems. However, wemust make provisions for the case where a bucket is filled to capacity <strong>and</strong> a newrecord being inserted hashes to that bucket. We can use a variation of chaining inwhich a pointer is maintained in each bucket to a linked list of overflow records forthe bucket, as shown in Figure <strong>13.1</strong>0. The pointers in the linked list should berecord pointers, which include both a block address <strong>and</strong> a relative record positionwithin the block.Hashing provides the fastest possible access for retrieving an arbitrary record giventhe value of its hash field. Although most good hash functions do not maintainrecords in order of hash field values, some functions-called order preservingdo.A simple example of an order preserving hash function is to take the leftmostthree digits of an invoice number field as the hash address <strong>and</strong> keep the recordssorted by invoice number within each bucket. Another example is to use an integerFigure 13.9Matching bucket numbers to disk block addreBucketNumberBlock address on diskM-2M-1012n trT

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!