|
INTEGER
Description
INTEGER is a special class that can be used to
compare algorithms that operate on integer-type data.
It is used by declaring variable of type INTEGER
instead of type int.
The most common operators have been overloaded.
Whenever an operation is performed, one of the various
counters is incremented. Besides the overloaded operators,
the following functions have been defined.
- print_stats() prints the current value of each
of the counters to standard output.
- get_total() returns the sum of all of the counters.
- get_comps() returns the number of comparisons only.
- reset_counters() sets all of the counters back to 0.
One of the things you might notice when using the print_stats()
function is that the highest counter is probably
Copy Constr count. The reason it is so high is that the
copy constructor is called in many instances you don't think about.
I have gone back and forth between including
and not including this count in the totals. For now it is included,
since it is a real 'expense'.
The one difficulty you may have with the INTEGER class
is trying to index an array with an INTEGER.
If x is an INTEGER, and A is an array of
INTEGERs, then instead of using the syntax A[x],
use A[x()]. This is the only time you should use the ()
syntax with an INTEGER.
By the way, if anyone knows of a better way to do performance comparisons
on algorithms, or is interested in improving the INTEGER class,
please let me know.
|