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:
Mark Olesen
2018-04-27 10:43:32 +02:00
parent c0766ce8ea
commit 10b69fa2b4
9 changed files with 367 additions and 66 deletions

View File

@ -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;
}