GClasses
GClasses::GSimpleAssignment Class Reference

Detailed Description

#include <GAssignment.h>

Inheritance diagram for GClasses::GSimpleAssignment:
GClasses::GAssignment

Public Member Functions

 GSimpleAssignment (std::size_t aSize, std::size_t bSize)
 Create an assignment between two sets of the given sizes that assigns everything to -1. More...
 
 GSimpleAssignment (std::size_t bSize, const std::vector< int > &bfA)
 Create an assignment between two sets of the given sizes that assigns everything according to the array bForA. More...
 
virtual ~GSimpleAssignment ()
 A do-nothing destructor needed since there may be subclasses. More...
 
virtual void assign (unsigned memberOfA, unsigned memberOfB)
 Create an assignment between the two members, setting any previously corresponding members to unassigned. More...
 
virtual int inverse (unsigned memberOfB) const
 Return the number of the member of set A corresponding to the memberOfB element in set B or -1 if there is no corresponding member. More...
 
virtual int operator() (unsigned memberOfA) const
 Return the number of the member of set B corresponding to the memberOfA element in set A or -1 if there is no corresponding member. More...
 
virtual bool operator< (const GSimpleAssignment &other) const
 Return true iff *this, expressed as the input to setBForA with sizeB prepended is lexiographically less than other. More...
 
virtual bool operator== (const GSimpleAssignment &other) const
 Return true if *this and other represent the same assignments among the same sized sets. More...
 
virtual void setBForA (const std::vector< int > &bfA)
 Set the assignment to the one expressed in the vector bForA. More...
 
virtual std::size_t sizeA () const
 Return the number of elements in the A set of this GAssignment. More...
 
virtual std::size_t sizeB () const
 Return the number of elements in the B set of this GAssignment. More...
 
virtual void swapAAndB ()
 Swaps the A and B set. The assignments stay the same. More...
 
virtual void unassignA (unsigned memberOfA)
 Remove any assignment for the given member of A. More...
 
virtual void unassignB (unsigned memberOfB)
 Remove any assignment for the given member of B. More...
 
- Public Member Functions inherited from GClasses::GAssignment
virtual ~GAssignment ()
 A do-nothing destructor needed since there will be subclasses. More...
 

Static Public Member Functions

static void test ()
 Run unit tests for GSimpleAssignment - throws an exception if an error is found. More...
 

Protected Attributes

std::vector< int > aForB
 aForB[i] has the member of A assigned to a given member of B (or -1 when no member) More...
 
std::vector< int > bForA
 bForA[i] has the member of B assigned to a given member of A (or -1 when no member) More...
 

Constructor & Destructor Documentation

GClasses::GSimpleAssignment::GSimpleAssignment ( std::size_t  aSize,
std::size_t  bSize 
)
inline

Create an assignment between two sets of the given sizes that assigns everything to -1.

Parameters
aSizethe number of elements in set A (the first set in the assignment)
bSizethe number of elements in set B (the second set in the assignment)
GClasses::GSimpleAssignment::GSimpleAssignment ( std::size_t  bSize,
const std::vector< int > &  bfA 
)
inline

Create an assignment between two sets of the given sizes that assigns everything according to the array bForA.

Just like writing:

GSimpleAssignment foo(bForA.size(), \a bSize);
foo.setBForA(bForA);
Parameters
bSizethe number of elements in set B (the second set in the assignment)
bForAbForA[i] gives the assignment for element i in set A. It is the index of the corresponding element of set B or -1 if there is no corresponding element.
See also
GSimpleAssignment(std::size_t, std::size_t)
bForA(const std::vector<int>&)
virtual GClasses::GSimpleAssignment::~GSimpleAssignment ( )
inlinevirtual

A do-nothing destructor needed since there may be subclasses.

Member Function Documentation

virtual void GClasses::GSimpleAssignment::assign ( unsigned  memberOfA,
unsigned  memberOfB 
)
inlinevirtual

Create an assignment between the two members, setting any previously corresponding members to unassigned.

First breaks any assignment between memberOfA and any other member and memberOfB and any other member, then makes a new assignment between memberOfA and memberOfB

Parameters
memberOfAthe number for the member of set A that will get assigned to memberOfB
memberOfBthe number for the member of set B that will get assigned to memberOfA
virtual int GClasses::GSimpleAssignment::inverse ( unsigned  memberOfB) const
inlinevirtual

Return the number of the member of set A corresponding to the memberOfB element in set B or -1 if there is no corresponding member.

Parameters
memberOfBthe number of the member of set B whose assignment is desired
Returns
the number of the member of set A corresponding to the memberOfB element in set B or -1 if there is no corresponding member.

Implements GClasses::GAssignment.

virtual int GClasses::GSimpleAssignment::operator() ( unsigned  memberOfA) const
inlinevirtual

Return the number of the member of set B corresponding to the memberOfA element in set A or -1 if there is no corresponding member.

Parameters
memberOfAthe number of the member of set A whose assignment is desired
Returns
the number of the member of set B corresponding to the memberOfA element in set A or -1 if there is no corresponding member

Implements GClasses::GAssignment.

virtual bool GClasses::GSimpleAssignment::operator< ( const GSimpleAssignment other) const
inlinevirtual

Return true iff *this, expressed as the input to setBForA with sizeB prepended is lexiographically less than other.

Parameters
otherthe GSimpleAssignment being compared to this one
Returns
true iff *this, expressed as the input to setBForA with sizeB prepended is lexiographically less than other
virtual bool GClasses::GSimpleAssignment::operator== ( const GSimpleAssignment other) const
inlinevirtual

Return true if *this and other represent the same assignments among the same sized sets.

If A is the same size as set A for other and B is the same size as B for other and the members with identical indices are assigned to one another and the unassigned members also have identical indices, then the two assignment objects are equal.

In other words, returns true if and only if sizeA(), sizeB(), operator()(unsigned) and inverse()(unsigned) give identical results on both *this and other for all valid input values.

Parameters
otherthe GSimpleAssignment object to compare to this
Returns
true if the assignments are the same, false otherwise. See main description for details.
virtual void GClasses::GSimpleAssignment::setBForA ( const std::vector< int > &  bfA)
inlinevirtual

Set the assignment to the one expressed in the vector bForA.

Given a vector bForA for which bForA[i] is the index of the member of set B that corresponds to the i-th member of set A or is -1 if there is no corresponding element, make the assignments in this object identical.

It is assumed that this operation will not change the sizes of the sets referred to by this assignment. That is, -1 <= bForA[i] and bForA[i] < sizeB() and bForA.size() == sizeA()

Parameters
bForAbForA[i] gives the assignment for element i in set A. It is the index of the corresponding element of set B or -1 if there is no corresponding element.
virtual std::size_t GClasses::GSimpleAssignment::sizeA ( ) const
inlinevirtual

Return the number of elements in the A set of this GAssignment.

See the class comment for more information.

Returns
the number of elements in the A set of this GAssignment

Implements GClasses::GAssignment.

virtual std::size_t GClasses::GSimpleAssignment::sizeB ( ) const
inlinevirtual

Return the number of elements in the B set of this GAssignment.

See the class comment for more information.

Returns
the number of elements in the B set of this GAssignment

Implements GClasses::GAssignment.

virtual void GClasses::GSimpleAssignment::swapAAndB ( )
inlinevirtual

Swaps the A and B set. The assignments stay the same.

If A element i was assigned to B element j before the swap, A element j will be asigned to B element i after the swap.

static void GClasses::GSimpleAssignment::test ( )
static

Run unit tests for GSimpleAssignment - throws an exception if an error is found.

virtual void GClasses::GSimpleAssignment::unassignA ( unsigned  memberOfA)
inlinevirtual

Remove any assignment for the given member of A.

Does nothing if A is unassigned.

Parameters
memberOfAThe number for the member of set A which should be unassigned
virtual void GClasses::GSimpleAssignment::unassignB ( unsigned  memberOfB)
inlinevirtual

Remove any assignment for the given member of B.

Does nothing if B is unassigned.

Parameters
memberOfBThe number for the member of set B which should be unassigned

Member Data Documentation

std::vector<int> GClasses::GSimpleAssignment::aForB
protected

aForB[i] has the member of A assigned to a given member of B (or -1 when no member)

std::vector<int> GClasses::GSimpleAssignment::bForA
protected

bForA[i] has the member of B assigned to a given member of A (or -1 when no member)