public class CircularBuffer : ICloneable { #region フィールド double[] buf; #endregion #region コンストラクタ public CircularBuffer() : this(0) { } /// /// バッファ長を指定して初期化 /// /// バッファ長 public CircularBuffer(int len) { this.buf = new double[len]; } #endregion #region 値の挿入・取得 /// /// n サンプル前の値の取得 /// /// 何サンプル前の値を読み書きするか /// n サンプル前の値 public double this[int n] { get { return this.buf[n]; } set { this.buf[n] = value; } } /// /// 値の挿入 /// /// 挿入したい値 public void Insert(double x) { for (int n = this.buf.Length - 1; n > 0; --n) { this.buf[n] = this.buf[n - 1]; } this.buf[0] = x; } /// /// 要素数 /// public int Count { get { return this.buf.Length; } } #endregion #region ICloneable メンバ public object Clone() { CircularBuffer cb = new CircularBuffer(this.Count); cb.buf = (double[])this.buf.Clone(); return cb; } #endregion }