Implements a stable sequence with sticky positions.
I.e if you have a position, it gets automatically updated after
insertions and deletions.
addPos
protected int addPos(int ipos,
Object value)
Add a value at a specified Pos.
- addPos in interface GapVector
- the updated Pos, which is after the inserted value..
adjustPositions
protected void adjustPositions(int low,
int high,
int delta)
Add a delta to all positions elements that point into a given range.
Assume x==positions[i], then if (unsigned)x>=(unsigned)low
&& (unsigned)x <= (unsigned)high, then add delta to positions[i].
Using unsigned comparisons allows us to compare ipos values,
which include both the index and the isAfter low-order bit.
allocPositionIndex
protected int allocPositionIndex()
chainFreelist
protected void chainFreelist()
Put all free elements in positions in a chain starting with free.
copyPos
public int copyPos(int ipos)
Make a copy of a position int.
For simple positions returns the argument.
However, if the positions are magic cookies that are actively managed
by the sequence (as opposed to for example a simple index), then making
a copy may need to increment a reference count, or maybe allocate a
new position cookie. In any case, the new position is initialized to
the same offset (and isAfter property) as the original.
- copyPos in interface AbstractSequence
ipos
- the position being copied.
createPos
public int createPos(int index,
boolean isAfter)
Generate a position at a given index.
The result is a position cookie that must be free'd with releasePos.
- createPos in interface GapVector
index
- offset from beginning of desired positionisAfter
- should the position have the isAfter property
fillPosRange
public void fillPosRange(int fromPos,
int toPos,
Object value)
- fillPosRange in interface GapVector
gapReserve
protected void gapReserve(int size)
Make sure gap is at least 'size' elements long.
- gapReserve in interface GapVector
isAfterPos
protected boolean isAfterPos(int ipos)
Tests whether the position has the "isAfter" property.
I.e. if something is inserted at the position, will
the iterator end up being after the new data?
- isAfterPos in interface GapVector
nextIndex
public int nextIndex(int ipos)
Get the offset from the beginning corresponding to a position cookie.
- nextIndex in interface GapVector
nextPos
public int nextPos(int ipos)
Return the next position following the argument.
The new position has the isAfter property.
The argument is implicitly released (as in releasePos).
Returns 0 if we are already at end of file.
- nextPos in interface AbstractSequence
releasePos
public void releasePos(int ipos)
Reclaim any resources used by the given position int.
- releasePos in interface AbstractSequence
ipos
- the Pos being free'd.
removePosRange
protected void removePosRange(int ipos0,
int ipos1)
Remove a range where each end-point is a position in a container.
- removePosRange in interface GapVector
ipos0
- start of range, as a poistionipos1
- end of range
unchainFreelist
protected void unchainFreelist()
Set all free elements in positions to FREE_POSITION.