package nxm.sys.libm;

import nxm.sys.inc.Constants;

/**
   Performs the Fill operation on arrays. <br>
   See {@link Operator} for a description of the available I/O Modes.
   @author  Auto-Generated
   @see     Operator
*/
@SuppressWarnings("cast")
public final class Fill extends Operator implements Constants {

  /** Create a new instance. */
  public Fill() {
    super();
  }

  /** Create a new instance.
      @param flags The processing flags to use.
   */
  public Fill (int flags) {
    super(flags);
  }

  /** Create a new instance.
      @param scale The scale factor to use.
   */
  public Fill (double scale) {
    super(scale);
  }

  /** Create a new instance.
      @param flags The processing flags to use.
      @param scale The scale factor to use.
   */
  public Fill (int flags, double scale) {
    super(flags,scale);
  }

  public final int validate (char type, int n, int mode) {
    switch (mode) {
      case S: return n;
      case C: return n;
      case V: return n;
      default: return NOSUPPORT;
    }
  }

  public final int process (double[][] v, int n, int mode) {
    switch (mode) {
      case S: S(v[0],n, scale); return n;
      case C: C(v[0],n, scale); return n;
      case V: V(v[0],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (double[][] v, int n, int mode, double scale) {
    switch (mode) {
      case S: S(v[0],n, scale); return n;
      case C: C(v[0],n, scale); return n;
      case V: V(v[0],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#S} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(double[][],int,int,double)
   */
  public static final void S (double[] a, int n, double scale) {
    double s=(double)scale;
      for (int i=0; i<n; i++) {
        a[i]=s;
      }
  }

  /** Apply this operator to mode {@link Operator#C} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(double[][],int,int,double)
   */
  public static final void C (double[] a, int n, double scale) {
    double s=(double)scale;
      for (int i=0,j=0; i<n; i++,j+=2) {
        a[j]=s; a[j+1]=s;
      }
  }

  /** Apply this operator to mode {@link Operator#V} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(double[][],int,int,double)
   */
  public static final void V (double[] a, int n, double scale) {
    double s=(double)scale;
      for (int i=0,k=0; i<n; i++,k+=3) {
        a[k]=s; a[k+1]=s; a[k+2]=s;
      }
  }

  public final int process (float[][] v, int n, int mode) {
    switch (mode) {
      case S: S(v[0],n, scale); return n;
      case C: C(v[0],n, scale); return n;
      case V: V(v[0],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (float[][] v, int n, int mode, double scale) {
    switch (mode) {
      case S: S(v[0],n, scale); return n;
      case C: C(v[0],n, scale); return n;
      case V: V(v[0],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#S} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(float[][],int,int,double)
   */
  public static final void S (float[] a, int n, double scale) {
    float s=(float)scale;
      for (int i=0; i<n; i++) {
        a[i]=s;
      }
  }

  /** Apply this operator to mode {@link Operator#C} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(float[][],int,int,double)
   */
  public static final void C (float[] a, int n, double scale) {
    float s=(float)scale;
      for (int i=0,j=0; i<n; i++,j+=2) {
        a[j]=s; a[j+1]=s;
      }
  }

  /** Apply this operator to mode {@link Operator#V} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(float[][],int,int,double)
   */
  public static final void V (float[] a, int n, double scale) {
    float s=(float)scale;
      for (int i=0,k=0; i<n; i++,k+=3) {
        a[k]=s; a[k+1]=s; a[k+2]=s;
      }
  }

  public final int process (int[][] v, int n, int mode) {
    switch (mode) {
      case S: S(v[0],n, scale); return n;
      case C: C(v[0],n, scale); return n;
      case V: V(v[0],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (int[][] v, int n, int mode, double scale) {
    switch (mode) {
      case S: S(v[0],n, scale); return n;
      case C: C(v[0],n, scale); return n;
      case V: V(v[0],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#S} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(int[][],int,int,double)
   */
  public static final void S (int[] a, int n, double scale) {
    int s=(int)scale;
      for (int i=0; i<n; i++) {
        a[i]=s;
      }
  }

  /** Apply this operator to mode {@link Operator#C} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(int[][],int,int,double)
   */
  public static final void C (int[] a, int n, double scale) {
    int s=(int)scale;
      for (int i=0,j=0; i<n; i++,j+=2) {
        a[j]=s; a[j+1]=s;
      }
  }

  /** Apply this operator to mode {@link Operator#V} data.
      @param a     The first  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(int[][],int,int,double)
   */
  public static final void V (int[] a, int n, double scale) {
    int s=(int)scale;
      for (int i=0,k=0; i<n; i++,k+=3) {
        a[k]=s; a[k+1]=s; a[k+2]=s;
      }
  }

  public int getInputs() { return 0; }
  public int getOutputs() { return 1; }
}
