Example usage for org.apache.hadoop.util IndexedSortable swap

List of usage examples for org.apache.hadoop.util IndexedSortable swap

Introduction

In this page you can find the example usage for org.apache.hadoop.util IndexedSortable swap.

Prototype

void swap(int i, int j);

Source Link

Document

Swap items at the given addresses.

Usage

From source file:com.ricemap.spateDB.util.MergeSorter.java

License:Apache License

protected void shift(IndexedSortable s, int src_l, int src_r, int dst_l) {
    int max_step = src_r - src_l;
    while (src_l > dst_l) {
        // Move in steps of (src_r - src_l) but the step should not move beyond
        // the destination dst_l
        if (src_l - dst_l >= max_step) {
            for (int i = 0; i < max_step; i++) {
                s.swap(src_l + i, src_l - max_step + i);
            }/*w  w w.ja va  2  s. c  o  m*/
            src_l -= max_step;
            src_r -= max_step;
        } else {
            int step = src_l - dst_l;
            for (int i = 0; i < step; i++) {
                s.swap(src_l + i, dst_l + i);
            }
            src_l += step;
            dst_l += step;
            max_step = src_r - src_l;
        }
    }
}