IBM 1130 User Manual page 598

Computing system
Hide thumbs Also See for 1130:
Table of Contents

Advertisement

Section
Subsections
Page
75
30
1
10
05
Address Calculation
When the approximate distribution of the key values
is known, it becomes possible to sort a file inter-
nally by estimating the eventual (sorted) position
of each key. This method is called "address cal-
culation" or "pigeonhole sorting".
Briefly, it consists of calculating the correct
record number of each item within the file by a
predetermined linear formula of the form y= a +bx.
If
the location at that record number is empty, the
item (record or key) is placed there; if it is full,
a search is made to find the closest empty space in
the viCinity of the calculated record number. The
item at the calculated record number and the adja-
cent items are then moved so that the new item can
be inserted in its proper place in the sequence.
Address calculation is similar to the insertion
method in that each item is placed directly in its
proper relative position within the file, and the
entire file is in order just after the last item has
been inserted. The method differs from insertion,
however, in that some foreknowledge of the range
and distribution of the keys is required to estimate
the relative location for each item. When this is
available, address calculation is a relatively simple
and rapid method for sorting a medium-size file
(several hundred to a few thousand items) of small
to medium-length records. The major disadvantage
of the method is the need for a fairly large storage
area -- about two or three times the size of the area
needed for the original file. If only a relatively
small working storage area is available, or if the
distribution within the file is not as forecast, a great
deal of processing time will be spent in redistrib-
uting the records.
To illustrate this method, let us consider a
hypothetical case: Many years ago, the ABC Com-
pany set up a man-number system based on a three-
digit number. Since they had about 150 employees,
each man was assigned, in alphabetic order, a num-
ber evenly divisible by 5 (005, 010, 015, 020, 025,
... ,995). However, there are now about 240 em-
ployees, and the system is not quite as neat as it
once was.
Some of the men (50 of them) have been assigned
num bers out of the normal pattern (for example,
862 in between 860 and 865). They are still in alpha-
betic order, though.
The address calculation sort could be used to
place this employee file onto the disk in alphabetic
(man-number) sequence in the following way:
1. Set up a file containing 500 records.
2. As each man-number is encountered, divide
it by 2.5, and convert the result to an integer (call
it N).
3. Check record number N to see whether there
is already an employee there.
4.
If
there isn't, put the man just processed into
that record.
5.
If
there
!E
someone there already, move the
adjacent records up (or down) until there is room
to insert the new man.
This will be quite fast, provided the "moving around"
(step 5) is not required too frequently.
If
it is, the
file could be increased to 600 records, and the man-
number divided by 2.
This, however, would waste
a considerable amount of space on the disk.

Advertisement

Table of Contents
loading

Table of Contents