Home > Data Center Tips > CICS Newsletter > Hash table how-tos for mainframe programmers
Data Center Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

CICS NEWSLETTER

Hash table how-tos for mainframe programmers


Robert Crawford, Contributor
01.29.2008
Rating: -3.40- (out of 5)


IT infrastructure news
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


I like to put referential data into external tables. It makes programs easier to maintain and it's much safer to change a table than logic. The only catch is that system level code, particularly in exits, must be very efficient. You wouldn't want to do a linear search of a fifty entry table for every file I/O as that would tend to bog things down. Ultimately the answer is to use a hash table.

Hash table basics
The idea behind hashing is to transform the table key into a number that can be used to directly access an entry. That way, a potentially long search loop turns into some arithmetic and a couple of memory references. Below is a diagram of a simple hashing structure.

hash table sample diagram
More on mainframe tables:
CICS program list tables: PLTPI and PLTSD programs

Adding and deleting CICS data tables

A hash table is simply a list of pointers. It must have a fixed length and be contiguous in memory. The addresses in the hash table may point to a table entry or be null, depending on the hashing algorithm.

The table itself contains the information you need. It may be in contiguous storage or spread all over creation, depending on your needs. In addition, each table entry needs a pointer for what's called a synonym chain.

Synonyms are table entries whose keys transform into the same index of the hash table. The hash table points to the first table entry for that hash value, then other entries for that index will be on the synonym chain. If there are no synonyms the chain pointer will be null. I know this goes against the premise that hashing eliminates loops but, unless the hashing algorithm is very badly suited to the table's keys, a search down the synonym chain will always be cheaper.

Hashing algorithms
Hashing algorithms transform the table key into an index whose value is between 0 and one minus the number of entries, inclusive. It then multiplies the index by 4 (or 8 in the 64 bit addressing world) thus creating an offset into the hash table.

As mentioned above, this is highly data dependent and it may be worthwhile to study the table's keys for shortcuts. For instance, if the table key is four bytes long but only the last two changes, a good hashing algorithm might consist of lopping off the first two bytes and using the remainder as the index.

If the key is more variable there are a couple of ways to randomize or boil it down to an index. An example is the Assembler PACK instruction, normally used to convert EBCDIC numbers into packed decimal. PACK works on character strings, too, and can reduce one into a usable index. Say you have a key of ABCDEFGH which is C1C2C3C4C5C6C7C8 in hex. The PACK instruction picks out the right nibble out of each byte to create the five byte binary number 012345678C. This is a good first step, although the resulting number may still need some pummeling to be a good index.

My favorite method is to divide the table key by the number of entries in the hash table and use the remainder as the index. Assume you have a four byte key to hash into a 32 entry hash table. Using ABCD as an example, my algorithm would divide X'C1C2C3C4' by 32 (hex 20) giving a remainder of 4 for use as an index.

Hash table implementation
After deciding on the hashing algorithm and table size you must write the routine to build the structure. This is fairly simple, remembering that the idea is to do all the work ahead of time as to save CPU in executing the search routines. Here is what the logic must do:

  • load the object table, and go through the table and hash each entry's key. Store the entry's address in the hash table if its slot is empty. If the slot is not empty, insert it into the synonym chain.
Now searching becomes very quick as it runs the search key through the hashing algorithm which returns an offset into the hashing table. Next the search routine gets the pointer to the table entry and checks the key. If they don't match it has to go through the synonym chain if one exists. Depending on the efficiency of the hash a search may be accomplished with four or five instructions instead of a repetitive loop.

There are a couple efficiency tweaks to the basic idea:

  • You can optimize an entry's position on the synonym chain by putting the entries in collating sequence. This allows the search routine to give up when it finds a key higher than the one it's looking for.
  • You may also want to add code to your construction routine to collect statistics if you're concerned about synonym chain lengths or the number of empty hashing table slots.
  • Lastly, you might try increasing the hash table size if the synonym chains get too long. There are diminishing returns as you will most likely always have synonyms. If the chains are still too long you may want to consider rewriting the hash algorithm.
Although hashing algorithms are processor-efficient, they will waste storage. Any number of slots in the hashing table may be empty in addition to the extra space needed for synonym chains. Still, after 60 years the processor is still the computer's most precious resource and system level code must be efficient enough to get quickly out of the way so the business can run.

ABOUT THE AUTHOR: For 24 years, Robert Crawford has worked off and on as a CICS systems programmer. He is experienced in debugging and tuning applications and has written in COBOL, Assembler and C++ using VSAM, DLI and DB2.

Rate this Tip
To rate tips, you must be a member of SearchDataCenter.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




BROWSE BY TAG
CICS Newsletter,   Mainframe operating systems and management,   Server hardware,   Mainframe computers,   VIEW ALL TAGS

Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
CICS Newsletter
IBM z/OS 1.11 preview: New features and functions
New statistics for CICS Transaction Server 3.2
Manage CICS workloads with transaction classes
Run CICS in batch to beat a shrinking batch window
Ensuring CICS security with the Web Services Security standard
Use DFHLS2WS to expose CICS applications as a Web service
Using IBM IPCS to battle software bugs
CICS and Web services: Ready to go
Using External Call Interface (EXCI) to access CICS
Using CICS event monitoring points (EMPs) for tuning and debugging

Mainframe operating systems and management
Roadmap to mainframe application modernization
Improve CICS Web services security and handle Web transaction requests
Coding a simple mainframe cryptography program
How is CICS prepared for future IT market demands?
Why IBM should listen to Neon Software, customers on zPrime
Aussie financial firms dump Unix, Windows for Linux on the mainframe
Using cryptography on the mainframe: An amateur's guide
How mainframes fit into cloud computing
IBM z/OS 1.11 preview: New features and functions
Neon Software CEO rejects IBM warnings on mainframe licensing issues due to zPrime

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
epoch  (SearchDataCenter.com)
ISPF  (SearchDataCenter.com)
job  (SearchDataCenter.com)
Job Entry Subsystem  (SearchDataCenter.com)
job scheduler  (SearchDataCenter.com)
job step  (SearchDataCenter.com)
MVS  (SearchDataCenter.com)
P/390  (SearchDataCenter.com)
Remote Job Entry  (SearchDataCenter.com)
z/OS  (SearchDataCenter.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



White Papers - Data Center Networking

The Intel IT Technology Center - Power, Performance and Mobility Solutions

HomeNewsTopicsITKnowledge ExchangeTipsBlogsMultimediaWhite PapersEvents
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts