| United States-English |
|
|
|
![]() |
HP Pascal/HP-UX Programmer's Guide > Chapter 5 Allocation and Alignment Sets |
|
The HP Pascal packing algorithm allocates sets in units called set chunks. Set chunk size depends on the number of bits required to represent the set and whether the set is unpacked, packed, or crunched. The number of bits required to represent the set is determined by the formula:
Table 5-13 “How Set Chunk Size Is Determined (HP Pascal Packing Algorithm) ” shows how the HP Pascal packing algorithm determines set chunk size. Table 5-13 How Set Chunk Size Is Determined (HP Pascal Packing Algorithm)
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:
(where ceil(x) means the integer closest to x that is greater than or equal to x). Table 5-14 “Bit and Set Chunk Requirements for Boolean, Char, and Integer Types (HP Pascal Packing Algorithm) ” 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-14 Bit and Set Chunk Requirements for Boolean, Char, and Integer Types (HP Pascal Packing Algorithm)
Title not available (Sets )
Example 1
The set days has seven elements and requires seven bits. Its set chunk size is four bytes (32 bits), so days is allocated one set chunk. Each element is represented by one bit, like this: The set months has 12 elements and requires 12 bits. Its set chunk size is two bytes, so months is allocated one set chunk (ceil(12/(2*8))=1). Each element is represented by one bit. Each of the sets set_33 and p_set_33 has 33 elements and requires 33 bits. The set chunk size is four bytes, so set_33 is allocated two set chunks (ceil(33/(4*8))=2). Each element is represented by one bit. If the type is a subrange, the formula for the number of set chunks is:
The upper bound of the subrange determines upper_bound_set_chunk_number, and the lower bound determines lower_bound_set_chunk_number. The formula is:
(where floor(x) means the integer closest to x that is less than or equal to x). Example 2
The set s is unpacked, so it has a 32-bit set chunk (see Table 5-13 “How Set Chunk Size Is Determined (HP Pascal Packing Algorithm) ”). The upper bound of the subrange is 18, so upper_bound_set_chunk_number is zero (floor(18/32=0)). The lower bound of the subrange is -7, so lower_bound_set_chunk_number is -1 (floor(-7/32)=-1). The set s is allocated two set chunks (0-(-1))+1=2). Each set element is represented by one bit, like this: To minimize storage space, avoid base types that are small subranges that overlap set chunk boundaries. Example 3
The set s1 takes two 32-bit set chunks, using 64 bits to represent a set that requires only two bits. The arithmetic is: (floor(32/32) - floor(31/32)) + 1 = (1-0) + 1 = 2. The PACKED set s2 takes two 8-bit set chunks, using 16 bits to represent a set that requires only two bits. The arithmetic is: (floor(16/8) - floor(15/8)) + 1 = (2-1)+1 = 2. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||