public abstract class OffsetGapList<E> extends GapList<E>
The physical raw offset stored in the element needs to be preprocessed
to get the real offset value.
In short the raw offset is either the actual offset in case
the offset gap is above it (greater or equal to offsetGapStart
value)
or, it's the actual offset plus the offset gap length otherwise.
Offsets up to +1GB (Integer.MAX_VALUE / 2
)
can be handled by this class which should be sufficient
for most uses.
It's not +2GB as then the offsets shifted above the offset gap
would overflow and be below zero which would break
the comparisons whether the offset is below offset gap start.
Negative offsets are supported as well with a limit of -2GB.
modCount
Constructor and Description |
---|
OffsetGapList() |
OffsetGapList(int initialCapacity) |
Modifier and Type | Method and Description |
---|---|
protected void |
consistencyCheck()
Internal consistency check.
|
void |
defaultInsertUpdate(int offset,
int length)
Inform the list that there was an insert done into an underlying storage
(e.g.
|
void |
defaultRemoveUpdate(int offset,
int length)
Inform the list that there was a removal done into an underlying storage
(e.g.
|
protected String |
dumpInternals() |
protected int |
elementOffset(E elem)
Get the offset of the element stored in the list.
|
protected int |
elementOffset(int index)
Get the offset of the element stored in the list at the given index.
|
protected abstract int |
elementRawOffset(E elem)
Get the raw offset of the given element currently stored in the list.
|
protected int |
findElementIndex(int offset)
Find an index of the first element at the given offset in the list
by using binary search.
|
protected void |
moveOffsetGap(int offset,
int index)
Move the offset gap so that it's on the requested offset.
|
protected int |
offset2raw(int offset)
Translate regular offset to raw offset.
|
protected int |
offsetGapLength()
Obtain the length of the offset gap.
|
protected int |
offsetGapStart()
Obtain the start of the offset gap.
|
protected int |
raw2Offset(int rawOffset)
Translate raw offset into real offset.
|
protected abstract void |
setElementRawOffset(E elem,
int rawOffset)
Set the raw offset of the given element currently stored in the list.
|
protected void |
updateElementOffsetAdd(E elem)
This method updates element's offset (shifts it above offset gap if necessary)
before adding the element to the list.
|
protected void |
updateElementOffsetRemove(E elem)
This method updates element's offset (shifts it below offset gap if necessary)
before (or after) the element gets removed from the list.
|
protected void |
updateOffsetGapLength(int offsetGapLengthDelta)
Update the offset gap length by the given delta.
|
protected void |
updateOffsetGapStart(int offsetDelta)
Update the offset gap start by the given delta.
|
add, add, addAll, addAll, addAll, addAll, addArray, addArray, addArray, clear, clone, consistencyError, contains, copy, copyElements, copyElements, copyItems, dumpDetails, dumpElements, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, swap, toArray, toArray, toString, trimToSize
equals, hashCode, iterator, listIterator, listIterator, subList
containsAll, remove, removeAll, retainAll
finalize, getClass, notify, notifyAll, wait, wait, wait
addFirst, addLast, containsAll, copyOf, equals, getFirst, getLast, hashCode, iterator, listIterator, listIterator, of, of, of, of, of, of, of, of, of, of, of, of, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, subList
parallelStream, removeIf, stream, toArray
public OffsetGapList()
public OffsetGapList(int initialCapacity)
protected abstract int elementRawOffset(E elem)
elem
- element currently stored in the list.OffsetGapList.raw2Offset(int)
to become the real offset.protected abstract void setElementRawOffset(E elem, int rawOffset)
elem
- element currently stored in the list.rawOffset
- raw offset to be stored in the given element.protected int elementOffset(E elem)
elem
- element stored in the list.protected int elementOffset(int index)
index
- of the element in the list.IndexOutOfBoundsException
- if index >= size() or lower than zeropublic void defaultInsertUpdate(int offset, int length)
Subclasses can build their own way of updating and they are not required to use this method.
offset
- offset at which the insertion occurred.length
- length of the inserted area.public void defaultRemoveUpdate(int offset, int length)
Subclasses can build their own way of updating and they are not required to use this method.
offset
- offset at which the removal occurred.length
- length of the removed area.protected final void moveOffsetGap(int offset, int index)
Note: Improper use of this may logically damage offsets of the elements contained in the list.
offset
- offset to which the offsetGapStart
should be assigned.index
- index of the first element in the list
that has an offset that is greater or equal that the given offset parameter.
OffsetGapList.findElementIndex(int)
.protected final int offsetGapStart()
protected final void updateOffsetGapStart(int offsetDelta)
Note: Improper use of this may logically damage offsets of the elements contained in the list.
protected final int offsetGapLength()
protected final void updateOffsetGapLength(int offsetGapLengthDelta)
Note: Improper use of this may logically damage offsets of the elements contained in the list.
protected final int findElementIndex(int offset)
offset
- offset of the elementprotected void updateElementOffsetAdd(E elem)
protected void updateElementOffsetRemove(E elem)
protected final int raw2Offset(int rawOffset)
rawOffset
- raw offset stored in an element.protected final int offset2raw(int offset)
offset
- regular offset.protected void consistencyCheck()
GapList
consistencyCheck
in class GapList<E>
protected String dumpInternals()
dumpInternals
in class GapList<E>