GClasses
|
A simple concrete implementation of the GAssignment protocol using std::vector<int>
#include <GAssignment.h>
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... | |
|
inline |
Create an assignment between two sets of the given sizes that assigns everything to -1.
aSize | the number of elements in set A (the first set in the assignment) |
bSize | the number of elements in set B (the second set in the assignment) |
|
inline |
Create an assignment between two sets of the given sizes that assigns everything according to the array bForA.
Just like writing:
bSize | the number of elements in set B (the second set in the assignment) |
bForA | bForA[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. |
|
inlinevirtual |
A do-nothing destructor needed since there may be subclasses.
|
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
memberOfA | the number for the member of set A that will get assigned to memberOfB |
memberOfB | the number for the member of set B that will get assigned to memberOfA |
|
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.
memberOfB | the number of the member of set B whose assignment is desired |
Implements GClasses::GAssignment.
|
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.
memberOfA | the number of the member of set A whose assignment is desired |
Implements GClasses::GAssignment.
|
inlinevirtual |
Return true iff *this, expressed as the input to setBForA with sizeB prepended is lexiographically less than other.
other | the GSimpleAssignment being compared to this one |
|
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.
other | the GSimpleAssignment object to compare to this |
|
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()
bForA | bForA[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. |
|
inlinevirtual |
Return the number of elements in the A set of this GAssignment.
See the class comment for more information.
Implements GClasses::GAssignment.
|
inlinevirtual |
Return the number of elements in the B set of this GAssignment.
See the class comment for more information.
Implements GClasses::GAssignment.
|
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 |
Run unit tests for GSimpleAssignment - throws an exception if an error is found.
|
inlinevirtual |
Remove any assignment for the given member of A.
Does nothing if A is unassigned.
memberOfA | The number for the member of set A which should be unassigned |
|
inlinevirtual |
Remove any assignment for the given member of B.
Does nothing if B is unassigned.
memberOfB | The number for the member of set B which should be unassigned |
|
protected |
aForB[i] has the member of A assigned to a given member of B (or -1 when no member)
|
protected |
bForA[i] has the member of B assigned to a given member of A (or -1 when no member)