Utilities Package
Version Linux2023.0
|
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 |
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.
Scobey::OperationCounter::OperationCounter | ( | ) |
Default constructor.
void Scobey::OperationCounter::reset | ( | ) |
Resets all operation counters to zero and the name of the "other" operation, if any, to an empty string.
void Scobey::OperationCounter::incrementAssignments | ( | int | numTimes = 1 | ) |
Increments the counter for the number of assignment operations.
numTimes | The number of times the assignment counter is to be incremented. |
void Scobey::OperationCounter::incrementComparisons | ( | int | numTimes = 1 | ) |
Increments the counter for the number of comparison operations.
numTimes | The number of times the comparison counter is to be incremented. |
void Scobey::OperationCounter::incrementExchanges | ( | int | numTimes = 1 | ) |
Increments the counter for the number of exchange operations.
numTimes | The number of times the exchange counter is to be incremented. |
void Scobey::OperationCounter::incrementOtherOp | ( | int | numTimes = 1 | ) |
Increments the counter for the number of "other" operations.
numTimes | The number of times the counter of the "other" operation is to be incremented. |
int Scobey::OperationCounter::getNumberOfComparisons | ( | ) | const |
Gets the number of comparison operations counted.
int Scobey::OperationCounter::getNumberOfExchanges | ( | ) | const |
Gets the number of exchange operations counted.
int Scobey::OperationCounter::getNumberOfAssignments | ( | ) | const |
Gets the number of assignment operations counted.
int Scobey::OperationCounter::getNumberOfOtherOp | ( | ) | const |
Gets the number of "other" operations performed.
void Scobey::OperationCounter::setNameOfOtherOp | ( | string | nameOfOtherOp | ) |
Sets (or resets) the name of the "other" operation.
nameOfOtherOp | Text for the name of the "other" operation. |
string Scobey::OperationCounter::getNameOfOtherOp | ( | ) | const |
Gets the name of the "other" operation.
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 = #
Summary of Non-Zero Operation Counts No operations of any kind have been counted.
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 = #
Summary of All Operation Counts No operations of any kind have been counted.