public ColumnCounter countAll(ColumnFamily container) { if (container == null) return this; DeletionInfo.InOrderTester tester = container.inOrderDeletionTester(); for (Cell c : container) count(c, tester); return this; }
private int discardTail(ColumnFamily cf, int toDiscard, ColumnFamily copy, Iterator<Cell> iter, DeletionInfo.InOrderTester tester) { // Redoing the counting like that is not extremely efficient. // This is called only for reversed slices or in the case of a race between // paging and a deletion (pretty unlikely), so this is probably acceptable. int liveCount = columnCounter().countAll(cf).live(); if (liveCount == toDiscard) return toDiscard; ColumnCounter counter = columnCounter(); // Discard the last 'toDiscard' live (so stop adding as sound as we're past 'liveCount - toDiscard') while (iter.hasNext()) { Cell c = iter.next(); counter.count(c, tester); if (counter.live() > liveCount - toDiscard) break; copy.addColumn(c); } return Math.min(liveCount, toDiscard); }
counter.count(c, tester);
public ColumnFamily trim(ColumnFamily cf, int trimTo, long now) { // each cell can increment the count by at most one, so if we have fewer cells than trimTo, we can skip trimming if (cf.getColumnCount() < trimTo) return cf; ColumnCounter counter = columnCounter(cf.getComparator(), now); ColumnFamily trimmedCf = cf.getFactory().create(cf.metadata(), reversed, trimTo); trimmedCf.delete(cf); Collection<Cell> cells = reversed ? cf.getReverseSortedColumns() : cf.getSortedColumns(); DeletionInfo.InOrderTester tester = cf.deletionInfo().inOrderTester(reversed); for (Iterator<Cell> iter = cells.iterator(); iter.hasNext(); ) { Cell cell = iter.next(); counter.count(cell, tester); if (counter.live() > trimTo) { break; } else { trimmedCf.addColumn(cell); } } return trimmedCf; }
continue; columnCounter.count(cell, tester);