/// <summary> /// Default constructor. /// </summary> /// <param name="writer">the underlying writer</param> /// <param name="sum">the sum to use for similar items (or <code>null</code>)</param> /// <param name="comparer">the comparer to use for records</param> /// <param name="outputFormatter">the formatter to use when writing the records (or <code>null</code>)</param> public SumWriter(IRecordWriter <T> writer, ISum <T> sum, IComparer <T> comparer, IFormatter <T> outputFormatter) { _writer = writer; _sum = sum; _comparer = comparer; _outputFormatter = outputFormatter; }
public Calculator(ISum adder, ISubtract subtractor) { _adder = adder; _subtractor = subtractor; this.Id = Guid.NewGuid(); }
public String Statistic(String cmdType, String arg1, String arg2) { ICommand cmd; if (cmdType == "Sum") { ISum sum = SumFactory.GetCommand(arg1, arg2); cmd = new SumCommand(sum); } else if (cmdType == "Average") { IAverage average = AverageFactory.GetCommand(arg1, arg2); cmd = new AverageCommand(average); } else if (cmdType == "Max") { IMax max = MaxFactory.GetCommand(arg1, arg2); cmd = new MaxCommand(max); } else { IMin min = MinFactory.GetCommand(arg1, arg2); cmd = new MinCommand(min); } String res = CommandInvoker.DoCommand(cmd); return(res); }
public TwoDimensionalArray(int rows, int columns, ISum sum) { this.rows = rows; this.columns = columns; Array = FillArray(); Sum = sum; }
/// <summary> /// Finds the sum of two symmetric matrices. /// </summary> /// <exception cref="ArgumentNullException"> /// Thrown if the second matrix is null. /// </exception> /// <exception cref="ArgumentException"> /// Thrown if matrices have different sizes. /// </exception> /// <typeparam name="T">The type of matrices.</typeparam> /// <param name="matrix1">The first matrix.</param> /// <param name="matrix2">The second matrix.</param> /// <param name="iSum">The summing logic.</param> /// <returns>Returns the resulting matrix.</returns> public static SymmetricMatrix <T> Add <T>(this SymmetricMatrix <T> matrix1, SymmetricMatrix <T> matrix2, ISum <T> iSum) { if (matrix2 == null) { throw new ArgumentNullException("The second matrix is null!"); } if (matrix1.Size != matrix2.Size) { throw new ArgumentException("Sizes of matrices are different!"); } int size = matrix1.Size; var result = new SymmetricMatrix <T>(size); for (int i = 0; i < size; i++) { for (int j = 0; j < i + 1; j++) { result[i, j] = iSum.Sum(matrix1[i, j], matrix2[i, j]); result[j, i] = result[i, j]; } } return(result); }
/// <summary> /// Constructor initializes matrix elements and /// way of sum matrix of class type /// </summary> /// <param name="_array">Matrix elements</param> /// <param name="_sum">Way of sum matrix of class type</param> public SquareMatrix(T[,] _array, ISum <T> _sum) { Modification = Listeners.MatrixModification; Validation(_array); Array = _array; sum = _sum; }
public BowlingBoard(IBuild_frames_from_rolls Build_frames_from_rolls, ISum_rolls Sum_rolls, ISum_strikes Sum_strikes, ISum_spares Sum_spares, Join<IEnumerable<int>,IEnumerable<int>,IEnumerable<int>,Tuple<IEnumerable<int>,IEnumerable<int>,IEnumerable<int>>> join, ISum Sum) { this._Process += Build_frames_from_rolls.Process; Build_frames_from_rolls.Result += Sum_rolls.Process; Build_frames_from_rolls.Result += Sum_strikes.Process; Build_frames_from_rolls.Result += Sum_spares.Process; Sum_rolls.Result += join.Input1; Sum_strikes.Result += join.Input2; Sum_spares.Result += join.Input3; join.Output += Sum.Process; Sum.Result += m => this.Result(m); }
public BaseController(ILogger logger, ISession session, IReader reader, ISum sum) { this._logger = logger; STLogger = this._logger.GetSTLogger(); this._session = session; ISession = this._session; this._reader = reader; Reader = this._reader; this._sum = sum; Sum = this._sum; }
/// <summary> /// Extension method which allaws to sum up two matrixes /// </summary> /// <typeparam name="T">type that closes method</typeparam> /// <param name="matrix">matrix whose functions is extended by this method</param> /// <param name="other">matrix which is added to existing</param> /// <param name="sum">the way of addition</param> /// <returns>new matrix which is sum of two matrixes</returns> public static Matrix <T> Sum <T>(this Matrix <T> matrix, Matrix <T> other, ISum <T> sum) { if (ReferenceEquals(other, null)) { throw new ArgumentNullException(nameof(other)); } var visitor = new Addition <T>(other, sum); matrix.Accept(visitor); return(visitor.Result); }
public char GetSumIdentifier(ISum sum) { int idx = sums.FindIndex(i => i.First == sum); if (idx != -1) { return(sums[idx].Second); } else { return('?'); } }
public BaseController(ILogger logger, ISession session, IReader reader, ISum sum, IJsonFile jsonFile) { this._logger = logger; STLogger = this._logger.GetSTLogger(); this._session = session; ISession = this._session; this._reader = reader; Reader = this._reader; this._sum = sum; Sum = this._sum; this._jsonFile = jsonFile; JsonFile = this._jsonFile; }
public char GetSumIdentifier(ISum sum) { int idx = sums.FindIndex(i => i.Item1 == sum); if (idx != -1) { return(sums[idx].Item2); } else { return('?'); } }
/// <summary> /// Adds a sum. /// </summary> /// <param name="sum">The sum.</param> public void AddSum(ISum sum) { for (char c = 'a'; c < 'z'; ++c) { char c1 = c; if (!vars.Contains(c1.ToString()) && sums.FindIndex(i => i.Second == c1) == -1) { sums.Add(new Pair <ISum, char>(sum, c)); vars.Add(c.ToString()); return; } } // todo: make this more civil later on throw new Exception("Out of variables!"); }
/// <summary> /// Finds the sum of two diagonal matrices. /// </summary> /// <exception cref="ArgumentNullException"> /// Thrown if the second matrix is null. /// </exception> /// <exception cref="ArgumentException"> /// Thrown if matrices have different sizes. /// </exception> /// <typeparam name="T">The type of matrices.</typeparam> /// <param name="matrix1">The first matrix.</param> /// <param name="matrix2">The second matrix.</param> /// <param name="iSum">The summing logic.</param> /// <returns>Returns the resulting matrix.</returns> public static DiagonalMatrix <T> Add <T>(this DiagonalMatrix <T> matrix1, DiagonalMatrix <T> matrix2, ISum <T> iSum) { if (matrix2 == null) { throw new ArgumentNullException("The second matrix is null!"); } if (matrix1.Size != matrix2.Size) { throw new ArgumentException("Sizes of matrices are different!"); } int size = matrix1.Size; var result = new DiagonalMatrix <T>(size); for (int i = 0; i < size; i++) { result[i, i] = iSum.Sum(matrix1[i, i], matrix2[i, i]); } return(result); }
public GroupCount(int count, ISum calculator) { _count = count; _calculator = calculator; }
public Sample(ISum sum) { _sum = sum; }
/// <summary> /// Constructor initializes matrix elements and /// way of sum matrix of class type /// </summary> /// <param name="_array">Matrix elements</param> /// <param name="_sum">Way of sum matrix of class type</param> public SymmetricalMatrix(T[,] _array, ISum <T> _sum) : base(_array, _sum) { Validation(_array); }
/// <summary> /// Default constructor. /// </summary> /// <param name="outputFile">The description of the current output file.</param> /// <param name="sum">The sum to use for similar items (or <c>null</c>).</param> /// <param name="comparer">The comparer to use for sorting records.</param> public SumWriter(IOutputFile <T> outputFile, ISum <T> sum, IComparer <T> comparer) { _outputFile = outputFile; _sum = sum; _comparer = comparer; }
/// <summary> /// Constructor initializes matrix elements and /// way of sum matrix of class type /// </summary> /// <param name="_array">Matrix elements</param> /// <param name="_sum">Way of sum matrix of class type</param> public DiagonalMatrix(T[,] _array, ISum <T> _sum) : base(_array, _sum) { Validation(_array); }
public HomeController(ILogger logger, ISession session, IReader reader, ISum sum, IJsonFile jsonFile) : base(logger, session, reader, sum, jsonFile) { }
static void Tests2() { foreach (var warmup in new[] { true, false }) { for (int li = 0; li < 140; li++) { GC.Collect(); GC.WaitForPendingFinalizers(); var uts = new UntypedBase[16]; for (int i = 0; i < 16; i++) { if (i % 2 == 0) { uts[i] = new Typed1(); } else { uts[i] = new Typed2(); } } var its = new ISum[16]; for (int i = 0; i < 16; i++) { if (i % 2 == 0) { its[i] = new Typed1(); } else { its[i] = new Typed2(); } } var dts = new NoVirt[16]; for (int i = 0; i < 16; i++) { if (i % 2 == 0) { dts[i] = new NoVirt(); } else { dts[i] = new NoVirt(); } } Measure($"Interface", warmup, () => { int check = 0; for (int i = 0; i < 1 << 20; i++) { check += its[i % 16].Sum(); } return(check); }); Measure($"Cast", warmup, () => { int check = 0; for (int i = 0; i < 1 << 20; i++) { check += uts[i % 16].CastSum(); } return(check); }); Measure($"Uncast", warmup, () => { int check = 0; for (int i = 0; i < 1 << 20; i++) { check += uts[i % 16].Sum(); } return(check); }); Measure($"Decast", warmup, () => { int check = 0; for (int i = 0; i < 1 << 20; i++) { check += uts[i % 16].Sum(); } return(check); }); Measure($"Devirt", warmup, () => { int check = 0; for (int i = 0; i < 1 << 20; i++) { check += dts[i % 16].Sum(); } return(check); }); } } foreach (var result in results_) { Console.WriteLine( $"Benchmarked avg of {result.Value.Count} samples totalling {result.Value.Average():F3} µs to {result.Key}"); } }
public SumCommand(ISum cmd) { this.cmd = cmd; }
/// <summary> /// Extension method which allaws to sum up two matrixes /// </summary> /// <typeparam name="T">type that closes method</typeparam> /// <param name="matrix">matrix whose functions is extended by this method</param> /// <param name="other">matrix which is added to existing</param> /// <param name="sum">the way of addition</param> /// <returns>new matrix which is sum of two matrixes</returns> public static BaseMatrix <T> Sum <T>(this BaseMatrix <T> matrix, BaseMatrix <T> other, ISum <T> sum) { if (ReferenceEquals(other, null)) { throw new ArgumentNullException(nameof(other)); } var result = new Addition <T>(other, sum); matrix.Accept(result); return(result.Result); }
/// <summary> /// create visitor which adds new operation to matrix /// </summary> /// <param name="other">matrix</param> /// <param name="criterion">criterion of sum of two matrixes</param> public Addition(Matrix <T> other, ISum <T> criterion) { this.other = other; this.criterion = criterion; }
public Loader(SumType sumType) { _sum = GetInstanceOfTypeISum(sumType); }