Like at(), but the search is performed in the range [start,end) */
| 157 | |
| 158 | /** Like at(), but the search is performed in the range [start,end) */ |
| 159 | inline Scalar atInRange(Index start, Index end, Index key, const Scalar &defaultValue = Scalar(0)) const |
| 160 | { |
| 161 | if (start>=end) |
| 162 | return defaultValue; |
| 163 | else if (end>start && key==m_indices[end-1]) |
| 164 | return m_values[end-1]; |
| 165 | // ^^ optimization: let's first check if it is the last coefficient |
| 166 | // (very common in high level algorithms) |
| 167 | const Index id = searchLowerIndex(start,end-1,key); |
| 168 | return ((id<end) && (m_indices[id]==key)) ? m_values[id] : defaultValue; |
| 169 | } |
| 170 | |
| 171 | /** \returns a reference to the value at index \a key |
| 172 | * If the value does not exist, then the value \a defaultValue is inserted |