6#include <unordered_set>
8#include "testing/testing.h"
23TEST(set, DefaultConstructor)
30TEST(set, ContainsNotExistant)
49 for (
int i = 0; i < 100; i++) {
53 for (
int i = 50; i < 100; i++) {
56 for (
int i = 100; i < 150; i++) {
61TEST(set, InitializerListConstructor)
115 set2 = std::move(set);
143 for (
int i = 0; i < 1000; i++) {
146 for (
int i = 100; i < 1000; i++) {
149 for (
int i = 900; i < 1000; i++) {
153 for (
int i = 0; i < 1000; i++) {
154 if (i < 100 || i >= 900) {
204 for (
int value : set) {
215TEST(set, OftenAddRemoveContained)
218 for (
int i = 0; i < 100; i++) {
229 set.
add_new(std::make_unique<int>());
230 auto value1 = std::make_unique<int>();
231 set.
add_new(std::move(value1));
232 set.
add(std::make_unique<int>());
307 return a.
value ==
b.value;
311 return a.
value ==
b.value;
385 return (a %
N) == (
b %
N);
396TEST(set, CustomizeHashAndEquality)
445 return a % 10 ==
b % 10;
449TEST(set, IntrusiveIntKeyCustomEq)
475 return a.
key ==
b.key;
528 EXPECT_EQ(set.lookup_key_or_add_cb({1, 5}, [&]() { return MyKeyType{1, 50}; }).attached_data,
530 EXPECT_EQ(set.lookup_key_or_add_cb({2, 20}, [&]() { return MyKeyType{2, 200}; }).attached_data,
544TEST(set, SpanConstructorExceptions)
546 std::array<ExceptionThrower, 5>
array = {1, 2, 3, 4, 5};
547 array[3].throw_during_copy =
true;
553TEST(set, CopyConstructorExceptions)
560TEST(set, MoveConstructorExceptions)
563 SetType set = {1, 2, 3};
565 EXPECT_ANY_THROW({ SetType set_moved(std::move(set)); });
567 set.add_multiple({3, 6, 7});
576 EXPECT_ANY_THROW({ set.
add_new(value); });
578 EXPECT_ANY_THROW({ set.
add_new(value); });
587 EXPECT_ANY_THROW({ set.
add(value); });
589 EXPECT_ANY_THROW({ set.
add(value); });
617TEST(set, RemoveDuringIteration)
629 Iter end = set.
end();
630 for (Iter iter =
begin; iter != end; ++iter) {
656TEST(set, RemoveUniquePtrWithRaw)
659 std::unique_ptr<int> a = std::make_unique<int>(5);
660 int *a_ptr = a.get();
661 set.
add(std::move(a));
672 const Set<int> d = {1, 2, 3, 4, 5, 6};
674 const Set<int> f = {10, 11, 12, 13, 14};
699 friend bool operator==(
const KeyWithData &a,
const KeyWithData &
b)
701 return a.key ==
b.key;
718 const KeyWithData key{2,
"d"};
728template<
typename SetT>
733 for (
int i = 0; i < amount; i++) {
742 for (
int value : values) {
749 for (
int value : values) {
750 count += set.contains(value);
755 for (
int value : values) {
756 count += set.remove(value);
761 std::cout <<
"Count: " << count <<
"\n";
768template<
typename Key>
class StdUnorderedSetWrapper {
770 using SetType = std::unordered_set<Key, DefaultHash<Key>>;
779 bool is_empty()
const
786 set_.reserve(
size_t(n));
795 set_.insert(std::move(key));
798 bool add(
const Key &key)
800 return set_.insert(key).second;
804 return set_.insert(std::move(key)).second;
807 void add_multiple(Span<Key> keys)
809 for (
const Key &key : keys) {
816 return set_.find(key) != set_.end();
819 bool remove(
const Key &key)
821 return bool(set_.erase(key));
824 void remove_contained(
const Key &key)
826 return set_.erase(key);
834 typename SetType::iterator
begin()
const
839 typename SetType::iterator end()
const
847 for (
int i = 0; i < 3; i++) {
848 benchmark_random_ints<Set<int>>(
"Set ", 100000, 1);
849 benchmark_random_ints<StdUnorderedSetWrapper<int>>(
"std::unordered_set", 100000, 1);
852 for (
int i = 0; i < 3; i++) {
854 benchmark_random_ints<Set<int>>(
"Set ", 100000, int(factor));
855 benchmark_random_ints<StdUnorderedSetWrapper<int>>(
"std::unordered_set", 100000, int(factor));
#define SCOPED_TIMER(name)
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)
const Key & lookup_key_or_add_cb(const Key &key, CreateValueF &&create_value)
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)
#define EXPECT_FALSE(result)
#define EXPECT_GE(result, expect)
#define EXPECT_NE(result, expect)
#define EXPECT_TRUE(result)
#define EXPECT_EQ(result, expect)
ccl_device_inline bool operator==(const float2 a, const float2 b)
bool contains(const VArray< bool > &varray, const IndexMask &indices_to_check, bool value)
void add(Depsgraph &depsgraph, std::function< void()> fn)
int size(const AssetLibraryReference *library_reference)
void add_new(const MultiFunction &fn)
TEST(any_virtual, DefaultConstructor)
static bool operator==(const Type1 &a, const Type1 &b)
unsigned __int64 uint64_t
IntrusiveSetSlot< Int, TemplatedKeyInfo< Int, EmptyValue, RemovedValue > > IntegerSetSlot
ATTR_WARN_UNUSED_RESULT const BMVert * v
struct RNG * BLI_rng_new(unsigned int seed)
BMesh const char void * data
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)
PythonProbingStrategy<> DefaultProbingStrategy
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
uint32_t operator()(const blender::tests::Type1 &value) const
uint32_t operator()(const blender::tests::Type2 &value) const
bool operator()(uint a, uint b) const
uint64_t operator()(uint value) const
bool operator()(const int a, const int b) const
uint64_t operator()(const int key) const
friend bool operator==(const MyKeyType &a, const MyKeyType &b)