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:
-
k1<k1 must never hold for any key
k1.
-
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
k2.
-
For any three keys k1, k2,
and k3, if k1<k2 and k2<k3
both hold then k1<k3 must also hold.
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).
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
else.
Using floating-point keys on such a machine invites disaster if a key is ever
NaN. Floating-point values cause no trouble.
Next topic:
Using a Map
Previous topic:
Defining Map Classes
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004