Skip to content
Snippets Groups Projects
Commit 2a17ac0f authored by mattijs's avatar mattijs
Browse files

ENH: findLower: have user-defined < operator

parent c786a02c
Branches
Tags
No related merge requests found
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -37,6 +37,7 @@ SourceFiles
#define ListOps_H
#include "labelList.H"
#include "ops.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -209,6 +210,18 @@ label findSortedIndex
);
//- Find last element < given value in sorted list and return index,
// return -1 if not found. Binary search.
template<class ListType, class BinaryOp>
label findLower
(
const ListType&,
typename ListType::const_reference,
const label stary,
const BinaryOp& bop
);
//- Find last element < given value in sorted list and return index,
// return -1 if not found. Binary search.
template<class ListType>
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -592,12 +592,13 @@ Foam::label Foam::findSortedIndex
}
template<class ListType>
template<class ListType, class BinaryOp>
Foam::label Foam::findLower
(
const ListType& l,
typename ListType::const_reference t,
const label start
const label start,
const BinaryOp& bop
)
{
if (start >= l.size())
......@@ -612,7 +613,7 @@ Foam::label Foam::findLower
{
label mid = (low + high)/2;
if (l[mid] < t)
if (bop(l[mid], t))
{
low = mid;
}
......@@ -622,13 +623,13 @@ Foam::label Foam::findLower
}
}
if (l[high] < t)
if (bop(l[high], t))
{
return high;
}
else
{
if (l[low] < t)
if (bop(l[low], t))
{
return low;
}
......@@ -640,6 +641,18 @@ Foam::label Foam::findLower
}
template<class ListType>
Foam::label Foam::findLower
(
const ListType& l,
typename ListType::const_reference t,
const label start
)
{
return findLower(l, t, start, lessOp<typename ListType::value_type>());
}
template<class Container, class T, int nRows>
Foam::List<Container> Foam::initList(const T elems[nRows])
{
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -142,6 +142,10 @@ Op(minMod, minMod(x, y))
Op(and, x && y)
Op(or, x || y)
Op(eqEq, x == y)
Op(less, x < y)
Op(lessEq, x <= y)
Op(greater, x > y)
Op(greaterEq, x >= y)
#undef Op
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment