All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.com.ibm.as400.access.IntegerHashtable Maven / Gradle / Ivy

There is a newer version: 11.1
Show newest version
///////////////////////////////////////////////////////////////////////////////
//                                                                             
// JTOpen (IBM Toolbox for Java - OSS version)                              
//                                                                             
// Filename: IntegerHashtable.java
//                                                                             
// The source code contained herein is licensed under the IBM Public License   
// Version 1.0, which has been approved by the Open Source Initiative.         
// Copyright (C) 1997-2001 International Business Machines Corporation and     
// others. All rights reserved.                                                
//                                                                             
///////////////////////////////////////////////////////////////////////////////

package com.ibm.as400.access;

/**
 * This class represents a hashtable that uses primitive ints for both keys and values.
 * It is much smaller and faster than using a java.util.Hashtable since you do not
 * have to wrap the primitive type in an Integer object. The current hash is hardcoded as 4
 * (to keep the memory usage low) but could conceivably be adjusted in a constructor if needed.
 * A valid key is any non-zero integer that can be used as an array index in Java.
 * A valid value is any integer.
 * This class is appropriately synchronized and can be considered threadsafe.
**/
final class IntegerHashtable implements java.io.Serializable
{
  static final long serialVersionUID = 5L;
  private static final int HASH = 4;
  final int[][] values_ = new int[HASH][];
  final int[][] keys_ = new int[HASH][];

  final int get(int key)
  {
    if (key == 0) return -1;
    int hash = key % HASH;
    synchronized(keys_)
    {
      int[] keyChain = keys_[hash];
      if (keyChain == null) return -1;
      for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy