Skip to content

Extra functionalities

Jean-Francois Baffier edited this page Jun 15, 2017 · 6 revisions

Extra functionalities for any Stack Algorithm run will add some overhead to the minimal code. As the aim of most of the users of this library is to optimize space efficiency while marginally increasing the execution time, we chose to provide some of those extra functionalities as options. Any such space-consuming option, current and future ones, can be found in the extras/ folder.

Custom bit size for indexation

To further optimize the space usage of the compressed stack, the bit size of the unsigned integers used for the indexation of the data is left to the user. By default, we provide 8, 16, 32, and 64 bits unsigned integers.

Classic Stack (as an optional functionality)

Stack algorithms can also be solved with a classic uncompressed stac. We provide access to a classic stack in case the user so desires (say, for debugging purposes).

Finally, we also provide another Stack Algorithm in extras/stackAlgoExtras.hpp that possesses both a compressed stack and a classic stack. This class will run and compare the state of both stacks all along the execution of the algorithm. Specific errors are raised to signal any difference in behavior.

As explained in the examples (examples/testrun/testrunExtras.cpp and examples/testrun/upperHullExtras.cpp), the different calls available are explained below.

/*==============================================================================
  How to use
    * argv[1] is the file name
    * argv[2] is the code of what is to be done
      * 0 is a testrun problem with a compressed stack (with extras)
      * 1 is a testrun problem with a classical stack
      * 2 is a testrun problem with both stacks comparison (check
errors)
    * argv[3] is the code for the integer size
      * 8 is for 8 bits integer (or smallest size handling 8 bits)
      * 16 is for 16 bits integer (or smallest size handling 16 bits)
      * 32 is for 32 bits integer (or smallest size handling 32 bits)
      * 64 or default is for 64 bits integer (or smallest size handling 64 bits)
==============================================================================*/

For instance, the call below creates a Stack Algorithm with both a classic stack and a compressed stack, using 32 bits unsigned integers for the indexation of elements.

./testrunExtras path_to_file 2 32

Counting functions

For debugging and analyzing purpose we propose simple counting functions inside any Stack Algorithm. All of them can be called anytime before, during, and after the execution of the Stack Algorithm.

  • Counting pops, pushes, and the number of elements currently in the stack
SomeStackAlgo instance;

instance.getPops();
instance.getPushes();
instance.countItems();
  • Counting the maximum number of elements that have been in the stack
SomeStackAlgo instance;

instance.getMaxItems();
Clone this wiki locally