DGtal  0.9.4beta
Static Public Member Functions
DGtal::detail::SetFunctionsImpl< Container, true, false > Struct Template Reference

#include <DGtal/base/SetFunctions.h>

Static Public Member Functions

static bool isEqual (const Container &S1, const Container &S2)
 
static bool isSubset (const Container &S1, const Container &S2)
 
static Container & assignDifference (Container &S1, const Container &S2)
 
static Container & assignUnion (Container &S1, const Container &S2)
 
static Container & assignIntersection (Container &S1, const Container &S2)
 
static Container & assignSymmetricDifference (Container &S1, const Container &S2)
 

Detailed Description

template<typename Container>
struct DGtal::detail::SetFunctionsImpl< Container, true, false >

Specialization for associative, unordered containers (unordered_set, unordered_map).

Definition at line 392 of file SetFunctions.h.

Member Function Documentation

template<typename Container >
static Container& DGtal::detail::SetFunctionsImpl< Container, true, false >::assignDifference ( Container &  S1,
const Container &  S2 
)
inlinestatic

Updates the set S1 as S1 - S2. This version does not use the fact that the container is ordered.

Parameters
[in,out]S1an input set, S1 - S2 as output.
[in]S2another input set.

Definition at line 444 of file SetFunctions.h.

445  {
446  typedef ComparatorAdapter< Container, true, false,
447  IsPairAssociativeContainer< Container >::value >
448  CompAdapter;
449 
450  for ( typename Container::const_iterator it = S2.begin(),
451  itE = S2.end(); it != itE; ++it )
452  S1.erase( CompAdapter::key( *it ) );
453  return S1;
454  }
template<typename Container >
static Container& DGtal::detail::SetFunctionsImpl< Container, true, false >::assignIntersection ( Container &  S1,
const Container &  S2 
)
inlinestatic

Updates the set S1 as \( S1 \cap S2 \). This version does not use the fact that the container is ordered.

Parameters
[in,out]S1an input set, \( S1 \cap S2 \) as output.
[in]S2another input set.

Definition at line 477 of file SetFunctions.h.

478  {
479  typedef ComparatorAdapter< Container, true, false,
480  IsPairAssociativeContainer< Container >::value >
481  CompAdapter;
482 
483  for ( typename Container::iterator it = S1.begin(),
484  itE = S1.end(); it != itE; )
485  {
486  typename Container::iterator itNext = it; ++itNext;
487  if ( S2.find( *it ) == S2.end() )
488  S1.erase( CompAdapter::key( *it ) );
489  it = itNext;
490  }
491  return S1;
492  }
template<typename Container >
static Container& DGtal::detail::SetFunctionsImpl< Container, true, false >::assignSymmetricDifference ( Container &  S1,
const Container &  S2 
)
inlinestatic

Updates the set S1 as \( S1 \Delta S2 \). This version does not use the fact that the container is ordered.

Parameters
[in,out]S1an input set, \( S1 \Delta S2 \) as output.
[in]S2another input set.

Definition at line 500 of file SetFunctions.h.

References DGtal::detail::SetFunctionsImpl< Container, associative, ordered >::assignDifference(), DGtal::detail::SetFunctionsImpl< Container, associative, ordered >::assignIntersection(), and DGtal::detail::SetFunctionsImpl< Container, associative, ordered >::assignUnion().

501  {
502  Container S12( S1 );
503  assignIntersection( S12, S2 );
504  assignUnion( S1, S2 );
505  return assignDifference( S1, S12 );
506  }
static Container & assignIntersection(Container &S1, const Container &S2)
Definition: SetFunctions.h:477
static Container & assignUnion(Container &S1, const Container &S2)
Definition: SetFunctions.h:462
static Container & assignDifference(Container &S1, const Container &S2)
Definition: SetFunctions.h:444
template<typename Container >
static Container& DGtal::detail::SetFunctionsImpl< Container, true, false >::assignUnion ( Container &  S1,
const Container &  S2 
)
inlinestatic

Updates the set S1 as \( S1 \cup S2 \). This version does not use the fact that the container is ordered.

Parameters
[in,out]S1an input set, \( S1 \cup S2 \) as output.
[in]S2another input set.

Definition at line 462 of file SetFunctions.h.

463  {
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 );
468  return S1;
469  }
template<typename Container >
static bool DGtal::detail::SetFunctionsImpl< Container, true, false >::isEqual ( const Container &  S1,
const Container &  S2 
)
inlinestatic

Equality test. This version does not use the fact that the container is ordered.

Parameters
[in]S1an input set.
[in]S2another input set.
Returns
true iff S1 is equal to S2 (seen as sets).

Definition at line 402 of file SetFunctions.h.

403  {
404  typedef ComparatorAdapter< Container, true, false,
405  IsPairAssociativeContainer< Container >::value >
406  CompAdapter;
407 
408  // Checks size first.
409  if ( S1.size() != S2.size() ) return false;
410  // Note that it is critical here that all elements are distinct.
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;
414  return true;
415  }
template<typename Container >
static bool DGtal::detail::SetFunctionsImpl< Container, true, false >::isSubset ( const Container &  S1,
const Container &  S2 
)
inlinestatic

Inclusion test. This version does not use the fact that the container is ordered.

Parameters
[in]S1an input set.
[in]S2another input set.
Returns
true iff S1 is a subset of S2.

Definition at line 424 of file SetFunctions.h.

425  {
426  typedef ComparatorAdapter< Container, true, false,
427  IsPairAssociativeContainer< Container >::value >
428  CompAdapter;
429 
430  // Checks size first.
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;
435  return true;
436  }

The documentation for this struct was generated from the following file: