Dismiss
InnovationQ will be updated on Sunday, Oct. 22, from 10am ET - noon. You may experience brief service interruptions during that time.
Browse Prior Art Database

Extending C/C++ Switch Statement to Select Based on Probabilities/Weights

IP.com Disclosure Number: IPCOM000117238D
Original Publication Date: 1996-Jan-01
Included in the Prior Art Database: 2005-Mar-31
Document File: 2 page(s) / 58K

Publishing Venue

IBM

Related People

Whitmill, KL: AUTHOR

Abstract

Disclosed is a method of making the C/C++ switch statement select cases based on probabilities or weights. A preprocessor is utilized to accommodate syntax changes to the normal switch statement that would allow specifying probabilities/weights. A selection function is used to select the correct case based on probabilities/weights.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 53% of the total text.

Extending C/C++ Switch Statement to Select Based on Probabilities/Weights

      Disclosed is a method of making the C/C++ switch statement
select cases based on probabilities or weights.  A preprocessor is
utilized to accommodate syntax changes to the normal switch statement
that would allow specifying probabilities/weights.  A selection
function is used to select the correct case based on
probabilities/weights.

      The method of using a preprocessor and select function to
enable selecting cases based on probabilities or weights is specified
below:
  o  Modify the syntax of the C/C++ switch statement.
     -  Use the "pswitch" keyword in place of the "switch" keyword.
     -  Omit the expression and parenthesis that syntactically follow
         a switch keyword.
     -  For each case label in the construct substitute a weight or
         probability for the  case value.
     -  Add an "endpswitch" keyword at the end of the construct.
  o  Use a preprocessor to process the pswitch construct before doing
      the normal compile.  The preprocessor does the following:
     -  Convert the pswitch keyword back to a switch keyword.
     -  Provide the switch condition expression to determine which
         case gets selected.  The switch condition is specified as a
         call to a selection function passing to it the
         weights/probabilities of each case.  The order of the
         weights/probabilities must be exactly the same as they are
         specified in the pswitch construct.
     -  Replace the case label values, specified as
         weights/probabilities, with the correspo...