FileDocCategorySizeDatePackage
LongHashMap.javaAPI DocGlassfish v2 API4540Fri May 04 22:32:10 BST 2007com.sun.enterprise.util.collection

LongHashMap

public class LongHashMap extends Object

$Source: /cvs/glassfish/appserv-commons/src/java/com/sun/enterprise/util/collection/LongHashMap.java,v $
author
$Author: tcfujii $
version
$Revision: 1.4 $ $Date: 2007/05/05 05:32:10 $

Fields Summary
int
maxBuckets
Bucket[]
buckets
Constructors Summary
public LongHashMap()

	
	  
		this(89);
	
public LongHashMap(int maxBuckets)

		this.maxBuckets = maxBuckets;
		buckets = new Bucket[maxBuckets];
		for (int i=0; i<maxBuckets; i++) {
			buckets[i] = new SortedArrayListBucket();
		}
	
public LongHashMap(Bucket[] buckets)

		this.buckets = buckets;
		this.maxBuckets = buckets.length;
	
Methods Summary
public java.lang.Objectget(long key)

		int index = (int) Math.abs(key % maxBuckets);
		return buckets[index].get(key);
	
public static voidmain(java.lang.String[] args)

		
    	int count = 20;
    	long time=0, t1=0, t2 = 0;
    	String data = "SomeData_";

		LongHashMap map = new LongHashMap();
		for (long i=0; i<count; i+= 5) {
			map.put(i, data + i);
		}
		
		for (long i=1; i<count; i+= 3) {
			map.put(i, data + i);
		}
		
		for (long i=3; i<count; i+= 4) {
			map.put(i, data + i);
		}
		
		for (long i=-23; i<count; i+= 4) {
			map.put(i, data + i);
		}
		
   		for (long j=-25; j<25; j++) {
    		System.out.println("Key: " + j + "; val: " + map.get(j));
    	}
    	t2 = System.currentTimeMillis();
		
	
public voidprint()

		for (int i=0; i<maxBuckets; i++) {
			System.out.println("Bucket[" + i + "]: " + buckets[i]);
		}
	
public voidput(long key, java.lang.Object object)

		int index = (int) Math.abs(key % maxBuckets);
		buckets[index].put(key, object);
	
public java.lang.Objectremove(long key)

		int index = (int) Math.abs(key % maxBuckets);
		return buckets[index].remove(key);