 Data Structures and Algorithms 
with Object-Oriented Design Patterns in Java
Data Structures and Algorithms 
with Object-Oriented Design Patterns in Java 
  
  
  
  
 Out of all the Java primitive types, the so-called integral types are the simplest to hash into integers. The integral data types are byte, short, int, long, 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:
 
Program  completes the definition of the Int wrapper class
introduced in Program
 completes the definition of the Int wrapper class
introduced in Program  .
In this case, the hashCode method simply returns
the contents of the value field.
Clearly, the running time of of the hashCode method is O(1).
.
In this case, the hashCode method simply returns
the contents of the value field.
Clearly, the running time of of the hashCode method is O(1).
   
Program: Int class hashCode method.
 
  
  
  
  
 
 Copyright © 1998 by Bruno R. Preiss, P.Eng.  All rights reserved.
Copyright © 1998 by Bruno R. Preiss, P.Eng.  All rights reserved.