next up previous
Next: Why is external Up: Key usage within Previous: Properties

Key Comparison

In Databases, two key objects are compared by using their class's " <" and " ==" operators, which are often relatively slow (e.g., a string object might use strcmp), but can represent an external meaning (e.g., lexicographic order).

In an attempt to protect the key ordering on which the underlying red-black tree depends, Databases always own their key objects. KeyDatabases and KeyRefDatabases own the original key objects, and it is the user's responsibility to protect their key fields (i.e., prevent key changes which would affect the outcome of operator " <" or " ==") while they are owned. For Database and RefDatabase objects, the original key objects are cloned and those clones are kept out of user reach to protect against such changes (but, for large class objects, that can be very expensive protection... use with care).

In Maps, two key objects are compared by using " <" and " ==" on their address. Like hashing, this is a fast operation, but, as they would in a hash table, objects in Maps end up in an arbitrary order. Even though Map and RefMap merely point at the original key object, they are protected from structural problems because its address (unlike data fields within it) cannot change.



Jay Hoeflinger
Mon Apr 21 11:52:18 CDT 1997