25 # ifndef DSGSETALGORITHMS_H 26 # define DSGSETALGORITHMS_H 33 template <
class T>
class SLList;
35 template <
class SetType,
typename Key>
41 return static_cast<SetType *
>(
this);
44 const SetType & const_me()
const 46 return *
static_cast<const SetType *
>(
this);
52 return const_me().search(k) !=
nullptr;
55 bool has(
const Key & k)
const 60 static SetType
join(
const SetType & s1,
const SetType & s2)
64 s2.
for_each([&ret_val] (
const Key & item)
72 SetType
join(
const SetType & s)
const 74 return join(const_me(), s);
77 static SetType
intersect(
const SetType & s1,
const SetType & s2)
79 if (s1.size() < s2.size())
80 return s1.template filter<SetType>([&s2] (
const Key & item)
82 return s2.contains(item);
85 return s2.template filter<SetType>([&s1] (
const Key & item)
87 return s1.contains(item);
96 static SetType
difference(
const SetType & s1,
const SetType & s2)
98 return s1.template filter<SetType>([&s2] (
const Key & item)
100 return not s2.contains(item);
109 template <
class SetType2 = SetType>
113 using Key2 =
typename SetType2::KeyType;
117 s1.
for_each([&ret_val, &s2] (
const Key & item1)
119 s2.for_each([&ret_val, &item1] (
const Key2 & item2)
121 ret_val.
append(std::make_pair(item1, item2));
128 template <
class SetType2 = SetType>
132 return cartesian_product<SetType2>(const_me(), s);
138 # endif // DSGSETALGORITHMS_H T & append(const T &item)
Definition: list.H:265
bool contains(const Key &k) const
Definition: setalgorithms.H:50
Definition: setalgorithms.H:36
static SLList< std::pair< Key, typename SetType2::KeyType > > cartesian_product(const SetType &s1, const SetType2 &s2)
Definition: setalgorithms.H:111
static SetType intersect(const SetType &s1, const SetType &s2)
Definition: setalgorithms.H:77
void for_each(Op &op) const
Definition: containeralgorithms.H:62
static SetType join(const SetType &s1, const SetType &s2)
Definition: setalgorithms.H:60
SetType difference(const SetType &s) const
Definition: setalgorithms.H:104
SetType join(const SetType &s) const
Definition: setalgorithms.H:72
SLList< std::pair< Key, typename SetType2::KeyType > > cartesian_product(const SetType2 &s) const
Definition: setalgorithms.H:130
Definition: italgorithms.H:33
bool has(const Key &k) const
Definition: setalgorithms.H:55
SetType intersect(const SetType &s) const
Definition: setalgorithms.H:91
static SetType difference(const SetType &s1, const SetType &s2)
Definition: setalgorithms.H:96