/// <summary> /// Gets or sets the element at the specified indices. /// </summary> /// <param name="rowIndex">The zero-based row index of the element to get or set.</param> /// <param name="columnIndex">The zero-based column index of the element to get or set.</param> public T this[int rowIndex, int columnIndex] { get { if (rowIndex < 0 || rowIndex >= rowDim) { Thrower.ArgumentOutOfRangeException(ArgumentType.rowIndex, Resources.ArgumentOutOfRange_RowIndex); } if (columnIndex < 0 && columnIndex >= colDim) { Thrower.ArgumentOutOfRangeException(ArgumentType.columnIndex, Resources.ArgumentOutOfRange_ColIndex); } return(DirectlyGet(rowIndex, columnIndex)); } set { if (rowIndex < 0 || rowIndex >= rowDim) { Thrower.ArgumentOutOfRangeException(ArgumentType.rowIndex, Resources.ArgumentOutOfRange_RowIndex); } if (columnIndex < 0 && columnIndex >= colDim) { Thrower.ArgumentOutOfRangeException(ArgumentType.columnIndex, Resources.ArgumentOutOfRange_ColIndex); } DirectlySet(rowIndex, columnIndex, value); version++; } }
/// <summary> /// Gets a view of the column at the specified index in the current instance of <see cref="T:Academy.Collections.Generic.SparseMatrix`1"/>. /// </summary> /// <param name="columnIndex">The zero-based index of the column to view.</param> /// <returns>Returns a view of the column at the specified index in the matrix.</returns> public IMatrixVectorView <T> GetColumnViewAt(int columnIndex) { if ((columnIndex < 0) || (columnIndex >= colDim)) { Thrower.ArgumentOutOfRangeException(ArgumentType.rowIndex, Resources.ArgumentOutOfRange_ColIndex); } return(new VectorView(this, columnIndex, false)); }
/// <summary> /// Gets a view of the row at the specified index in the current instance of <see cref="T:Academy.Collections.Generic.SparseMatrix`1"/>. /// </summary> /// <param name="rowIndex">The zero-based index of the row to view.</param> /// <returns>Returns a view of the row at the specified index in the matrix.</returns> public IMatrixVectorView <T> GetRowViewAt(int rowIndex) { if ((rowIndex < 0) || (rowIndex >= rowDim)) { Thrower.ArgumentOutOfRangeException(ArgumentType.rowIndex, Resources.ArgumentOutOfRange_RowIndex); } return(new VectorView(this, rowIndex, true)); }
internal override void InternalAdd(T item) { if (!IsInRange(item)) { Thrower.ArgumentOutOfRangeException(ArgumentType.item, null); } _underlying.InternalAdd(item); _count++; }
private void CheckIndex(int index) { if (isRow) { if ((index < 0) && (index >= matrix.RowCount)) { Thrower.ArgumentOutOfRangeException(ArgumentType.index, Resources.ArgumentOutOfRange_Index); } } }
public override SortedLinkedList <T> GetViewBetween(T lowerValue, T upperValue) { if (_comparer.Compare(_min, lowerValue) > 0) { Thrower.ArgumentOutOfRangeException(ArgumentType.lowerValue, Resources.ArgumentOutOfRange_ViewValue); } if (_comparer.Compare(_max, upperValue) < 0) { Thrower.ArgumentOutOfRangeException(ArgumentType.upperValue, Resources.ArgumentOutOfRange_ViewValue); } return(_underlying.GetViewBetween(lowerValue, upperValue)); }
internal override ReadOnlySortedSet <T> GetSubset(T lowerValue, T upperValue) { if (Count == 0 || _comparer.Compare(_elements[_lowerIndex], lowerValue) > 0) { Thrower.ArgumentOutOfRangeException(ArgumentType.lowerValue, Resources.ArgumentOutOfRange_ViewValue); } if (_comparer.Compare(_elements[_upperIndex], lowerValue) < 0) { Thrower.ArgumentOutOfRangeException(ArgumentType.upperValue, Resources.ArgumentOutOfRange_ViewValue); } return(_underlying.GetViewBetween(lowerValue, upperValue)); }
/// <summary> /// Gets the element at the specified index. /// </summary> /// <param name="index">The zero-based index of the element to get.</param> /// <returns>The element at the specified index.</returns> public T this[int index] { get { int num = index + StartIndex; if (num < 0 || num >= EndIndex) { Thrower.ArgumentOutOfRangeException(ArgumentType.index, string.Empty); } return(this._elements[num]); } }
public static void CopyToCheck <T>(T[] array, int index, int count) { if (array == null) { Thrower.ArgumentNullException(ArgumentType.array); } if (index < 0 || index > array.Length) { Thrower.ArgumentOutOfRangeException(ArgumentType.index, string.Format(Resources.ArgumentOutOfRange_Range_G, new object[] { 0, array.Length - 1 })); } if (array.Length - index < count) { Thrower.ArgumentException(ArgumentType.index, Resources.Argument_ArrayNotLongEnought); } }
/// <summary> /// Initializes a new instance of <see cref="T:Academy.Collections.Generic.MatrixEntry`1"/> structure with specified indices and value. /// </summary> /// <param name="rowIndex">The row index.</param> /// <param name="columnIndex">The column index</param> /// <param name="value">The value associated to the specified indices.</param> public MatrixEntry(int rowIndex, int columnIndex, T value) { if (rowIndex < 0) { Thrower.ArgumentOutOfRangeException(ArgumentType.rowIndex, Resources.ArgumentOutOfRange_RowIndex); } if (columnIndex < 0) { Thrower.ArgumentOutOfRangeException(ArgumentType.columnIndex, Resources.ArgumentOutOfRange_ColIndex); } this._rowIndex = rowIndex; this._colIndex = columnIndex; this._value = value; }
/// <summary> /// Initialize a new instance of the <see cref="T:Academy.Collections.Generic.PriorityQueue`1"/> class that is /// empty and has the specified initial capacity and comparer. /// </summary> /// <param name="capacity">The number of elements that the new <see cref="T:Academy.Collections.Generic.PriorityQueue`1"/> instance can initially store.</param> /// <param name="comparer">The default comparer to use for compare objects.</param> public PriorityQueue(int capacity, IComparer <T> comparer) { if (capacity < MinimumCapacity) { Thrower.ArgumentOutOfRangeException(ArgumentType.capacity, Resources.ArgumentOutOfRange_Negative); } if (capacity == int.MaxValue) { capacity--; } if (comparer == null) { comparer = Comparer <T> .Default; } _elements = new T[capacity + 1]; _comparer = comparer; _currentIndex = 1; _elements[0] = default(T); }
public static void CopyToCheck(Array array, int index, int count) { if (array == null) { Thrower.ArgumentNullException(ArgumentType.array); } if (array.Rank != 1) { Thrower.ArgumentException(ArgumentType.array, Resources.Argument_ArrayRank); } if (array.GetLowerBound(0) != 0) { Thrower.ArgumentException(ArgumentType.array, Resources.Argument_LowerBoundArrayNotZero); } if (index < 0 || index > array.Length) { Thrower.ArgumentOutOfRangeException(ArgumentType.index, string.Format(Resources.ArgumentOutOfRange_Range_G, new object[] { 0, array.Length - 1 })); } if ((array.Length - index) < count) { Thrower.ArgumentException(ArgumentType.empty, Resources.Argument_ArrayNotLongEnought); } }
/// <summary> /// Initializes a new instance of the <see cref="T:Academy.Collections.Generic.SparseMatrix`1"/> class with specified dimensions, data order, /// default value and elements copied from the specified collection and positioned in the indices specified by the respective entries. /// </summary> /// <param name="entries">The collection whose elements are copied to the new matrix.</param> /// <param name="rowCount">The amount of rows of the matrix.</param> /// <param name="columnDimension">The amount of columns of the matrix.</param> /// <param name="defaultValue">The value the matrix will assume as the default value.</param> /// <param name="order">The order the matrix will store elements in memory. 'Default' and 'Merged' values are used as 'Row' value.</param> public SparseMatrix(IEnumerable <MatrixEntry <T> > entries, int rowCount, int columnDimension, T defaultValue, MatrixDataOrder order) { if (order != MatrixDataOrder.Column) { order = MatrixDataOrder.Row; } this.order = order; IComparer <Index> comparer; if (order == MatrixDataOrder.Row) { comparer = new RowFirstIndexComparer(); } else { comparer = new ColumnFirstIndexComparer(); } dict = new SortedDictionary <Index, T>(comparer); MatrixEntry <T> upperEntry = new MatrixEntry <T>(rowCount - 1, columnDimension - 1, default(T)); this.def = defaultValue; this.comparer = new ValueEqualityComparer(); this.rowDim = rowCount; this.colDim = columnDimension; this.count = (long)rowCount * (long)columnDimension; foreach (MatrixEntry <T> entry in entries) { int num = entry.CompareTo(lowerEntry); int num2 = entry.CompareTo(upperEntry); if ((num < 0) || (num2 > 0)) { Thrower.ArgumentOutOfRangeException(ArgumentType.empty, Resources.ArgumentOutOfRange_EntryOutOfBounds); } DirectlySet(entry.RowIndex, entry.ColumnIndex, entry.Value); } }