31#if defined(SetFunctions_RECURSES)
32#error Recursive header files inclusion detected in SetFunctions.h
35#define SetFunctions_RECURSES
37#if !defined SetFunctions_h
44#include "DGtal/base/Common.h"
45#include "DGtal/base/ContainerTraits.h"
52 template <
typename LessThan,
typename T>
62 template <
typename KeyComparator,
typename PairKeyData>
67 bool operator()(
const PairKeyData& t1,
const PairKeyData& t2 )
const
69 return compare( t1.first, t2.first );
75 template <
typename Container,
bool associative,
bool ordered,
bool pair>
97 template <
typename Container>
121 template <
typename Container>
146 template <
typename Container>
168 template <
typename Container>
233 template <
typename Container,
bool associative,
bool ordered>
243 static bool isEqual(
const Container& S1,
const Container& S2 )
246 if ( S1.size() != S2.size() )
return false;
247 typedef typename Container::value_type value_type;
248 typedef std::vector<value_type>
Vector;
253 Vector V1( S1.begin(), S1.end() );
254 Vector V2( S2.begin(), S2.end() );
255 std::sort( V1.begin(), V1.end(), CompAdapter::less( S1 ) );
256 std::sort( V2.begin(), V2.end(), CompAdapter::less( S1 ) );
257 return std::equal( V1.begin(), V1.end(), V2.begin(),
258 CompAdapter::equal_to( S1 ) );
268 static bool isSubset(
const Container& S1,
const Container& S2 )
271 if ( S1.size() > S2.size() )
return false;
272 typedef typename Container::value_type value_type;
273 typedef std::vector<value_type>
Vector;
278 Vector V1( S1.begin(), S1.end() );
279 Vector V2( S2.begin(), S2.end() );
280 std::sort( V1.begin(), V1.end(), CompAdapter::less( S1 ) );
281 std::sort( V2.begin(), V2.end(), CompAdapter::less( S1 ) );
282 return std::includes( V2.begin(), V2.end(), V1.begin(), V1.end(),
283 CompAdapter::less( S1 ) );
294 typedef typename Container::value_type value_type;
295 typedef std::vector<value_type>
Vector;
300 Vector V1( S1.begin(), S1.end() );
301 Vector V2( S2.begin(), S2.end() );
302 std::sort( V1.begin(), V1.end(), CompAdapter::less( S1 ) );
303 std::sort( V2.begin(), V2.end(), CompAdapter::less( S1 ) );
305 std::set_difference( V1.begin(), V1.end(), V2.begin(), V2.end(),
306 std::inserter( S1, S1.end() ), CompAdapter::less( S1 ) );
316 static Container&
assignUnion( Container& S1,
const Container& S2 )
318 typedef typename Container::value_type value_type;
319 typedef std::vector<value_type>
Vector;
324 Vector V1( S1.begin(), S1.end() );
325 Vector V2( S2.begin(), S2.end() );
326 std::sort( V1.begin(), V1.end(), CompAdapter::less( S1 ) );
327 std::sort( V2.begin(), V2.end(), CompAdapter::less( S1 ) );
329 std::set_union( V1.begin(), V1.end(), V2.begin(), V2.end(),
330 std::inserter( S1, S1.end() ), CompAdapter::less( S1 ) );
342 typedef typename Container::value_type value_type;
343 typedef std::vector<value_type>
Vector;
348 Vector V1( S1.begin(), S1.end() );
349 Vector V2( S2.begin(), S2.end() );
350 std::sort( V1.begin(), V1.end(), CompAdapter::less( S1 ) );
351 std::sort( V2.begin(), V2.end(), CompAdapter::less( S1 ) );
353 std::set_intersection( V1.begin(), V1.end(), V2.begin(), V2.end(),
354 std::inserter( S1, S1.end() ),
355 CompAdapter::less( S1 ) );
367 typedef typename Container::value_type value_type;
368 typedef std::vector<value_type>
Vector;
373 Vector V1( S1.begin(), S1.end() );
374 Vector V2( S2.begin(), S2.end() );
375 std::sort( V1.begin(), V1.end(), CompAdapter::less( S1 ) );
376 std::sort( V2.begin(), V2.end(), CompAdapter::less( S1 ) );
378 std::set_symmetric_difference( V1.begin(), V1.end(), V2.begin(), V2.end(),
379 std::inserter( S1, S1.end() ),
380 CompAdapter::less( S1 ) );
391 template <
typename Container>
402 static bool isEqual(
const Container& S1,
const Container& S2 )
409 if ( S1.size() != S2.size() )
return false;
411 for (
typename Container::const_iterator it = S1.begin(),
412 itE = S1.end(); it != itE; ++it )
413 if ( S2.find( CompAdapter::key( *it ) ) == S2.end() )
return false;
424 static bool isSubset(
const Container& S1,
const Container& S2 )
431 if ( S1.size() > S2.size() )
return false;
432 for (
typename Container::const_iterator it = S1.begin(),
433 itE = S1.end(); it != itE; ++it )
434 if ( S2.find( CompAdapter::key( *it ) ) == S2.end() )
return false;
450 for (
typename Container::const_iterator it = S2.begin(),
451 itE = S2.end(); it != itE; ++it )
452 S1.erase( CompAdapter::key( *it ) );
462 static Container&
assignUnion( Container& S1,
const Container& S2 )
464 typename Container::iterator itS1 = S1.end();
465 for (
typename Container::const_iterator it = S2.begin(),
466 itE = S2.end(); it != itE; ++it )
467 itS1 = S1.insert( itS1, *it );
483 for (
typename Container::iterator it = S1.begin(),
484 itE = S1.end(); it != itE; )
486 typename Container::iterator itNext = it; ++itNext;
487 if ( S2.find( CompAdapter::key( *it ) ) == S2.end() )
488 S1.erase( CompAdapter::key( *it ) );
513 template <
typename Container>
524 static bool isEqual(
const Container& S1,
const Container& S2 )
527 if ( S1.size() != S2.size() )
return false;
535 return std::equal( S1.begin(), S1.end(), S2.begin(),
536 CompAdapter::equal_to( S1 ) );
547 static bool isSubset(
const Container& S1,
const Container& S2 )
550 if ( S1.size() > S2.size() )
return false;
555 return std::includes( S2.begin(), S2.end(),
556 S1.begin(), S1.end(), CompAdapter::less( S1 ) );
574 std::set_difference( S.begin(), S.end(), S2.begin(), S2.end(),
575 std::inserter( S1, S1.end() ),
576 CompAdapter::less( S1 ) );
586 static Container&
assignUnion( Container& S1,
const Container& S2 )
594 std::set_union( S.begin(), S.end(), S2.begin(), S2.end(),
595 std::inserter( S1, S1.end() ),
596 CompAdapter::less( S1 ) );
614 std::set_intersection( S.begin(), S.end(), S2.begin(), S2.end(),
615 std::inserter( S1, S1.end() ),
616 CompAdapter::less( S1 ) );
634 std::set_symmetric_difference( S.begin(), S.end(), S2.begin(), S2.end(),
635 std::inserter( S1, S1.end() ),
636 CompAdapter::less( S1 ) );
645 template <
typename Container >
655 static bool isEqual(
const Container& S1,
const Container& S2 )
661 if ( S1.size() != S2.size() )
return false;
662 return std::equal( S1.begin(), S1.end(), S2.begin(),
663 CompAdapter::equal_to( S1 ) );
674 static bool isSubset(
const Container& S1,
const Container& S2 )
680 if ( S1.size() > S2.size() )
return false;
681 return std::includes( S2.begin(), S2.end(), S1.begin(), S1.end(),
682 CompAdapter::less( S1 ) );
698 std::set_difference( S.begin(), S.end(), S2.begin(), S2.end(),
699 std::inserter( S1, S1.end() ),
700 CompAdapter::less( S1 ) );
710 static Container&
assignUnion( Container& S1,
const Container& S2 )
717 std::set_union( S.begin(), S.end(), S2.begin(), S2.end(),
718 std::inserter( S1, S1.end() ),
719 CompAdapter::less( S1 ) );
736 std::set_intersection( S.begin(), S.end(), S2.begin(), S2.end(),
737 std::inserter( S1, S1.end() ),
738 CompAdapter::less( S1 ) );
755 std::set_symmetric_difference( S.begin(), S.end(), S2.begin(), S2.end(),
756 std::inserter( S1, S1.end() ),
757 CompAdapter::less( S1 ) );
768 namespace functions {
788 template <
typename Container,
bool ordered>
789 bool isEqual(
const Container& S1,
const Container& S2 )
792 BOOST_STATIC_CONSTANT
794 BOOST_STATIC_CONSTANT
795 (
bool, isOrdered = ordered
814 template <
typename Container>
815 bool isEqual(
const Container& S1,
const Container& S2 )
818 BOOST_STATIC_CONSTANT
820 BOOST_STATIC_CONSTANT
844 template <
typename Container,
bool ordered>
845 bool isSubset(
const Container& S1,
const Container& S2 )
848 BOOST_STATIC_CONSTANT
850 BOOST_STATIC_CONSTANT
851 (
bool, isOrdered = ordered
868 template <
typename Container>
869 bool isSubset(
const Container& S1,
const Container& S2 )
872 BOOST_STATIC_CONSTANT
874 BOOST_STATIC_CONSTANT
895 template <
typename Container,
bool ordered>
899 BOOST_STATIC_CONSTANT
901 BOOST_STATIC_CONSTANT
902 (
bool, isOrdered = ordered
917 template <
typename Container>
921 BOOST_STATIC_CONSTANT
923 BOOST_STATIC_CONSTANT
945 template <
typename Container,
bool ordered>
964 template <
typename Container>
989 template <
typename Container,
bool ordered>
993 BOOST_STATIC_CONSTANT
995 BOOST_STATIC_CONSTANT
996 (
bool, isOrdered = ordered
1011 template <
typename Container>
1015 BOOST_STATIC_CONSTANT
1017 BOOST_STATIC_CONSTANT
1038 template <
typename Container,
bool ordered>
1039 Container
makeUnion(
const Container& S1,
const Container& S2 )
1056 template <
typename Container>
1057 Container
makeUnion(
const Container& S1,
const Container& S2 )
1081 template <
typename Container,
bool ordered>
1085 BOOST_STATIC_CONSTANT
1087 BOOST_STATIC_CONSTANT
1088 (
bool, isOrdered = ordered
1103 template <
typename Container>
1107 BOOST_STATIC_CONSTANT
1109 BOOST_STATIC_CONSTANT
1130 template <
typename Container,
bool ordered>
1148 template <
typename Container>
1175 template <
typename Container,
bool ordered>
1179 BOOST_STATIC_CONSTANT
1181 BOOST_STATIC_CONSTANT
1182 (
bool, isOrdered = ordered
1197 template <
typename Container>
1201 BOOST_STATIC_CONSTANT
1203 BOOST_STATIC_CONSTANT
1224 template <
typename Container,
bool ordered>
1242 template <
typename Container>
1271 template <
typename Container>
1272 inline Container&
operator-=( Container& S1,
const Container& S2 )
1287 template <
typename Container>
1288 inline Container
operator-(
const Container& S1,
const Container& S2 )
1302 template <
typename Container>
1303 inline Container
operator|(
const Container& S1,
const Container& S2 )
1316 template <
typename Container>
1317 inline Container&
operator|=( Container& S1,
const Container& S2 )
1331 template <
typename Container>
1332 inline Container
operator&(
const Container& S1,
const Container& S2 )
1345 template <
typename Container>
1346 inline Container&
operator&=( Container& S1,
const Container& S2 )
1361 template <
typename Container>
1362 inline Container
operator^(
const Container& S1,
const Container& S2 )
1377 template <
typename Container>
1378 inline Container&
operator^=( Container& S1,
const Container& S2 )
1393#include "DGtal/base/SetFunctions.ih"
1400#undef SetFunctions_RECURSES
DigitalPlane::Point Vector
Container & operator-=(Container &S1, const Container &S2)
Container operator-(const Container &S1, const Container &S2)
Container & operator^=(Container &S1, const Container &S2)
Container operator^(const Container &S1, const Container &S2)
Container operator&(const Container &S1, const Container &S2)
Container & operator&=(Container &S1, const Container &S2)
Container & operator|=(Container &S1, const Container &S2)
Container operator|(const Container &S1, const Container &S2)
Container makeSymmetricDifference(const Container &S1, const Container &S2)
Container & assignUnion(Container &S1, const Container &S2)
bool isEqual(const Container &S1, const Container &S2)
Container & assignIntersection(Container &S1, const Container &S2)
Container makeIntersection(const Container &S1, const Container &S2)
Container & assignDifference(Container &S1, const Container &S2)
Container & assignSymmetricDifference(Container &S1, const Container &S2)
bool isSubset(const Container &S1, const Container &S2)
Container makeDifference(const Container &S1, const Container &S2)
Container makeUnion(const Container &S1, const Container &S2)
DGtal is the top-level namespace which contains all DGtal functions and types.
static LessThanPredicate less(const Container &)
Container::key_type key_type
std::equal_to< key_type > EqualPredicate
static EqualPredicate equal_to(const Container &)
static const key_type & key(const value_type &value)
Container::value_type value_type
std::less< key_type > LessThanPredicate
Container::value_type value_type
Container::key_type key_type
static LessThanPredicate less(const Container &)
KeyComparatorForPairKeyData< std::less< key_type >, value_type > LessThanPredicate
static EqualPredicate equal_to(const Container &)
KeyComparatorForPairKeyData< std::equal_to< key_type >, value_type > EqualPredicate
static const key_type & key(const value_type &value)
Container::key_compare key_compare
Container::key_type key_type
EqualPredicateFromLessThanComparator< LessThanPredicate, value_type > EqualPredicate
key_compare LessThanPredicate
static const key_type & key(const value_type &value)
static LessThanPredicate less(const Container &C)
static EqualPredicate equal_to(const Container &C)
Container::value_type value_type
static LessThanPredicate less(const Container &C)
Container::key_type key_type
Container::key_compare key_compare
KeyComparatorForPairKeyData< key_compare, value_type > LessThanPredicate
static const key_type & key(const value_type &value)
EqualPredicateFromLessThanComparator< LessThanPredicate, value_type > EqualPredicate
static EqualPredicate equal_to(const Container &C)
Container::value_type value_type
Container::value_type value_type
static EqualPredicate equal_to(const Container &)
static LessThanPredicate less(const Container &)
std::less< value_type > LessThanPredicate
static const value_type & key(const value_type &value)
std::equal_to< value_type > EqualPredicate
EqualPredicateFromLessThanComparator(LessThan aCompare)
bool operator()(const T &t1, const T &t2) const
KeyComparatorForPairKeyData(KeyComparator aCompare)
bool operator()(const PairKeyData &t1, const PairKeyData &t2) const
static bool isSubset(const Container &S1, const Container &S2)
static Container & assignSymmetricDifference(Container &S1, const Container &S2)
static Container & assignDifference(Container &S1, const Container &S2)
static Container & assignIntersection(Container &S1, const Container &S2)
static Container & assignUnion(Container &S1, const Container &S2)
static bool isEqual(const Container &S1, const Container &S2)
static bool isEqual(const Container &S1, const Container &S2)
static Container & assignSymmetricDifference(Container &S1, const Container &S2)
static Container & assignUnion(Container &S1, const Container &S2)
static Container & assignIntersection(Container &S1, const Container &S2)
static bool isSubset(const Container &S1, const Container &S2)
static Container & assignDifference(Container &S1, const Container &S2)
static Container & assignIntersection(Container &S1, const Container &S2)
static Container & assignSymmetricDifference(Container &S1, const Container &S2)
static bool isSubset(const Container &S1, const Container &S2)
static bool isEqual(const Container &S1, const Container &S2)
static Container & assignUnion(Container &S1, const Container &S2)
static Container & assignDifference(Container &S1, const Container &S2)
Aim: Specialize set operations (union, intersection, difference, symmetric_difference) according to t...
static Container & assignIntersection(Container &S1, const Container &S2)
static bool isEqual(const Container &S1, const Container &S2)
static Container & assignUnion(Container &S1, const Container &S2)
static bool isSubset(const Container &S1, const Container &S2)
static Container & assignDifference(Container &S1, const Container &S2)
static Container & assignSymmetricDifference(Container &S1, const Container &S2)