Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents index

Integral Keys

Of all the C# types, the so-called integral types  are the simplest to hash into integers. The integral data types are byte, sbyte, short, ushort, int, uint, long, ulong, and char. Since the underlying representation of such data types can be viewed as an integer, the hash function is trivial. A suitable function f for an integral data type is the identity function:

displaymath61741

Program gif completes the definition of the ComparableInt32 wrapper class introduced in Program gif. In this case, the GetHashCode method simply returns the value of the boxed Int32 object. Clearly, the running time of of the GetHashCode method is O(1).

   program10739
Program: ComparableInt32 class GetHashCode method.


next up previous contents index

Bruno Copyright © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.