Beispiel #1
0
        /// <summary>
        /// Return the value at the given index.
        ///
        /// Will throw if the index is out of bounds.  Use <see cref="TryGetValue(long, out Value)"/> for non-throwing gets.
        /// </summary>
        public              Value this[long rowIndex]
        {
            get
            {
                var translatedRowIndex = Parent.TranslateIndex(rowIndex);

                Value value;
                if (!Parent.TryGetValueTranslated(translatedRowIndex, TranslatedColumnIndex, out value))
                {
                    long minLegal;
                    long maxLegal;
                    switch (Parent.Basis)
                    {
                    case BasisType.One:
                        minLegal = 1;
                        maxLegal = Parent.Metadata.NumRows;
                        break;

                    case BasisType.Zero:
                        minLegal = 0;
                        maxLegal = Parent.Metadata.NumRows - 1;
                        break;

                    default: throw new InvalidOperationException($"Unexpected Basis: {Parent.Basis}");
                    }

                    throw new ArgumentOutOfRangeException($"Row index out of range, valid between [{minLegal}, {maxLegal}] found {rowIndex}");
                }

                return(value);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns the row at the given index (in the dataframe's basis).
        ///
        /// Throws if the index is out of range.
        /// </summary>
        public      Row this[long index]
        {
            get
            {
                var translatedIndex = Parent.TranslateIndex(index);

                if (translatedIndex < 0 || translatedIndex >= Parent.Metadata.NumRows)
                {
                    long minLegal;
                    long maxLegal;
                    switch (Parent.Basis)
                    {
                    case BasisType.One:
                        minLegal = 1;
                        maxLegal = Parent.Metadata.NumRows;
                        break;

                    case BasisType.Zero:
                        minLegal = 0;
                        maxLegal = Parent.Metadata.NumRows - 1;
                        break;

                    default: throw new InvalidOperationException($"Unexpected Basis: {Parent.Basis}");
                    }

                    throw new ArgumentOutOfRangeException(nameof(index), $"Row index out of range, valid between [{minLegal}, {maxLegal}] found {index}");
                }

                return(new Row(Parent, translatedIndex));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Return the value at the given index.
        ///
        /// Will throw if the index is out of bounds.  Use <see cref="TryGetValue(long, out Value)"/> for non-throwing gets.
        /// </summary>
        public             Value this[long columnIndex]
        {
            get
            {
                var translatedColumnIndex = Parent.TranslateIndex(columnIndex);

                Value value;
                if (!Parent.TryGetValueTranslated(TranslatedRowIndex, translatedColumnIndex, out value))
                {
                    var rowIndex = Parent.UntranslateIndex(TranslatedRowIndex);

                    long minRowIx, minColIx, maxRowIx, maxColIx;
                    switch (Parent.Basis)
                    {
                    case BasisType.One:
                        minRowIx = 1;
                        maxRowIx = Parent.Metadata.NumRows;
                        minColIx = 1;
                        maxColIx = Parent.Metadata.Columns.Length;
                        break;

                    case BasisType.Zero:
                        minRowIx = 0;
                        maxRowIx = Parent.Metadata.NumRows - 1;
                        minColIx = 0;
                        maxColIx = Parent.Metadata.Columns.Length - 1;
                        break;

                    default: throw new InvalidOperationException($"Unexpected Basis: {Parent.Basis}");
                    }

                    throw new ArgumentOutOfRangeException($"Address out of range, legal range is [{minRowIx}, {minColIx}] - [{maxRowIx}, {maxColIx}], found [{rowIndex}, {columnIndex}]");
                }

                return(value);
            }
        }