numColumns += region[1] - region[0] + 1;
}
}
- cursor.resetCursor(hiddenColumns);
+ cursor = new HiddenColumnsCursor(hiddenColumns);
}
} finally
{
// reset the cursor to just before our insertion point: this saves
// a lot of reprocessing in large alignments
- cursor.resetCursor(hiddenColumns, previndex, prevHiddenCount);
+ cursor = new HiddenColumnsCursor(hiddenColumns, previndex,
+ prevHiddenCount);
// reset the number of columns so they will be recounted
numColumns = 0;
{
hideColumns(r[0], r[1]);
}
- cursor.resetCursor(hiddenColumns);
+ cursor = new HiddenColumnsCursor(hiddenColumns);
numColumns = 0;
} finally
{
}
}
hiddenColumns.clear();
- cursor.resetCursor(hiddenColumns);
+ cursor = new HiddenColumnsCursor(hiddenColumns);
numColumns = 0;
} finally
lastSet = inserts.nextClearBit(firstSet);
hideColumns(firstSet, lastSet - 1);
}
- cursor.resetCursor(hiddenColumns);
+ cursor = new HiddenColumnsCursor(hiddenColumns);
numColumns = 0;
} finally
{
}
hiddenColumns.subList(startindex, endindex + 1).clear();
- cursor.resetCursor(hiddenColumns);
+ cursor = new HiddenColumnsCursor(hiddenColumns);
numColumns = 0;
}
} finally
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.atomic.AtomicReference;
public class HiddenColumnsCursor
{
private List<int[]> hiddenColumns = new ArrayList<>();
- // AtomicReference to hold the current region index and hidden column count
- // Could be done with synchronisation but benchmarking shows this way is 2x
- // faster
- private final AtomicReference<HiddenCursorPosition> cursorPos = new AtomicReference<>(
- new HiddenCursorPosition(0, 0));
+ private HiddenCursorPosition cursorPos = new HiddenCursorPosition(0, 0);
protected HiddenColumnsCursor()
{
}
- /**
- * Reset the cursor with a new hidden columns collection. Calls to resetCursor
- * should be made from within a writeLock in the HiddenColumns class - since
- * changes to the hiddenColumns collection require a writeLock the lock should
- * already exist.
- *
- * @param hiddenCols
- * new hidden columns collection
- */
- protected void resetCursor(List<int[]> hiddenCols)
+ protected HiddenColumnsCursor(List<int[]> hiddenCols)
{
resetCursor(hiddenCols, 0, 0);
}
+ protected HiddenColumnsCursor(List<int[]> hiddenCols, int index,
+ int hiddencount)
+ {
+ resetCursor(hiddenCols, index, hiddencount);
+ }
+
/**
* Reset the cursor with a new hidden columns collection, where we know in
* advance the index and hidden columns count of a particular location.
* @param hiddencount
* hidden columns count to reset to
*/
- protected void resetCursor(List<int[]> hiddenCols, int index,
+ private void resetCursor(List<int[]> hiddenCols, int index,
int hiddencount)
{
hiddenColumns = hiddenCols;
if (!hiddenCols.isEmpty())
{
firstColumn = hiddenColumns.get(0)[0];
- HiddenCursorPosition oldpos = cursorPos.get();
- HiddenCursorPosition newpos = new HiddenCursorPosition(index,
+ cursorPos = new HiddenCursorPosition(index,
hiddencount);
- cursorPos.compareAndSet(oldpos, newpos);
}
}
// nothing changes; otherwise
// we deleted the last region (index=hiddenCols.size()-1)
// or the index was at the end of the alignment (index=hiddenCols.size())
- HiddenCursorPosition oldpos = cursorPos.get();
+ HiddenCursorPosition oldpos = cursorPos; // .get();
int index = oldpos.getRegionIndex();
if (index >= hiddenColumns.size() - 1)
// deleted last region, index is now end of alignment
index = hiddenCols.size();
- HiddenCursorPosition newpos = new HiddenCursorPosition(index,
+ cursorPos = new HiddenCursorPosition(index,
oldpos.getHiddenSoFar());
- cursorPos.compareAndSet(oldpos, newpos);
}
}
hiddenColumns = hiddenCols;
return null;
}
- HiddenCursorPosition oldpos = cursorPos.get();
+ HiddenCursorPosition oldpos = cursorPos;// .get();
int index = oldpos.getRegionIndex();
int hiddenCount = oldpos.getHiddenSoFar();
if (index != oldpos.getRegionIndex()
|| hiddenCount != oldpos.getHiddenSoFar())
{
- HiddenCursorPosition newpos = new HiddenCursorPosition(index,
+ cursorPos = new HiddenCursorPosition(index,
hiddenCount);
- cursorPos.compareAndSet(oldpos, newpos);
- return newpos;
+ return cursorPos;
}
return oldpos;
}
return null;
}
- HiddenCursorPosition oldpos = cursorPos.get();
+ HiddenCursorPosition oldpos = cursorPos;// .get();
int index = oldpos.getRegionIndex();
int hiddenCount = oldpos.getHiddenSoFar();
if (index != oldpos.getRegionIndex()
|| hiddenCount != oldpos.getHiddenSoFar())
{
- HiddenCursorPosition newpos = new HiddenCursorPosition(index,
+ cursorPos = new HiddenCursorPosition(index,
hiddenCount);
- cursorPos.compareAndSet(oldpos, newpos);
- return newpos;
+ return cursorPos;
}
return oldpos;
}
List<int[]> hidden = new ArrayList<>();
hidden.add(new int[] { 53, 76 });
hidden.add(new int[] { 104, 125 });
- cursor.resetCursor(hidden);
+
+ cursor = new HiddenColumnsCursor(hidden);
int regionIndex = cursor.findRegionForColumn(126).getRegionIndex();
assertEquals(2, regionIndex);
assertEquals(0, regionIndex);
hidden.add(new int[] { 138, 155 });
- cursor.resetCursor(hidden);
+
+ cursor = new HiddenColumnsCursor(hidden);
regionIndex = cursor.findRegionForColumn(160).getRegionIndex();
assertEquals(3, regionIndex);
List<int[]> hidden = new ArrayList<>();
hidden.add(new int[] { 53, 76 });
hidden.add(new int[] { 104, 125 });
- cursor.resetCursor(hidden);
+
+ cursor = new HiddenColumnsCursor(hidden);
int offset = cursor.findRegionForVisColumn(80).getHiddenSoFar();
assertEquals(46, offset);