HP Pascal/iX Programmer's Guide (31502-90023)
5-: 23
Table 5-10. How Set Chunk Size Is Determined (HP Pascal Packing Algorithm)
---------------------------------------------------------------------------------------
|| |
| Number of Bits | Set Chunk Size |
| Required | |
| To Represent Set | |
|| |
---------------------------------------------------------------------------------------
|||||
||Set is not PACKED | Set is PACKED | Set is CRUNCHED |
|||||
---------------------------------------------------------------------------------------
|||||
| 1 to 8 | 32 bits | 8 bits | 1 bit |
|||||
---------------------------------------------------------------------------------------
|||||
| 9 to 16 | 32 bits | 16 bits | 1 bit |
|||||
---------------------------------------------------------------------------------------
|||||
| 17 or more | 32 bits | 32 bits | 1 bit |
|||||
---------------------------------------------------------------------------------------
The number of set chunks allocated to a set depends on its type. For the
types Boolean, char, enumeration, and integer, the formula for the number
of set chunks is:
number_of_set_chunks
=
ceil(bits_required_for_set/set_chunk_size)
(where
ceil(x)
means the integer closest to
x
that is greater than or
equal to
x
).
Table 5-11 gives the values for
bits_required_for_set
and
number_of_set_chunks
for Boolean, char, and integer base types. For
enumerated sets,
bits_required_for_set
is the number of elements in the
set, and you must use the formula to determine
number_of_set_chunks
.
Table 5-11. Bit and Set Chunk Requirements for Boolean,
Char, and Integer Types
(HP Pascal Packing Algorithm)
---------------------------------------------------------------------------------------
|| | |
| Base Type | bits_required_for_set | number_of_set_chunks |
|| | |
---------------------------------------------------------------------------------------
|| | |
| Boolean | 2 | 1 |
|| | |
---------------------------------------------------------------------------------------
|| | |
| Char | 256 | 8 |
|| | |
---------------------------------------------------------------------------------------
|| | |
| Integer * | 256 (by default) * | 8 |
|| | |
---------------------------------------------------------------------------------------
* Same for bit16, bit32, bit52, shortint, and longint.
* Integers outside the range 0..255 cannot belong to the set.
Example 1
VAR
days = SET OF (sun,mon,tues,wed,thurs,fri,sat);
months = PACKED SET OF (ja,f,mr,ap,ma,jn,jl,au,s,o,n,d);