Skip to content
Snippets Groups Projects
Commit 596fc11e authored by Markus Blatt's avatar Markus Blatt
Browse files

operator[] const and operator[] semantics are now the same.

Both do not do any error checking.
Introduced at method that does the same but checks for errors.

[[Imported from SVN: r1067]]
parent dcc0733a
No related branches found
No related tags found
No related merge requests found
...@@ -374,11 +374,23 @@ namespace Dune ...@@ -374,11 +374,23 @@ namespace Dune
* N log(N). * N log(N).
* @param global The globally unique id of the pair. * @param global The globally unique id of the pair.
* @return The pair of indices for the id. * @return The pair of indices for the id.
* @exception NoSuchEntry Thrown if the global id is not known. * @warning If the global index is not in the set a wrong or even a
* null reference might be returned. To be save use the throwing alternative at.
*/ */
inline IndexPair& inline IndexPair&
operator[](const GlobalIndex& global); operator[](const GlobalIndex& global);
/**
* @brief Find the index pair with a specific global id.
*
* This starts a binary search for the entry and therefor has complexity
* N log(N).
* @param global The globally unique id of the pair.
* @return The pair of indices for the id.
* @exception RangeError Thrown if the global id is not known.
*/
inline IndexPair&
at(const GlobalIndex& global);
/** /**
* @brief Find the index pair with a specific global id. * @brief Find the index pair with a specific global id.
...@@ -387,11 +399,24 @@ namespace Dune ...@@ -387,11 +399,24 @@ namespace Dune
* N log(N). * N log(N).
* @param global The globally unique id of the pair. * @param global The globally unique id of the pair.
* @return The pair of indices for the id. * @return The pair of indices for the id.
* @exception NoSuchEntry Thrown if the global id is not known. * @warning If the global index is not in the set a wrong or even a
* null reference might be returned. To be save use the throwing alternative at.
*/ */
inline const IndexPair& inline const IndexPair&
operator[](const GlobalIndex& global) const; operator[](const GlobalIndex& global) const;
/**
* @brief Find the index pair with a specific global id.
*
* This starts a binary search for the entry and therefor has complexity
* N log(N).
* @param global The globally unique id of the pair.
* @return The pair of indices for the id.
* @exception RangeError Thrown if the global id is not known.
*/
inline const IndexPair&
at(const GlobalIndex& global) const;
/** /**
* @brief Get an iterator over the indices positioned at the first index. * @brief Get an iterator over the indices positioned at the first index.
* @return Iterator over the local indices. * @return Iterator over the local indices.
...@@ -526,7 +551,7 @@ namespace Dune ...@@ -526,7 +551,7 @@ namespace Dune
* N log(N). This method is forwarded to the underlying index set. * N log(N). This method is forwarded to the underlying index set.
* @param global The globally unique id of the pair. * @param global The globally unique id of the pair.
* @return The pair of indices for the id. * @return The pair of indices for the id.
* @exception NoSuchEntry Thrown if the global id is not known. * @exception RangeError Thrown if the global id is not known.
*/ */
inline const IndexPair& inline const IndexPair&
operator[](const GlobalIndex& global) const; operator[](const GlobalIndex& global) const;
...@@ -842,7 +867,7 @@ namespace Dune ...@@ -842,7 +867,7 @@ namespace Dune
template<class TG, class TL, int N> template<class TG, class TL, int N>
inline const IndexPair<TG,TL>& inline const IndexPair<TG,TL>&
ParallelIndexSet<TG,TL,N>::operator[](const TG& global) const ParallelIndexSet<TG,TL,N>::at(const TG& global) const
{ {
// perform a binary search // perform a binary search
int low=0, high=localIndices_.size()-1, probe=-1; int low=0, high=localIndices_.size()-1, probe=-1;
...@@ -856,20 +881,35 @@ namespace Dune ...@@ -856,20 +881,35 @@ namespace Dune
low = probe+1; low = probe+1;
} }
#ifdef DUNE_ISTL_WITH_CHECKING
if(probe==-1) if(probe==-1)
DUNE_THROW(RangeError, "No entries!"); DUNE_THROW(RangeError, "No entries!");
if( localIndices_[low].global() != global) if( localIndices_[low].global() != global)
DUNE_THROW(RangeError, "Could not find entry of "<<global); DUNE_THROW(RangeError, "Could not find entry of "<<global);
else else
#endif return localIndices_[low];
return localIndices_[low];
} }
template<class TG, class TL, int N>
inline const IndexPair<TG,TL>&
ParallelIndexSet<TG,TL,N>::operator[](const TG& global) const
{
// perform a binary search
int low=0, high=localIndices_.size()-1, probe=-1;
while(low<high)
{
probe = (high + low) / 2;
if(global <= localIndices_[probe].global())
high = probe;
else
low = probe+1;
}
return localIndices_[low];
}
template<class TG, class TL, int N> template<class TG, class TL, int N>
inline IndexPair<TG,TL>& ParallelIndexSet<TG,TL,N>::operator[](const TG& global) inline IndexPair<TG,TL>& ParallelIndexSet<TG,TL,N>::at(const TG& global)
{ {
// perform a binary search // perform a binary search
int low=0, high=localIndices_.size()-1, probe=-1; int low=0, high=localIndices_.size()-1, probe=-1;
...@@ -883,17 +923,32 @@ namespace Dune ...@@ -883,17 +923,32 @@ namespace Dune
low = probe+1; low = probe+1;
} }
#ifdef DUNE_ISTL_WITH_CHECKING
if(probe==-1) if(probe==-1)
DUNE_THROW(RangeError, "No entries!"); DUNE_THROW(RangeError, "No entries!");
if( localIndices_[low].global() != global) if( localIndices_[low].global() != global)
DUNE_THROW(RangeError, "Could not find entry of "<<global); DUNE_THROW(RangeError, "Could not find entry of "<<global);
else else
#endif return localIndices_[low];
return localIndices_[low];
} }
template<class TG, class TL, int N>
inline IndexPair<TG,TL>& ParallelIndexSet<TG,TL,N>::operator[](const TG& global)
{
// perform a binary search
int low=0, high=localIndices_.size()-1, probe=-1;
while(low<high)
{
probe = (high + low) / 2;
if(localIndices_[probe].global() >= global)
high = probe;
else
low = probe+1;
}
return localIndices_[low];
}
template<class TG, class TL, int N> template<class TG, class TL, int N>
inline typename ParallelIndexSet<TG,TL,N>::iterator inline typename ParallelIndexSet<TG,TL,N>::iterator
ParallelIndexSet<TG,TL,N>::begin() ParallelIndexSet<TG,TL,N>::begin()
......
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