From e6d563ee97f19b1e901c02b4ccceca0e270e75b4 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Fri, 11 Nov 2011 11:30:43 +0100 Subject: [PATCH] added method getValue() to template class CRSMatrix --- MathLib/LinAlg/Sparse/CRSMatrix.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/MathLib/LinAlg/Sparse/CRSMatrix.h b/MathLib/LinAlg/Sparse/CRSMatrix.h index 04965cd46d3..65e503ddc2f 100644 --- a/MathLib/LinAlg/Sparse/CRSMatrix.h +++ b/MathLib/LinAlg/Sparse/CRSMatrix.h @@ -125,6 +125,22 @@ public: return 1; } + double getValue(IDX_TYPE row, IDX_TYPE col) + { + assert(0 <= row && row < MatrixBase::_n_rows); + + // linear search - for matrices with many entries per row binary search is much faster + const IDX_TYPE idx_end (_row_ptr[row+1]); + IDX_TYPE j(_row_ptr[row]), k; + + while (j<idx_end && (k=_col_idx[j]) <= col) { + if (k == col) { + return _data[j]; + } + j++; + } + return 0.0; + } /** * This is the constant access operator to a non-zero matrix entry. -- GitLab