Skip to content
Snippets Groups Projects
Commit f5374e8c authored by Oliver Sander's avatar Oliver Sander
Browse files

Code simplification: use std::lower_bound instead of hand-coding binary search

parent f6622144
No related branches found
No related tags found
No related merge requests found
......@@ -560,33 +560,19 @@ namespace Dune {
//! random access to blocks, assumes ascending ordering
B& operator[] (size_type i)
{
size_type l=0, r=n-1;
while (l<r)
{
size_type q = (l+r)/2;
if (i <= j[q]) r=q;
else l = q+1;
}
if (j[l]!=i) {
const size_type* lb = std::lower_bound(j, j+n, i);
if (lb == j+n or *lb != i)
DUNE_THROW(ISTLError,"index "<<i<<" not in compressed array");
}
return p[l];
return p[lb-j];
}
//! same for read only access, assumes ascending ordering
const B& operator[] (size_type i) const
{
size_type l=0, r=n-1;
while (l<r)
{
size_type q = (l+r)/2;
if (i <= j[q]) r=q;
else l = q+1;
}
if (j[l]!=i) {
const size_type* lb = std::lower_bound(j, j+n, i);
if (lb == j+n or *lb != i)
DUNE_THROW(ISTLError,"index "<<i<<" not in compressed array");
}
return p[l];
return p[lb-j];
}
//! iterator class for sequential access
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment