@@ -53,7 +53,7 @@ public abstract class Array<T> implements Writable {
5353 public static int ROW_PARALLELIZATION_THRESHOLD = 10000 ;
5454
5555 /** A soft reference to a memorization of this arrays mapping, used in transformEncode */
56- protected SoftReference <Map <T , Integer >> _rcdMapCache = null ;
56+ protected SoftReference <Map <T ,Integer >> _rcdMapCache = null ;
5757
5858 /** The current allocated number of elements in this Array */
5959 protected int _size ;
@@ -73,7 +73,7 @@ protected int newSize() {
7373 *
7474 * @return The cached recode map
7575 */
76- public final SoftReference <Map <T , Integer >> getCache () {
76+ public final SoftReference <Map <T ,Integer >> getCache () {
7777 return _rcdMapCache ;
7878 }
7979
@@ -82,7 +82,7 @@ public final SoftReference<Map<T, Integer>> getCache() {
8282 *
8383 * @param m The element to cache.
8484 */
85- public final void setCache (SoftReference <Map <T , Integer >> m ) {
85+ public final void setCache (SoftReference <Map <T ,Integer >> m ) {
8686 _rcdMapCache = m ;
8787 }
8888
@@ -121,16 +121,16 @@ public synchronized final Map<T, Integer> getRecodeMap(int estimate) {
121121 *
122122 * @param estimate the estimated number of unique values in this array.
123123 * @param pool An executor pool to be used for parallel execution (Note this method does not shutdown the pool)
124- * @param k Parallelization degree allowed
124+ * @param k Parallelization degree allowed
125125 * @return A recode map
126126 * @throws ExecutionException if the parallel execution fails
127127 * @throws InterruptedException if the parallel execution fails
128128 */
129- public synchronized final Map <T , Integer > getRecodeMap (int estimate , ExecutorService pool , int k )
129+ public synchronized final Map <T ,Integer > getRecodeMap (int estimate , ExecutorService pool , int k )
130130 throws InterruptedException , ExecutionException {
131131 // probe cache for existing map
132- Map <T , Integer > map ;
133- SoftReference <Map <T , Integer >> tmp = getCache ();
132+ Map <T ,Integer > map ;
133+ SoftReference <Map <T ,Integer >> tmp = getCache ();
134134 map = (tmp != null ) ? tmp .get () : null ;
135135 if (map != null )
136136 return map ;
@@ -152,17 +152,17 @@ public synchronized final Map<T, Integer> getRecodeMap(int estimate, ExecutorSer
152152 * @param estimate The estimate number of unique values inside this array.
153153 * @param pool The thread pool to use for parallel creation of recode map (can be null). (Note this method does
154154 * not shutdown the pool)
155- * @param k The allowed degree of parallelism
155+ * @param k The allowed degree of parallelism
156156 * @return The recode map created.
157157 * @throws ExecutionException if the parallel execution fails
158158 * @throws InterruptedException if the parallel execution fails
159159 */
160- protected Map < T , Integer > createRecodeMap (int estimate , ExecutorService pool , int k )
160+ protected HashMapToInt < T > createRecodeMap (int estimate , ExecutorService pool , int k )
161161 throws InterruptedException , ExecutionException {
162162 final boolean debug = LOG .isDebugEnabled ();
163163 final Timing t = debug ? new Timing () : null ;
164164 final int s = size ();
165- final Map < T , Integer > ret ;
165+ final HashMapToInt < T > ret ;
166166 if (k <= 1 || pool == null || s < ROW_PARALLELIZATION_THRESHOLD )
167167 ret = createRecodeMap (estimate , 0 , s );
168168 else
@@ -175,21 +175,21 @@ protected Map<T, Integer> createRecodeMap(int estimate, ExecutorService pool, in
175175 return ret ;
176176 }
177177
178- private Map < T , Integer > parallelCreateRecodeMap (int estimate , ExecutorService pool , final int s , int k )
178+ private HashMapToInt < T > parallelCreateRecodeMap (int estimate , ExecutorService pool , final int s , int k )
179179 throws InterruptedException , ExecutionException {
180180
181181 final int blk = Math .max (ROW_PARALLELIZATION_THRESHOLD / 2 , (s + k ) / k );
182- final List <Future <Map < T , Integer >>> tasks = new ArrayList <>();
182+ final List <Future <HashMapToInt < T >>> tasks = new ArrayList <>();
183183 for (int i = blk ; i < s ; i += blk ) { // start at blk for the other threads
184184 final int start = i ;
185185 final int end = Math .min (i + blk , s );
186186 tasks .add (pool .submit (() -> createRecodeMap (estimate , start , end )));
187187 }
188188 // make the initial map thread local allocation.
189- final Map < T , Integer > map = new HashMap < >((int ) (estimate * 1.3 ));
189+ final HashMapToInt < T > map = new HashMapToInt < T >((int ) (estimate * 1.3 ));
190190 createRecodeMap (map , 0 , blk );
191191 for (int i = 0 ; i < tasks .size (); i ++) { // merge with other threads work.
192- final Map < T , Integer > map2 = tasks .get (i ).get ();
192+ final HashMapToInt < T > map2 = tasks .get (i ).get ();
193193 mergeRecodeMaps (map , map2 );
194194 }
195195 return map ;
@@ -216,22 +216,22 @@ protected static <T> void mergeRecodeMaps(Map<T, Integer> target, Map<T, Integer
216216 }
217217 }
218218
219- private Map < T , Integer > createRecodeMap (final int estimate , final int s , final int e ) {
219+ protected HashMapToInt < T > createRecodeMap (final int estimate , final int s , final int e ) {
220220 // * 1.3 because we hashMap has a load factor of 1.75
221- final Map < T , Integer > map = new HashMap <>((int ) (Math .min ((long ) estimate , (e - s )) * 1.3 ));
221+ final HashMapToInt < T > map = new HashMapToInt <>((int ) (Math .min ((long ) estimate , (e - s )) * 1.3 ));
222222 return createRecodeMap (map , s , e );
223223 }
224224
225- private Map < T , Integer > createRecodeMap (Map < T , Integer > map , final int s , final int e ) {
225+ protected HashMapToInt < T > createRecodeMap (HashMapToInt < T > map , final int s , final int e ) {
226226 int id = 1 ;
227227 for (int i = s ; i < e ; i ++)
228228 id = addValRecodeMap (map , id , i );
229229 return map ;
230230 }
231231
232- protected int addValRecodeMap (Map < T , Integer > map , int id , int i ) {
232+ protected int addValRecodeMap (HashMapToInt < T > map , int id , int i ) {
233233 final T val = getInternal (i );
234- if (val != null && map .putIfAbsent (val , id ) == null )
234+ if (val != null && map .putIfAbsentI (val , id ) == - 1 )
235235 id ++;
236236 return id ;
237237 }
@@ -1040,8 +1040,8 @@ public double[] minMax(int l, int u) {
10401040 * @param m The MapToData to set the value part of the Map from
10411041 * @param i The index to set in m
10421042 */
1043- public void setM (Map < T , Integer > map , AMapToData m , int i ) {
1044- m .set (i , map .get (getInternal (i )). intValue ( ) - 1 );
1043+ public void setM (HashMapToInt < T > map , AMapToData m , int i ) {
1044+ m .set (i , map .getI (getInternal (i )) - 1 );
10451045 }
10461046
10471047 /**
@@ -1053,17 +1053,17 @@ public void setM(Map<T, Integer> map, AMapToData m, int i) {
10531053 * @param m The MapToData to set the value part of the Map from
10541054 * @param i The index to set in m
10551055 */
1056- public void setM (Map < T , Integer > map , int si , AMapToData m , int i ) {
1057- try {
1058- final T v = getInternal (i );
1059- if (v != null )
1060- m .set (i , map .get ( v ). intValue ( ) - 1 );
1061- else
1062- m .set (i , si );
1063- }
1064- catch (Exception e ) {
1065- String error = "expected: " + getInternal (i ) + " to be in map: " + map ;
1066- throw new RuntimeException (error , e );
1067- }
1056+ public void setM (HashMapToInt < T > map , int si , AMapToData m , int i ) {
1057+ // try {
1058+ final T v = getInternal (i );
1059+ if (v != null )
1060+ m .set (i , map .getI ( v ) - 1 );
1061+ else
1062+ m .set (i , si );
1063+ // }
1064+ // catch(Exception e) {
1065+ // String error = "expected: " + getInternal(i) + " to be in map: " + map;
1066+ // throw new RuntimeException(error, e);
1067+ // }
10681068 }
10691069}
0 commit comments