Java Code Examples for com.android.internal.util.ArrayUtils#newUnpaddedLongArray()

The following examples show how to use com.android.internal.util.ArrayUtils#newUnpaddedLongArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LongSparseLongArray.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new SparseLongArray containing no mappings that will not
 * require any additional memory allocation to store the specified
 * number of mappings.  If you supply an initial capacity of 0, the
 * sparse array will be initialized with a light-weight representation
 * not requiring any additional array allocations.
 */
public LongSparseLongArray(int initialCapacity) {
    if (initialCapacity == 0) {
        mKeys = EmptyArray.LONG;
        mValues = EmptyArray.LONG;
    } else {
        mKeys = ArrayUtils.newUnpaddedLongArray(initialCapacity);
        mValues = new long[mKeys.length];
    }
    mSize = 0;
}
 
Example 2
Source File: LongSparseArray.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new LongSparseArray containing no mappings that will not
 * require any additional memory allocation to store the specified
 * number of mappings.  If you supply an initial capacity of 0, the
 * sparse array will be initialized with a light-weight representation
 * not requiring any additional array allocations.
 */
public LongSparseArray(int initialCapacity) {
    if (initialCapacity == 0) {
        mKeys = EmptyArray.LONG;
        mValues = EmptyArray.OBJECT;
    } else {
        mKeys = ArrayUtils.newUnpaddedLongArray(initialCapacity);
        mValues = ArrayUtils.newUnpaddedObjectArray(initialCapacity);
    }
    mSize = 0;
}
 
Example 3
Source File: SparseLongArray.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new SparseLongArray containing no mappings that will not
 * require any additional memory allocation to store the specified
 * number of mappings.  If you supply an initial capacity of 0, the
 * sparse array will be initialized with a light-weight representation
 * not requiring any additional array allocations.
 */
public SparseLongArray(int initialCapacity) {
    if (initialCapacity == 0) {
        mKeys = EmptyArray.INT;
        mValues = EmptyArray.LONG;
    } else {
        mValues = ArrayUtils.newUnpaddedLongArray(initialCapacity);
        mKeys = new int[mValues.length];
    }
    mSize = 0;
}
 
Example 4
Source File: LongArray.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an empty LongArray with the specified initial capacity.
 */
public LongArray(int initialCapacity) {
    if (initialCapacity == 0) {
        mValues = EmptyArray.LONG;
    } else {
        mValues = ArrayUtils.newUnpaddedLongArray(initialCapacity);
    }
    mSize = 0;
}
 
Example 5
Source File: LongArray.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures capacity to append at least <code>count</code> values.
 */
private void ensureCapacity(int count) {
    final int currentSize = mSize;
    final int minCapacity = currentSize + count;
    if (minCapacity >= mValues.length) {
        final int targetCap = currentSize + (currentSize < (MIN_CAPACITY_INCREMENT / 2) ?
                MIN_CAPACITY_INCREMENT : currentSize >> 1);
        final int newCapacity = targetCap > minCapacity ? targetCap : minCapacity;
        final long[] newValues = ArrayUtils.newUnpaddedLongArray(newCapacity);
        System.arraycopy(mValues, 0, newValues, 0, currentSize);
        mValues = newValues;
    }
}