Exemple #1
0
        /**
         * Adds a mapping from the specified key to the specified value,
         * replacing the previous mapping from the specified key if there
         * was one.
         */
        public void put(int key, E value)
        {
            int i = ContainerHelpers.binarySearch(mKeys, mSize, key);

            if (i >= 0)
            {
                mValues[i] = value;
            }
            else
            {
                i = ~i;

                if (i < mSize && mValues[i] == DELETED)
                {
                    mKeys[i]   = key;
                    mValues[i] = value;
                    return;
                }

                if (mGarbage && mSize >= mKeys.Length)
                {
                    gc();

                    // Search again because indices may have changed.
                    i = ~ContainerHelpers.binarySearch(mKeys, mSize, key);
                }

                mKeys   = GrowingArrayUtils.insert(mKeys, mSize, i, key);
                mValues = GrowingArrayUtils.insert(mValues, mSize, i, value);
                mSize++;
            }
        }
Exemple #2
0
        /**
         * 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();
            }

            mKeys   = GrowingArrayUtils.append(mKeys, mSize, key);
            mValues = GrowingArrayUtils.append(mValues, mSize, value);
            mSize++;
        }