public static int idealObjectArraySize(int need) { return idealByteArraySize(need * 4) / 4; }
/** * Creates a new SparseIntArray containing no mappings that will not * require any additional memory allocation to store the specified * number of mappings. */ public SparseIntArray(int initialCapacity) { initialCapacity = ArrayUtils.idealIntArraySize(initialCapacity); mKeys = new int[initialCapacity]; mValues = new int[initialCapacity]; mSize = 0; }
public static int idealCharArraySize(int need) { return idealByteArraySize(need * 2) / 2; }
/** * Creates a new SparseArray containing no mappings that will not * require any additional memory allocation to store the specified * number of mappings. */ public SparseArray(int initialCapacity) { initialCapacity = ArrayUtils.idealIntArraySize(initialCapacity); mKeys = new int[initialCapacity]; mValues = new Object[initialCapacity]; mSize = 0; }
public static int idealFloatArraySize(int need) { return idealByteArraySize(need * 4) / 4; }
/** * Puts a key/value pair into the array, optimizing for the case where * the key is greater than all existing keys in the array. */ public void append(int key, int value) { if (mSize != 0 && key <= mKeys[mSize - 1]) { put(key, value); return; } int pos = mSize; if (pos >= mKeys.length) { int n = ArrayUtils.idealIntArraySize(pos + 1); int[] nkeys = new int[n]; int[] nvalues = new int[n]; // Log.e("SparseIntArray", "grow " + mKeys.length + " to " + n); System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length); System.arraycopy(mValues, 0, nvalues, 0, mValues.length); mKeys = nkeys; mValues = nvalues; } mKeys[pos] = key; mValues[pos] = value; mSize = pos + 1; }
public static int idealBooleanArraySize(int need) { return idealByteArraySize(need); }
int n = ArrayUtils.idealIntArraySize(mSize + 1);
public static int idealLongArraySize(int need) { return idealByteArraySize(need * 8) / 8; }
/** * Puts a key/value pair into the array, optimizing for the case where * the key is greater than all existing keys in the array. */ public void append(int key, E value) { if (mSize != 0 && key <= mKeys[mSize - 1]) { put(key, value); return; } if (mGarbage && mSize >= mKeys.length) { gc(); } int pos = mSize; if (pos >= mKeys.length) { int n = ArrayUtils.idealIntArraySize(pos + 1); int[] nkeys = new int[n]; Object[] nvalues = new Object[n]; // Log.e("SparseArray", "grow " + mKeys.length + " to " + n); System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length); System.arraycopy(mValues, 0, nvalues, 0, mValues.length); mKeys = nkeys; mValues = nvalues; } mKeys[pos] = key; mValues[pos] = value; mSize = pos + 1; }
public static int idealShortArraySize(int need) { return idealByteArraySize(need * 2) / 2; }
int n = ArrayUtils.idealIntArraySize(mSize + 1);
public static int idealIntArraySize(int need) { return idealByteArraySize(need * 4) / 4; }