示例#1
0
 void IEnumerator.Reset()
 {
     this.count         = 0;
     this.currentRow    = 0;
     this.currentColumn = 0;
     this.current       = default(MatrixEntry <T>);
 }
示例#2
0
        /// <summary>
        /// Compares the current <see cref="T:Academy.Collections.Generic.MatrixEntry`1"/> with another entry by comparing the row index and the column index.
        /// </summary>
        /// <param name="other">A <see cref="T:Academy.Collections.Generic.MatrixEntry`1"/> to compare with this entry.</param>
        /// <returns>
        /// A value that indicates the relative order of the objects being compared.
        /// If the value is less than zero this entry is less than the <paramref name="other"/> parameter.
        /// If value is zero this entry and the <paramref name="other"/> parameter are equals.
        /// And if the value is greater than zero this entry is bigger than <paramref name="other"/>.
        /// </returns>
        public int CompareTo(MatrixEntry <T> other)
        {
            int num  = this._rowIndex.CompareTo(other._rowIndex);
            int num2 = this._colIndex.CompareTo(other._colIndex);

            return(num | num2);
        }
示例#3
0
            public int Compare(MatrixEntry <T> x, MatrixEntry <T> y)
            {
                int num = x.ColumnIndex.CompareTo(y.ColumnIndex);

                if (num == 0)
                {
                    return(x.RowIndex.CompareTo(y.RowIndex));
                }
                return(num);
            }
示例#4
0
 /// <summary>
 /// Advances the enumerator to the next element of the <see cref="T:Academy.Collections.Generic.Matrix`1"/>
 /// </summary>
 /// <returns>true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.</returns>
 public bool MoveNext()
 {
     if (count < matrix.Count)
     {
         current = new MatrixEntry <T>(currentRow, currentColumn, matrix._elements[count]);
         MoveToNextIndex();
         return(true);
     }
     current = default(MatrixEntry <T>);
     return(false);
 }
            public override bool ContainsEntry(int rowIndex, int columnIndex)
            {
                MatrixEntry <T> entry = new MatrixEntry <T>(rowIndex, columnIndex, default(T));

                if (comparer != null)
                {
                    int index = list.BinarySearch(entry, comparer);
                    return(index >= 0);
                }
                return(list.Contains(entry));
            }
示例#6
0
 public bool Equals(MatrixEntry <T> x, MatrixEntry <T> y)
 {
     if (x.Equals(y))
     {
         if (comparer == null)
         {
             return(true);
         }
         return(comparer.Equals(x.Value, y.Value));
     }
     return(false);
 }
            public EntryFixedCollection(IEnumerable <MatrixEntry <T> > collection, MatrixDataOrder order)
                : base(order)
            {
                list = new List <MatrixEntry <T> >(collection);
                if (order != MatrixDataOrder.Merged)
                {
                    IComparer <MatrixEntry <T> > comparer = MatrixEntry <T> .CreateEntryComparer(order);

                    list.Sort(comparer);
                }
                else
                {
                    comparer = null;
                }
            }
示例#8
0
 private void Initialize()
 {
     if (isRowOrder)
     {
         this.i = startIndex.row - 1;
         this.j = (colCount + startIndex.col - 1);
     }
     else
     {
         this.i = (rowCount + startIndex.row - 1);
         this.j = startIndex.col - 1;
     }
     this.comparer = new IndexEqualityComparer();
     this.current  = new MatrixEntry <T>(0, 0, default(T));
     this.SetNext();
 }
示例#9
0
 /// <summary>
 /// Gets the matrix entry for the specified value.
 /// </summary>
 /// <param name="value">The value of the entry.</param>
 /// <param name="entry">When this method returns, the entry for the specified value, if the value is found; otherwise the first entry for a matrix.</param>
 /// <returns>true if the <see cref="T:Academy.Collections.Generic.SparseMatrix`1"/> contains the specified value; otherwise, false.</returns>
 public bool TryGetEntry(T value, out MatrixEntry <T> entry)
 {
     if (IsDefault(value))
     {
         if (dict.Count < LongCount)
         {
             entry = this.First((x) => IsDefault(x.Value));
             return(true);
         }
         entry = default(MatrixEntry <T>);
         return(false);
     }
     if (value == null)
     {
         foreach (var item in dict)
         {
             if (item.Value == null)
             {
                 entry = new MatrixEntry <T>(item.Key.row, item.Key.col, item.Value);
                 return(true);
             }
         }
     }
     else
     {
         foreach (var item in dict)
         {
             if (EqualityComparer <T> .Default.Equals(item.Value, value))
             {
                 entry = new MatrixEntry <T>(item.Key.row, item.Key.col, item.Value);
                 return(true);
             }
         }
     }
     entry = default(MatrixEntry <T>);
     return(false);
 }
示例#10
0
 /// <summary>
 /// Advances the enumerator to the next element of the <see cref="T:Academy.Collections.Generic.SparseMatrix`1"/>
 /// </summary>
 /// <returns>true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.</returns>
 public bool MoveNext()
 {
     if (version != matrix.version)
     {
         Thrower.EnumeratorCorrupted();
     }
     if (MoveToNextIndex())
     {
         Index index = new Index {
             row = i, col = j
         };
         T value = default(T);
         if (comparer.Equals(index, next.Key))
         {
             value = next.Value;
             SetNext();
         }
         current = new MatrixEntry <T>(index.row, index.col, value);
         return(true);
     }
     i = matrix.RowCount + 1;
     j = matrix.ColumnCount + 1;
     return(false);
 }
示例#11
0
        /// <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);
            }
        }
示例#12
0
 /// <summary>
 /// Indicates whether the current entry is equals to the specified entry.
 /// </summary>
 /// <param name="other">The other <see cref="T:Academy.Collections.Generic.MatrixEntry`1"/> object.</param>
 /// <returns>true if the current and the specified entries are equals; otherwise false.</returns>
 public bool Equals(MatrixEntry <T> other)
 {
     return((_rowIndex == other._rowIndex) && (_colIndex == other._colIndex));
 }
示例#13
0
 public int GetHashCode(MatrixEntry <T> obj)
 {
     return(obj.GetHashCode());
 }
示例#14
0
 public int Compare(MatrixEntry <T> x, MatrixEntry <T> y)
 {
     return(0);
 }