private int discardHead(
      ColumnFamily cf,
      int toDiscard,
      ColumnFamily copy,
      Iterator<Column> iter,
      DeletionInfo.InOrderTester tester) {
    ColumnCounter counter = columnCounter();

    List<Column> staticColumns = new ArrayList<>(cfm.staticColumns().size());

    // Discard the first 'toDiscard' live, non-static columns
    while (iter.hasNext()) {
      Column c = iter.next();

      // if it's a static column, don't count it and save it to add to the trimmed results
      ColumnDefinition columnDef = cfm.getColumnDefinitionFromColumnName(c.name());
      if (columnDef != null && columnDef.type == ColumnDefinition.Type.STATIC) {
        staticColumns.add(c);
        continue;
      }

      counter.count(c, tester);

      // once we've discarded the required amount, add the rest
      if (counter.live() > toDiscard) {
        for (Column staticColumn : staticColumns) copy.addColumn(staticColumn);

        copy.addColumn(c);
        while (iter.hasNext()) copy.addColumn(iter.next());
      }
    }
    return Math.min(counter.live(), toDiscard);
  }
  private int discardTail(
      ColumnFamily cf,
      int toDiscard,
      ColumnFamily copy,
      Iterator<Column> 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();

    ColumnCounter counter = columnCounter();
    // Discard the last 'toDiscard' live (so stop adding as sound as we're past 'liveCount -
    // toDiscard')
    while (iter.hasNext()) {
      Column c = iter.next();
      counter.count(c, tester);
      if (counter.live() > liveCount - toDiscard) break;

      copy.addColumn(c);
    }
    return Math.min(liveCount, toDiscard);
  }