4 Commits

Author SHA1 Message Date
Kazu Hirata
687fc08e7c
[ADT] Use UnorderedElementsAre in SetOperationsTest.cpp (NFC) (#99596) 2024-07-18 21:29:47 -07:00
Kazu Hirata
c0725804e6
[ADT] Add unit tests for set_subtract (#99561)
This patch adds a couple of unit tests:

- SetSubtractSmallPtrSet exercises the code path involving remove_if,
  added in d772cdd6279de1e578dfdfca7432327a1806c659.  Note that
  SmallPtrSet supports remove_if.

- SetSubtractSmallVector exercises the code path involving
  S1.erase(*SI) and ensures that set_subtract continues to accept S2
  being a vector, which does not have contains.
2024-07-18 18:06:19 -07:00
Nikita Popov
6c4c44b50b
[SetOperations] Support set containers with remove_if (#96613)
The current set_intersect implementation only works for std::set style
sets that have a value-erase method that does not invalidate iterators.
As such, it cannot be used for set containers like SetVector, which only
has iterator-invalidating erase.

Support such set containers by calling the remove_if method instead, if
it exists. The detection code is adopted from how contains() is detected
inside llvm::is_contained().
2024-06-26 09:20:55 +02:00
Teresa Johnson
bf0f94a5cf New SetOperations and unittesting for all SetOperations
New set operations split out of D140908 as suggested, and I have added
unit testing for all set operations.

This adds a set_intersection, which returns the intersection instead of
updating the first set like set_intersect (using a different name
analogous to set_difference vs set_subtract).

Also adds a variant of set_subtract that updates two additional set
arguments to note which members of the subtrahend were removed from
the minuend and which were not.

Differential Revision: https://reviews.llvm.org/D144220
2023-02-17 07:18:32 -08:00