"Fossies" - the Fresh Open Source Software Archive

Member "heaplayers-351/benchmarks/lindsay/chooselr.c" (3 May 2004, 2046 Bytes) of package /linux/misc/old/heaplayers_3_5_1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "chooselr.c" see the Fossies "Dox" file reference documentation.

    1 // chooselr.c   - ignores okset and simply goes left to right.
    2 // ----------
    3 //      Copyright 1988 D.C. Lindsay at Carnegie Mellon University
    4 //
    5 // Implementation of class: see choose.h for spec.
    6 // Different implementations will try different policies.
    7 // The class is instantiatied ONCE.
    8 
    9 #include "node.h"
   10 #include "choose.h"
   11 #include <stream.h>
   12 
   13 extern node nodes[];
   14 extern int cube_size;
   15 extern const int bitmask[]; // bitmask[i] is 2**i
   16 
   17 chooseclass choose;     // ONLY INSTANCE
   18 /*************************************************/
   19 chooseclass::chooseclass()
   20 {
   21 }
   22 /*******************************************/
   23 void chooseclass::sanitycheck()
   24 {
   25     cout << "Choose algorithm: lr (strict left-right, no history tag)\n";
   26 }
   27 /*******************************************/
   28 void chooseclass::noteack( nodenum here, linknum lout, struct message *pm )
   29 {
   30 }
   31 /*******************************************/
   32 void chooseclass::notenak( nodenum here, linknum lout, struct message *pm )
   33 {
   34 }
   35 /*****************************************/
   36 //
   37 // rightmost returns the bit position (0..15) of the rightmost set bit.
   38 // Returns -1 if no bit set.
   39 
   40 linknum rightmost( int mask )
   41 {
   42     if( (mask <0) || (mask > cube_size)){
   43         cout << "ERROR: rightmost invalid argument " << mask NL;
   44         return 1;
   45     }
   46     if( mask == 0 ) return -1;
   47     int i;
   48     for( i=0;; i++ ) {
   49         if( mask & 1 ) break;
   50         mask >>= 1;
   51     }
   52     return i;
   53 }
   54 /*****************************************/
   55 // chooselink returns a link# that is free at that node,
   56 // and that is in both the linkset and the okset.
   57 // Returns -1 if no such.
   58 // The search is done right-to-left (LS -> MS).
   59 
   60 linknum chooseclass::outlink( nodenum here, int linkset, int okset )
   61 {
   62     struct node *phere = &nodes[ here ];
   63     linknum l;
   64     for(;;) {
   65         l = rightmost( linkset );       // index of bit
   66         if( l < 0 ) break;
   67         if( phere->links[l].busy == false ) break;  // found one
   68         linkset ^= bitmask[l];          // turn off bit l
   69     }
   70     return l;
   71 }
   72 /*******************************************/
   73 //  int goodlinkset, badlinkset;
   74 //  linknum lastlink;
   75 //  char bestlink[ MAX_CUBE_SIZE ];