Key and Value Types
There are several restrictions on the key and value types:
In addition to these restrictions, it must be possible to compare keys for
sorting purposes. In other words, if k1 and k2
are two keys,
k1<k2 must be well-defined. Moreover, when <
is applied to two keys, it must be a "strong total order relation".
That is, it must have the following properties:
Notice that we do not require that k1==k2 or k1>k2
be defined because we can infer k1>k2 from
k2<k1 and k1==k2 from !(k1<k2||k2<k1).
k1<k1 must never hold for any key
For any two keys k1 and k2,
either k1<k2, k2<k1, or
k1 and k2 are equal. No more than one of these
conditions may hold for any particular values of k1 and
For any three keys k1, k2,
and k3, if k1<k2 and k2<k3
both hold then k1<k3 must also hold.
The integral types (int, short,
char, and long) and the String
class all have an appropriate definition for <. The floating-point
types are a different matter:
some machines support a special floating-point ``not-a-number''
value (NaN) that is neither less than, greater than, or equal to anything
Using floating-point keys on such a machine invites disaster if a key is ever
NaN. Floating-point values cause no trouble.
Using a Map
Defining Map Classes
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005