Previous: SIn_Array Example, Up: SIn Array Object


7.2.3 SIn_Array Reference

— Class: SIn_Array<typename T>

A sparse array with elements of type T. The number of elements the array can hold is equal to the number of static instructions in the benchmark program (the value of RSIM global variable num_all_instructions). Initially the array has zero elements. Elements are automatically created using the get function or [] operator. The peek function can be used to check whether an element is present (unlike get it won't create one). Function del deletes elements. Function iterate can be used in loops that need to examine each element.

— Function: T* SIn_Array<T>::get int ii
— Function: T* SIn_Array<T>::get SIn* sin
— Function: T* SIn_Array<T>::get DIn* din
— Function: T* SIn_Array<T>::operator[] int ii
— Function: T* SIn_Array<T>::operator[] SIn* sin
— Function: T* SIn_Array<T>::operator[] DIn* din

If not present at ii, instantiate object of type T and store it there. Return a pointer to the object. In first form the instruction index is given (ii). In second and third forms instruction index is determined using the argument. The last three are operator versions of the first three.

          // The four lines below are equivalent.
          //
          Diff_SIn_Info* const si = sin_info[din];
          Diff_SIn_Info* const si = sin_info.get(din);
          Diff_SIn_Info* const si = sin_info[din->pc];
          Diff_SIn_Info* const si = sin_info[din->sin];
     
— Function: T* SIn_Array<T>::peek int ii
— Function: T* SIn_Array<T>::peek SIn* sin
— Function: T* SIn_Array<T>::peek DIn* din

If not present at ii return NULL, otherwise return a pointer to the object. Value for ii computed in same way as get.

— Function: void SIn_Array<T>::del int ii
— Function: void SIn_Array<T>::del SIn* sin
— Function: void SIn_Array<T>::del DIn* din

If there is an element at ii, sin, or din delete it.

— Function: void SIn_Array<T>::reset

Delete all elements and reset iterator. This might be used before re-reading data from a Profile object.

— Function: T* SIn_Array::iterate
— Function: bool SIn_Array::iterate int& idx

The first form returns an element of the array, or NULL. The second form will either set idx to the instruction index of an element of the array and return true or it will return false. Suppose the array contains five elements. The first call of iterate will return the first element (the one with the lowest index), the second call will return the second element, and so on. The sixth call will return NULL (or false). The seventh call will return the first element, starting the sequence again.

            // Each loop iterates over all members of sin_info.
          
            for( int ii; sin_info.iterate(ii); )
              {
                Diff_SIn_Info* const si = sin_info[ii];
                total_exec += si->exe_count;
              }
          
            while ( Diff_SIn_Info* const si = sin_info.iterate() )
               total_exec += si->exe_count;
     
— Function: void SIn_Array::iterate_reset

Reset the iteration state so that a subsequent call to iterate will return the first element.

— Function: int SIn_Array::iterate_get_ii
— Function: t_ptru SIn_Array::iterate_get_pc
— Function: SIn* SIn_Array::iterate_get_sin

The first form returns the index of the last element returned by iterate, the second form returns the program counter, and the third form returns a pointer to the SIn structure.