All files ordering.js

100% Statements 59/59
100% Branches 9/9
80% Functions 8/10
100% Lines 59/59

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 603x 3x 3x 3x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 3x 3x 12x 12x 3x 3x 1514x 1514x 3x 3x 226x 226x 226x 226x 3x 3x 3x 3x 1x 1x 3x 3x 6x 6x 3x 3x 6x 6x 6x 6x 3x 3x 3x  
/**
 *  @abstract
 */
export class Ordering {
  /** @member {number} - leading dimension */
  ld;
 
  constructor(ld) {
    this.ld = ld;
  }
 
  /**
   * @abstract
   * @param {number} row - row accessor
   * @param {number} col - col accessor
   * @returns {number} - address i
   */
  toI(row, col) {}
 
  /**
   * @abstract
   * @param {number} i - address i
   * @returns {[number, number]} - [row, col] accessors
   */
  fromI(i) {}
}
class RowMajor extends Ordering {
  constructor(width) {
    super(width);
  }
 
  toI(row, col) {
    return this.ld * row + col;
  }
 
  fromI(i) {
    const row = Math.floor(i / this.ld);
    const col = i - row * this.ld;
    return [row, col];
  }
}
 
class ColMajor extends Ordering {
  constructor(height) {
    super(height);
  }
 
  toI(row, col) {
    return this.ld * col + row;
  }
 
  fromI(i) {
    const col = Math.floor(i / this.ld);
    const row = i - col * this.ld;
    return [row, col];
  }
}
 
export { ColMajor, RowMajor };