Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
openfoam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
openfoam
Commits
d3c76d8e
Commit
d3c76d8e
authored
5 years ago
by
mattijs
Browse files
Options
Downloads
Patches
Plain Diff
ENH: ListOps: added findIndices with predicate
parent
f1e950ce
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/OpenFOAM/containers/Lists/ListOps/ListOps.H
+10
-0
10 additions, 0 deletions
src/OpenFOAM/containers/Lists/ListOps/ListOps.H
src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C
+50
-1
50 additions, 1 deletion
src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C
with
60 additions
and
1 deletion
src/OpenFOAM/containers/Lists/ListOps/ListOps.H
+
10
−
0
View file @
d3c76d8e
...
...
@@ -655,6 +655,16 @@ bool found
);
//- Linear search to find all occurences of given element.
template
<
class
ListType
,
class
UnaryPredicate
>
labelList
findIndices
(
const
ListType
&
input
,
const
UnaryPredicate
&
pred
,
label
start
=
0
);
//- Set various locations of the list with a specified value.
//
// \param list the list to modify
...
...
This diff is collapsed.
Click to expand it.
src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C
+
50
−
1
View file @
d3c76d8e
...
...
@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-20
19
OpenCFD Ltd.
Copyright (C) 2015-20
20
OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -1170,6 +1170,55 @@ bool Foam::ListOps::found
}
template
<
class
ListType
,
class
UnaryPredicate
>
Foam
::
labelList
Foam
::
ListOps
::
findIndices
(
const
ListType
&
input
,
const
UnaryPredicate
&
pred
,
label
start
)
{
const
label
len
=
input
.
size
();
// Pass 1: count occurrences
label
count
=
0
;
if
(
start
>=
0
)
{
for
(
label
i
=
start
;
i
<
len
;
++
i
)
{
if
(
pred
(
input
[
i
]))
{
if
(
!
count
)
start
=
i
;
// adjust start for second pass
++
count
;
}
}
}
labelList
indices
(
count
);
// Pass 2: fill content
if
(
count
)
{
const
label
total
=
count
;
count
=
0
;
for
(
label
i
=
start
;
i
<
len
;
++
i
)
{
if
(
pred
(
input
[
i
]))
{
indices
[
count
]
=
i
;
if
(
++
count
==
total
)
// early termination
{
break
;
}
}
}
}
return
indices
;
}
template
<
class
T
>
void
Foam
::
ListOps
::
setValue
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment