Commit Graph

13 Commits

Author SHA1 Message Date
Mark Olesen
0fb2c8eb1c STYLE: update applications/tests to use SpanStream/CharStream 2023-10-11 18:11:37 +00:00
Mark Olesen
036abb8ecb BUG: bitSet &= operation does not mask out non-overlapping (#2456)
- the values from non-overlapping blocks were simply ignored,
  which meant that ('111111111111' & '111111') would not mask out
  the unset values at all.

- similar oddities in other operations (|=, ^= etc)
  where the original implementation tried hard to avoid touching the
  sizing at all, but now better resolved as follows:

  - '|=' : Set may grow to accommodate new 'on' bits.
  - '^=' : Set may grow to accommodate new 'on' bits.
  - '-=' : Never changes the original set size.
  - '&=' : Never changes the original set size.
           Non-overlapping elements are considered 'off'.

  These definitions are consistent with HashSet behaviour
  and also ensures that (a & b) == (b & a)

ENH: improve short-circuiting within bitSet ops

- in a few places can optimise by checking for none() instead of
  empty() and avoid unnecessary block operations.

ENH: added bitSet::resize_last() method

- as the name says: resizes to the last bit set.
  A friendlier way of writing `resize(find_last()+1)`
2022-05-10 10:47:01 +02:00
Mark Olesen
8884d58a52 STYLE: fix/correct some tests. Remove useless tests 2021-07-05 14:55:37 +02:00
Mark Olesen
9dc3d2bf40 ENH: additional ITstream constructors
- additional default construct

- add explicit zero-size constructor for ITstream.
  For tagged dispatching, without ambiguity

- elminate mandatory name for parsing versions.
  This makes it easier to use ITstream, IStringStream, UListStream
  interchangeable.
2021-04-26 17:09:39 +02:00
Mark Olesen
a939042e1b ENH: add bitSet::null() and clarify some documentation
- the NullObject singleton can also be cast to a bitSet
  (sufficient size and bit-pattern). Useful for places that
  need to hold a reference on construction
2020-12-08 11:58:28 +01:00
Andrew Heather
fdf8d10ab4 Merge commit 'e9219558d7' into develop-v1906 2019-12-05 11:47:19 +00:00
OpenFOAM bot
e9219558d7 GIT: Header file updates 2019-10-31 14:48:44 +00:00
Mark Olesen
1dde76c8dd ENH: add bitSet::begin(pos) to provide alternative start for indexing 2019-08-07 13:49:48 +02:00
Mark Olesen
a5e5ba3179 ENH: add bitSet-type of methods for boolList
- test(), get(), set(), unset() with behaviour as per bitSet,
  to allow easier swapping out of boolList <-> bitSet.
2018-07-27 15:51:19 +02:00
Mark Olesen
6b6b36afd3 STYLE: revert bitSet/HashSet setMany() to set() method (issue #837)
- improves backward compatibility and more naming consistency.
  Retain setMany(iter1, iter2) to avoid ambiguity with the
  PackedList::set(index, value) method.
2018-05-29 17:38:02 +02:00
Mark Olesen
0ea44eda59 ENH: bitSet::find_first_not() method (issue #751)
- find the position of the first bit off - symmetrical with find_first()
2018-05-02 08:33:49 +02:00
Mark Olesen
10b69fa2b4 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)) ...
2018-04-27 10:43:32 +02:00
Mark Olesen
bac943e6fc ENH: new bitSet class and improved PackedList class (closes #751)
- The bitSet class replaces the old PackedBoolList class.
  The redesign provides better block-wise access and reduced method
  calls. This helps both in cases where the bitSet may be relatively
  sparse, and in cases where advantage of contiguous operations can be
  made. This makes it easier to work with a bitSet as top-level object.

  In addition to the previously available count() method to determine
  if a bitSet is being used, now have simpler queries:

    - all()  - true if all bits in the addressable range are empty
    - any()  - true if any bits are set at all.
    - none() - true if no bits are set.

  These are faster than count() and allow early termination.

  The new test() method tests the value of a single bit position and
  returns a bool without any ambiguity caused by the return type
  (like the get() method), nor the const/non-const access (like
  operator[] has). The name corresponds to what std::bitset uses.

  The new find_first(), find_last(), find_next() methods provide a faster
  means of searching for bits that are set.

  This can be especially useful when using a bitSet to control an
  conditional:

  OLD (with macro):

      forAll(selected, celli)
      {
          if (selected[celli])
          {
              sumVol += mesh_.cellVolumes()[celli];
          }
      }

  NEW (with const_iterator):

      for (const label celli : selected)
      {
          sumVol += mesh_.cellVolumes()[celli];
      }

      or manually

      for
      (
          label celli = selected.find_first();
          celli != -1;
          celli = selected.find_next()
      )
      {
          sumVol += mesh_.cellVolumes()[celli];
      }

- When marking up contiguous parts of a bitset, an interval can be
  represented more efficiently as a labelRange of start/size.
  For example,

  OLD:

      if (isA<processorPolyPatch>(pp))
      {
          forAll(pp, i)
          {
              ignoreFaces.set(i);
          }
      }

  NEW:

      if (isA<processorPolyPatch>(pp))
      {
          ignoreFaces.set(pp.range());
      }
2018-03-07 11:21:48 +01:00