class SortedReduceIndexAdapter extends AbstractReduceIndexAdapter {
    /** */
    private static final IndexType TYPE = IndexType.createNonUnique(false);

    /** */
    private final SortedReducer delegate;

    /**
     * @param ctx Kernal context.
     * @param tbl Table.
     * @param name Index name,
     * @param cols Columns.
     */
    public SortedReduceIndexAdapter(
        GridKernalContext ctx,
        ReduceTable tbl,
        String name,
        IndexColumn[] cols
    ) {
        super(ctx, tbl, name, TYPE, cols);

        delegate = new SortedReducer(ctx, this::compareRows);
    }

    /** {@inheritDoc} */
    @Override protected SortedReducer reducer() {
        return delegate;
    }

    /** {@inheritDoc} */
    @Override public double getCost(Session ses, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder,
        HashSet<Column> allColumnsSet) {
        return getCostRangeIndex(masks, getRowCountApproximation(), filters, filter, sortOrder, false, allColumnsSet);
    }

    /** {@inheritDoc} */
    @Override public int compareRows(SearchRow rowData, SearchRow compare) {<FILL_FUNCTION_BODY>}
}

        if (rowData == compare)
            return 0;

        for (int i = 0, len = indexColumns.length; i < len; i++) {
            int idx = columnIds[i];
            int sortType = indexColumns[i].sortType;
            Value v1 = rowData.getValue(idx);
            Value v2 = compare.getValue(idx);

            if (v1 == null || v2 == null)
                return 0;

            else if (v1 == v2) continue;

            else if (v1 == ValueNull.INSTANCE || v2 == ValueNull.INSTANCE) {
                if ((sortType & SortOrder.NULLS_FIRST) != 0)
                    return v1 == ValueNull.INSTANCE ? -1 : 1;
                else if ((sortType & SortOrder.NULLS_LAST) != 0)
                    return v1 == ValueNull.INSTANCE ? 1 : -1;
            }

            int comp = table.compareTypeSafe(v1, v2);
            if ((sortType & SortOrder.DESCENDING) != 0)
                comp = -comp;

            if (comp != 0)
                return comp;
        }
        return 0;
    
<methods>public void add(Session, Row) ,public boolean canGetFirstOrLast() ,public void checkRename() ,public void close(Session) ,public final Cursor find(Session, SearchRow, SearchRow) ,public Cursor findFirstOrLast(Session, boolean) ,public long getDiskSpaceUsed() ,public long getRowCount(Session) ,public long getRowCountApproximation() ,public boolean needRebuild() ,public void remove(Session, Row) ,public void remove(Session) ,public void truncate(Session) <variables>