1 30 package com.tc.asm.tree.analysis; 31 32 37 class IntMap { 38 39 private int size; 40 41 private Object [] keys; 42 43 private int[] values; 44 45 public IntMap(final int size) { 46 this.size = size; 47 this.keys = new Object [size]; 48 this.values = new int[size]; 49 } 50 51 public int get(final Object key) { 52 int n = size; 53 int h = (key.hashCode() & 0x7FFFFFFF) % n; 54 int i = h; 55 while (keys[i] != key) { 56 i = (i + 1) % n; 57 if (i == h) { 58 throw new RuntimeException ("Cannot find index of " + key); 59 } 60 } 61 return values[i]; 62 } 63 64 public void put(final Object key, final int value) { 65 int n = size; 66 int i = (key.hashCode() & 0x7FFFFFFF) % n; 67 while (keys[i] != null) { 68 i = (i + 1) % n; 69 } 70 keys[i] = key; 71 values[i] = value; 72 } 73 } | Popular Tags |