mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: ListOp::inplaceMapValue using a Map<label> for the mapping.
For example, with some HashTable or Map container of models
{ model0 => 1, model1 => 4, model2 => 5, model3 => 12, model4 => 15, }
specify the remapping
Map<label> mapper({{1, 3}, {2, 6}, {3, 12}, {5, 8}});
inplaceMapValue(mapper, models) then yields
{ model0 => 3, model1 => 4, model2 => 8, model3 => 12, model4 => 15, }
--
ENH: extend bitSet::count() to optionally count unset bits instead.
--
ENH: BitOps compatibility methods for boolList.
- These ease coding that uses a boolList instead of bitSet and use
short-circuit logic when possible.
Eg, when 'bitset' and 'bools' contain the same information
bitset.count() <-> BitOps::count(bools)
bitset.all() <-> BitOps::all(bools)
bitset.any() <-> BitOps::any(bools)
bitset.none() <-> BitOps::none(bools)
These methods can then be used directly in parameters or in logic.
Eg,
returnReduce(bitset.any(), orOp<bool>());
returnReduce(BitOps::any(bools), orOp<bool>());
if (BitOps::any(bools)) ...
This commit is contained in:
@ -49,6 +49,7 @@ inline Ostream& report
|
||||
{
|
||||
Info<< "size=" << bitset.size() << "/" << bitset.capacity()
|
||||
<< " count=" << bitset.count()
|
||||
<< " !count=" << bitset.count(false)
|
||||
<< " all:" << bitset.all()
|
||||
<< " any:" << bitset.any()
|
||||
<< " none:" << bitset.none() << nl;
|
||||
@ -63,6 +64,19 @@ inline Ostream& report
|
||||
}
|
||||
|
||||
|
||||
inline Ostream& report(const UList<bool>& bools)
|
||||
{
|
||||
Info<< "size=" << bools.size()
|
||||
<< " count=" << BitOps::count(bools)
|
||||
<< " !count=" << BitOps::count(bools, false)
|
||||
<< " all:" << BitOps::all(bools)
|
||||
<< " any:" << BitOps::any(bools)
|
||||
<< " none:" << BitOps::none(bools) << nl;
|
||||
|
||||
return Info;
|
||||
}
|
||||
|
||||
|
||||
template<class UIntType>
|
||||
std::string toString(UIntType value, char off='.', char on='1')
|
||||
{
|
||||
@ -304,6 +318,35 @@ int main(int argc, char *argv[])
|
||||
<< flatOutput(bools1.toc()) << endl;
|
||||
}
|
||||
|
||||
|
||||
// Check bitSet vs boolList
|
||||
{
|
||||
boolList bools(list4.values());
|
||||
|
||||
Info<< nl << "Check BitOps on boolList" << nl << nl;
|
||||
|
||||
Info<<"bitSet ";
|
||||
report(list4);
|
||||
|
||||
list4.shrink();
|
||||
Info<<"shrunk ";
|
||||
report(list4);
|
||||
|
||||
Info<< nl;
|
||||
|
||||
Info<<"bools ";
|
||||
report(bools);
|
||||
|
||||
bools = false;
|
||||
Info<<"bools (all unset) ";
|
||||
report(bools);
|
||||
|
||||
bools = true;
|
||||
Info<<"bools (all set) ";
|
||||
report(bools);
|
||||
}
|
||||
|
||||
Info<< "\nDone" << nl << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user