6#include <unordered_set>
8#include "testing/testing.h"
22TEST(set, DefaultConstructor)
29TEST(set, ContainsNotExistant)
48 for (
int i = 0;
i < 100;
i++) {
52 for (
int i = 50;
i < 100;
i++) {
55 for (
int i = 100;
i < 150;
i++) {
60TEST(set, InitializerListConstructor)
114 set2 = std::move(set);
142 for (
int i = 0;
i < 1000;
i++) {
145 for (
int i = 100;
i < 1000;
i++) {
148 for (
int i = 900;
i < 1000;
i++) {
152 for (
int i = 0;
i < 1000;
i++) {
203 for (
int value : set) {
214TEST(set, OftenAddRemoveContained)
217 for (
int i = 0;
i < 100;
i++) {
228 set.
add_new(std::make_unique<int>());
229 auto value1 = std::make_unique<int>();
230 set.
add_new(std::move(value1));
231 set.
add(std::make_unique<int>());
252 EXPECT_FALSE(set.
contains(
"world2"));
271 EXPECT_TRUE(set.
remove(2));
274 EXPECT_FALSE(set.
remove(2));
276 EXPECT_TRUE(set.
remove(5));
290 return a.
value ==
b.value;
294 return a.
value ==
b.value;
359 EXPECT_TRUE(set.
add_as(
"test"));
362 EXPECT_FALSE(set.
add_as(
"qwe"));
368 return (a %
N) == (
b %
N);
379TEST(set, CustomizeHashAndEquality)
403 EXPECT_TRUE(set.add(4));
404 EXPECT_TRUE(set.add(3));
405 EXPECT_TRUE(set.add(11));
406 EXPECT_TRUE(set.add(8));
407 EXPECT_FALSE(set.add(3));
408 EXPECT_FALSE(set.add(4));
409 EXPECT_TRUE(set.remove(4));
410 EXPECT_FALSE(set.remove(7));
411 EXPECT_TRUE(set.add(4));
412 EXPECT_TRUE(set.remove(4));
426 return a.
key ==
b.key;
479 EXPECT_FALSE(set.
contains(
"worlds"));
484TEST(set, SpanConstructorExceptions)
486 std::array<ExceptionThrower, 5>
array = {1, 2, 3, 4, 5};
487 array[3].throw_during_copy =
true;
493TEST(set, CopyConstructorExceptions)
500TEST(set, MoveConstructorExceptions)
503 SetType set = {1, 2, 3};
505 EXPECT_ANY_THROW({ SetType set_moved(std::move(set)); });
507 set.add_multiple({3, 6, 7});
516 EXPECT_ANY_THROW({ set.
add_new(value); });
518 EXPECT_ANY_THROW({ set.
add_new(value); });
527 EXPECT_ANY_THROW({ set.
add(value); });
529 EXPECT_ANY_THROW({ set.
add(value); });
552 EXPECT_FALSE(std::any_of(set.
begin(), set.
end(), [](
int v) { return v == 5; }));
553 EXPECT_TRUE(std::any_of(set.
begin(), set.
end(), [](
int v) { return v == 30; }));
557TEST(set, RemoveDuringIteration)
569 Iter end = set.
end();
570 for (Iter iter =
begin; iter != end; ++iter) {
596TEST(set, RemoveUniquePtrWithRaw)
599 std::unique_ptr<int> a = std::make_unique<int>(5);
600 int *a_ptr = a.get();
601 set.
add(std::move(a));
612 const Set<int> d = {1, 2, 3, 4, 5, 6};
614 const Set<int> f = {10, 11, 12, 13, 14};
639 friend bool operator==(
const KeyWithData &a,
const KeyWithData &
b)
641 return a.key ==
b.key;
651 EXPECT_FALSE(set.
add(KeyWithData{1,
"b"}));
658 const KeyWithData key{2,
"d"};
668template<
typename SetT>
673 for (
int i = 0;
i < amount;
i++) {
682 for (
int value : values) {
689 for (
int value : values) {
690 count += set.contains(value);
695 for (
int value : values) {
696 count += set.remove(value);
701 std::cout <<
"Count: " <<
count <<
"\n";
708template<
typename Key>
class StdUnorderedSetWrapper {
710 using SetType = std::unordered_set<Key, blender::DefaultHash<Key>>;
719 bool is_empty()
const
726 set_.reserve(
size_t(n));
729 void add_new(
const Key &key)
733 void add_new(
Key &&key)
735 set_.insert(std::move(key));
740 return set_.insert(key).second;
744 return set_.insert(std::move(key)).second;
747 void add_multiple(Span<Key> keys)
749 for (
const Key &key : keys) {
756 return set_.find(key) != set_.end();
761 return bool(set_.erase(key));
764 void remove_contained(
const Key &key)
766 return set_.erase(key);
774 typename SetType::iterator
begin()
const
779 typename SetType::iterator end()
const
787 for (
int i = 0;
i < 3;
i++) {
788 benchmark_random_ints<Set<int>>(
"blender::Set ", 100000, 1);
789 benchmark_random_ints<StdUnorderedSetWrapper<int>>(
"std::unordered_set", 100000, 1);
792 for (
int i = 0;
i < 3;
i++) {
794 benchmark_random_ints<Set<int>>(
"blender::Set ", 100000, int(factor));
795 benchmark_random_ints<StdUnorderedSetWrapper<int>>(
"std::unordered_set", 100000, int(factor));
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void int BLI_rng_get_int(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
struct RNG * BLI_rng_new(unsigned int seed)
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1)
#define SCOPED_TIMER(name)
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
unsigned long long int uint64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
const Key & lookup_key_default(const Key &key, const Key &default_value) const
bool remove_as(const ForwardKey &key)
const Key & lookup_key_or_add(const Key &key)
void add_multiple_new(Span< Key > keys)
const Key & lookup_key(const Key &key) const
static bool Disjoint(const Set &a, const Set &b)
bool add_as(ForwardKey &&key)
bool contains_as(const ForwardKey &key) const
void remove_contained(const Key &key)
bool contains(const Key &key) const
static bool Intersects(const Set &a, const Set &b)
void add_multiple(Span< Key > keys)
void add_new(const Key &key)
bool add_overwrite(const Key &key)
int64_t remove_if(Predicate &&predicate)
void remove_contained_as(const ForwardKey &key)
const Key * lookup_key_ptr(const Key &key) const
bool remove(const Key &key)
bool contains(const T &value) const
void append(const T &value)
static void clear(Message &msg)
static void add(blender::Map< std::string, std::string > &messages, Message &msg)
bool contains(const VArray< bool > &varray, const IndexMask &indices_to_check, bool value)
bool remove(void *owner, const StringRef name)
static bool operator==(const Type1 &a, const Type1 &b)
IntrusiveSetSlot< Int, TemplatedKeyInfo< Int, EmptyValue, RemovedValue > > IntegerSetSlot
PythonProbingStrategy<> DefaultProbingStrategy
uint32_t operator()(const tests::Type1 &value) const
uint32_t operator()(const tests::Type2 &value) const
bool operator()(uint a, uint b) const
uint64_t operator()(uint value) const
friend bool operator==(const MyKeyType &a, const MyKeyType &b)