< prev index next >

src/java.base/share/classes/sun/util/PreHashedMap.java

Print this page




 104      * @param shift
 105      *        The value by which hash codes are right-shifted
 106      * @param mask
 107      *        The value with which hash codes are masked after being shifted
 108      */
 109     protected PreHashedMap(int rows, int size, int shift, int mask) {
 110         this.rows = rows;
 111         this.size = size;
 112         this.shift = shift;
 113         this.mask = mask;
 114         this.ht = new Object[rows];
 115         init(ht);
 116     }
 117 
 118     /**
 119      * Initializes this map.
 120      *
 121      * <p> This method must construct the map's hash chains and store them into
 122      * the appropriate elements of the given hash-table row array.
 123      *
 124      * @param rows
 125      *        The row array to be initialized
 126      */
 127     protected abstract void init(Object[] ht);
 128 
 129     @SuppressWarnings("unchecked")
 130     private V toV(Object x) {
 131         return (V)x;
 132     }
 133 
 134     public V get(Object k) {
 135         int h = (k.hashCode() >> shift) & mask;
 136         Object[] a = (Object[])ht[h];
 137         if (a == null) return null;
 138         for (;;) {
 139             if (a[0].equals(k))
 140                 return toV(a[1]);
 141             if (a.length < 3)
 142                 return null;
 143             a = (Object[])a[2];
 144         }
 145     }




 104      * @param shift
 105      *        The value by which hash codes are right-shifted
 106      * @param mask
 107      *        The value with which hash codes are masked after being shifted
 108      */
 109     protected PreHashedMap(int rows, int size, int shift, int mask) {
 110         this.rows = rows;
 111         this.size = size;
 112         this.shift = shift;
 113         this.mask = mask;
 114         this.ht = new Object[rows];
 115         init(ht);
 116     }
 117 
 118     /**
 119      * Initializes this map.
 120      *
 121      * <p> This method must construct the map's hash chains and store them into
 122      * the appropriate elements of the given hash-table row array.
 123      *
 124      * @param ht The row array to be initialized

 125      */
 126     protected abstract void init(Object[] ht);
 127 
 128     @SuppressWarnings("unchecked")
 129     private V toV(Object x) {
 130         return (V)x;
 131     }
 132 
 133     public V get(Object k) {
 134         int h = (k.hashCode() >> shift) & mask;
 135         Object[] a = (Object[])ht[h];
 136         if (a == null) return null;
 137         for (;;) {
 138             if (a[0].equals(k))
 139                 return toV(a[1]);
 140             if (a.length < 3)
 141                 return null;
 142             a = (Object[])a[2];
 143         }
 144     }


< prev index next >