You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2015/12/29 19:35:19 UTC

svn commit: r1722212 - /uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java

Author: schor
Date: Tue Dec 29 18:35:18 2015
New Revision: 1722212

URL: http://svn.apache.org/viewvc?rev=1722212&view=rev
Log:
[UIMA-4674] add copy method, use common method for nextHigherPowerOf2.

Modified:
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java?rev=1722212&r1=1722211&r2=1722212&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java Tue Dec 29 18:35:18 2015
@@ -108,10 +108,6 @@ public class Int2ObjHashMap<T> {
   private static final boolean TUNE = false;
   
   private final static int[] EMPTY_INT_ARRAY = new int[0];
-
-  static int nextHigherPowerOf2(int i) {
-    return (i < 1) ? 1 : Integer.highestOneBit(i) << ( (Integer.bitCount(i) == 1 ? 0 : 1));
-  }
  
   // this load factor gives, for array doubling strategy:
   //   between 1.5 * 8 bytes (2 words, one for key, one for value) = 12 and
@@ -159,8 +155,24 @@ public class Int2ObjHashMap<T> {
     }
   }
   
+  /** 
+   * for use by copy
+   * @param clazz
+   * @param initialCapacity
+   */
+  private Int2ObjHashMap(Class<T> clazz, int initialCapacity,
+    int sizeWhichTriggersExpansion, int size, int[] keys, T [] values) {
+    this.componentType = clazz;
+    this.initialCapacity = initialCapacity;
+    this.sizeWhichTriggersExpansion = sizeWhichTriggersExpansion;
+    this.histogram = null;
+    this.size = size;
+    this.keys = Arrays.copyOf(keys, keys.length);
+    this.values = Arrays.copyOf(values, values.length);
+  }
+        
   private void newTableKeepSize(int capacity) {
-    capacity = Math.max(16, nextHigherPowerOf2(capacity));
+    capacity = Math.max(16, Misc.nextHigherPowerOf2(capacity));
     keys = new int[capacity];
     values = (T[]) Array.newInstance(componentType, capacity);
     sizeWhichTriggersExpansion = (int)(capacity * loadFactor);
@@ -432,4 +444,8 @@ public class Int2ObjHashMap<T> {
     }
   }
 
+  public Int2ObjHashMap<T> copy() {
+    return new Int2ObjHashMap<>(componentType, initialCapacity, sizeWhichTriggersExpansion, size, keys, values);
+  }
+
 }