Utilities Package  Version Linux2023.0
Public Member Functions | List of all members
Scobey::OperationCounter Class Reference

For counting operations performed by an algorithm. More...

#include <utilities.h>

Public Member Functions

 OperationCounter ()
 Default constructor. More...
 
void reset ()
 Resets all operation counters to zero and the name of the "other" operation, if any, to an empty string. More...
 
void incrementAssignments (int numTimes=1)
 Increments the counter for the number of assignment operations. More...
 
void incrementComparisons (int numTimes=1)
 Increments the counter for the number of comparison operations. More...
 
void incrementExchanges (int numTimes=1)
 Increments the counter for the number of exchange operations. More...
 
void incrementOtherOp (int numTimes=1)
 Increments the counter for the number of "other" operations. More...
 
int getNumberOfComparisons () const
 Gets the number of comparison operations counted. More...
 
int getNumberOfExchanges () const
 Gets the number of exchange operations counted. More...
 
int getNumberOfAssignments () const
 Gets the number of assignment operations counted. More...
 
int getNumberOfOtherOp () const
 Gets the number of "other" operations performed. More...
 
void setNameOfOtherOp (string nameOfOtherOp)
 Sets (or resets) the name of the "other" operation. More...
 
string getNameOfOtherOp () const
 Gets the name of the "other" operation. More...
 
void displayNonZeroCounts () const
 
void displayAllCounts () const
 

Detailed Description

For counting operations performed by an algorithm.

An object of the OperationCounter class may be used to keep a count of the number of each of several different kinds operations performed during the application of an algorithm to a data set. The operations that can be counted are the usual comparisons, exchanges, and assignments that one might be interested in tracking, as well as one other kind of operation chosen by the client. The client may also supply a name for that "other" operation, and use that name in summary output.

Constructor & Destructor Documentation

◆ OperationCounter()

Scobey::OperationCounter::OperationCounter ( )

Default constructor.

Precondition
None
Postcondition
A counter object has been constructed, with all operation counters set to 0 and the name of the "other" operation set to "Other Op".

Member Function Documentation

◆ reset()

void Scobey::OperationCounter::reset ( )

Resets all operation counters to zero and the name of the "other" operation, if any, to an empty string.

Returns
void
Precondition
None
Postcondition
All counting data members have been reset to 0, and the name of the "other" operation has been set to "Other Op".

◆ incrementAssignments()

void Scobey::OperationCounter::incrementAssignments ( int  numTimes = 1)

Increments the counter for the number of assignment operations.

Returns
void
Parameters
numTimesThe number of times the assignment counter is to be incremented.
Returns
void
Precondition
None
Postcondition
The number of assignment operations has been incremented by the value of numTimes.

◆ incrementComparisons()

void Scobey::OperationCounter::incrementComparisons ( int  numTimes = 1)

Increments the counter for the number of comparison operations.

Returns
void
Parameters
numTimesThe number of times the comparison counter is to be incremented.
Precondition
None
Postcondition
The number of comparison operations has been incremented by the value of numTimes.

◆ incrementExchanges()

void Scobey::OperationCounter::incrementExchanges ( int  numTimes = 1)

Increments the counter for the number of exchange operations.

Returns
void
Parameters
numTimesThe number of times the exchange counter is to be incremented.
Precondition
None
Postcondition
The number of exchange operations has been incremented by the value of numTimes.

◆ incrementOtherOp()

void Scobey::OperationCounter::incrementOtherOp ( int  numTimes = 1)

Increments the counter for the number of "other" operations.

Returns
void
Parameters
numTimesThe number of times the counter of the "other" operation is to be incremented.
Precondition
None
Postcondition
The number of "other" operations has been incremented by the value of numTimes.

◆ getNumberOfComparisons()

int Scobey::OperationCounter::getNumberOfComparisons ( ) const

Gets the number of comparison operations counted.

Returns
The number of comparison operations counted.
Precondition
None
Postcondition
No side effects.

◆ getNumberOfExchanges()

int Scobey::OperationCounter::getNumberOfExchanges ( ) const

Gets the number of exchange operations counted.

Returns
The number of exchange operations counted.
Precondition
None
Postcondition
No side effects.

◆ getNumberOfAssignments()

int Scobey::OperationCounter::getNumberOfAssignments ( ) const

Gets the number of assignment operations counted.

Returns
The number of assignment operations counted.
Precondition
None
Postcondition
No side effects.

◆ getNumberOfOtherOp()

int Scobey::OperationCounter::getNumberOfOtherOp ( ) const

Gets the number of "other" operations performed.

Returns
The number of "other" operations counted.
Precondition
None
Postcondition
No side effects.

◆ setNameOfOtherOp()

void Scobey::OperationCounter::setNameOfOtherOp ( string  nameOfOtherOp)

Sets (or resets) the name of the "other" operation.

Returns
void
Parameters
nameOfOtherOpText for the name of the "other" operation.
Precondition
nameOfOtherOp has been initialized.
Postcondition
The value of nameOfOtherOp has been assigned as the name of the other operation.

◆ getNameOfOtherOp()

string Scobey::OperationCounter::getNameOfOtherOp ( ) const

Gets the name of the "other" operation.

Returns
The name of the "other" operation.
Precondition
None
Postcondition
The name of the "other operation" has been returned (and will be "Other Op" unless it has been set to something else with setNameOfOtherOp().

◆ displayNonZeroCounts()

void Scobey::OperationCounter::displayNonZeroCounts ( ) const
Displays a summary of the counts for all operations actually performed
(and which therefore have non-zero counts). This method would normally
be called if only one or two operations were being counted and the
user did not want to take up space in the output with zero counts
for the other operations.
@return void
@pre None
@post
- Case 1: Whatever counts of comparisons, number of exchanges, number
of assignments and/or the number of operations of the "other" kind (if
applicable) have been recorded by counter object and are non-zero have
been displayed as shown below. That is, the title is displayed, along
with those lines corresponding to non-zero counts.
Summary of Non-Zero Operation Counts
Comparisons = #
Exchanges   = #
Assignments = #
Name of Other Operation = #
  • Case 2: If all counts are zero, the following message is displayed.
    Summary of Non-Zero Operation Counts
    No operations of any kind have been counted.
    

◆ displayAllCounts()

void Scobey::OperationCounter::displayAllCounts ( ) const
Displays a summary of the number of operations counted. This method
would normally be used when the user desires to see all counts, even
if some are (and are known to be) zero.
@return void
@pre None
@post
- Case 1: All operation counts are displayed in the format shown below.
Summary of All Operation Counts
Comparisons = #
Exchanges   = #
Assignments = #
Name of Other Operation = #
  • Case 2: If all counts are zero, the following message is displayed:
    Summary of All Operation Counts
    No operations of any kind have been counted.
    

The documentation for this class was generated from the following files: