File sort order

Records in a Sculptor keyed file are sorted in ascending order of the whole key, which consists of all the key fields concatenated. The sort order is determined at binary level by the number and position of bits set in the whole key. The lowest key value has no bits set - the null key. The highest key value has all bits set. The leftmost bit is most significant.

The file indexes are maintained dynamically, and so the records are always sorted correctly.

Alphanumeric fields

Alphanumeric fields are sorted in ASCII order; the lowest printable character is a space and the highest a tilde. The first character in a string is the most significant. Therefore, an alpha field containing numeric data is sorted such that the string “2” is sorted higher than the string “19”.

If an alphanumeric field contains numeric data which is required to be sorted by the numeric value, the numbers must be zero-padded or right-justified with leading spaces. Using the example in the previous paragraph, “02” or ” 2” sort lower than “19”, achieving the desired effect.

Floating point fields

Floating point numbers are stored as mantissa and exponent; this data type is not recommended for use in key fields since the resulting sort order is not meaningful. The recommended method for including floating point data in a key is to use an alphanumeric field containing the ASCII representation of the real number.

Negative integers

Sculptor stores negative integers in two’s complement form, and sorts at the binary level. The sort order of this data type is therefore as follows:

1

Zero (the null key).

2

All the positive values in ascending order.

3

All the negative values in ascending order (most negative lowest).

It can be seen from this that integer fields that may have both positive and negative values are unlikely to be suitable as key fields.


RELATED TOPICS

Keyed files

ODBC sort order