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 { ...@@ -560,33 +560,19 @@ namespace Dune {
//! random access to blocks, assumes ascending ordering //! random access to blocks, assumes ascending ordering
B& operator[] (size_type i) B& operator[] (size_type i)
{ {
size_type l=0, r=n-1; const size_type* lb = std::lower_bound(j, j+n, i);
while (l<r) if (lb == j+n or *lb != i)
{
size_type q = (l+r)/2;
if (i <= j[q]) r=q;
else l = q+1;
}
if (j[l]!=i) {
DUNE_THROW(ISTLError,"index "<<i<<" not in compressed array"); DUNE_THROW(ISTLError,"index "<<i<<" not in compressed array");
} return p[lb-j];
return p[l];
} }
//! same for read only access, assumes ascending ordering //! same for read only access, assumes ascending ordering
const B& operator[] (size_type i) const const B& operator[] (size_type i) const
{ {
size_type l=0, r=n-1; const size_type* lb = std::lower_bound(j, j+n, i);
while (l<r) if (lb == j+n or *lb != i)
{
size_type q = (l+r)/2;
if (i <= j[q]) r=q;
else l = q+1;
}
if (j[l]!=i) {
DUNE_THROW(ISTLError,"index "<<i<<" not in compressed array"); DUNE_THROW(ISTLError,"index "<<i<<" not in compressed array");
} return p[lb-j];
return p[l];
} }
//! iterator class for sequential access //! 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