154:
155: /* Return the element in the current position of this array. */
156: return where.mCell.mElems[where.mOffset];
157: }
158:
159: /**
160: * Returns the cached size.
161: *
162: * @return The size of the VList.
163: */
164: @Override
165: public int size() {
166: return mSize;
167: }
168:
169: /**
170: * Sets an element at a particular position to have a particular value.
171: *
172: * @param index
173: * The index at which to write a new value.
174: * @param value
175: * The value to write at that position.
176: * @return The value originally held at that position.
177: */
178: @Override
179: public T set(int index, T value) {
180: VListLocation
181:
182: /* Cache the element in the current position of this array. */
183: T result = where.mCell.mElems[where.mOffset];
184: where.mCell.mElems[where.mOffset] = value;
185: return result;
186: }
187:
188: /**
189: * Removes the element at the specified position from the VList, returning
190: * its value.
191: *
192: * @param index
193: * The index at which the element should be removed.
194: * @return The value held at that position.
195: */
197: public T remove(int index) {
198: VListLocation
199:
200: /* Cache the value that will be removed. */
201: T result = where.mCell.mElems[where.mOffset];
202:
203: /* Invoke the helper to do most of the work. */
204: removeAtPosition(where);
205:
206: return result;
207: }
208:
209: /**
210: * Removes the element at the indicated VListLocation.
211: *
212: * @param where
213: * The location at which the element should be removed.
214: */
215: private void removeAtPosition(VListLocation
216: /*
217: * Scan backward across the blocks after this element, shuffling array
218: * elements down a position and copying the last element of the next
219: * block over to fill in the top.
220: *
221: * The variable shuffleTargetPosition indicates the first element of the
222: * block that should be overwritten during the shuffle-down. In the
223: * first block, this is the position of the element that was
224: * overwritten. In all other blocks, it's the last element.
225: */
226: VListCell
227: for (int shuffleTargetPosition = where.mOffset; curr != null; curr = curr.mPrev, shuffleTargetPosition = (curr == null 0
228: : curr.mElems.length - 1)) {
229: /*
230: * Shuffle down each element in the current array on top of the
231: * target position. Note that in the final block, this may end up
232: * copying a whole bunch of null values down. This is more work than
233: * necessary, but is harmless and doesn't change the asymptotic
234: * runtime (since the last block has size O(n)).
235: */
236: for (int i = shuffleTargetPosition - 1; i >= 0; --i)
237: curr.mE