C:/Users/Dennis/src/lang/russell.orig/src/pass2/retrieve.c

Go to the documentation of this file.
00001 
00002 /*
00003  *      retrieve(key)
00004  *
00005  *      Return a pointer to the Identry with i_sttindx key.
00006  */
00007 
00008 # include "parm.h"
00009 # include "stree/ststructs.mh"
00010 # include "pass1/stt/sttdefs.h"
00011 # include "Idtable.h"
00012 # define DEBUG yes
00013 
00014 /* int nprobes = 0; */
00015 int nkeys = 0;
00016 
00017 Identry * retrieve(key)
00018 sttrelptr key;
00019 {
00020         nkeys++;
00021         return ( &Idtable[retr1(key, 0, sttnstrings-1)] );
00022 }
00023 
00024 /*
00025  *      retr1(key, f, l)
00026  *
00027  *      Hidden routine to search Idtable between the bounds f and l for the entry
00028  *      with i_sttindx equal to indx. An interpolation search is used.
00029  */
00030 retr1(key, f, l)
00031 register sttrelptr key;
00032 register int f, l;                                      /* first, last indices                          */
00033 {       register int c;                                 /* "current" probe index                        */
00034 
00035         for(;;) {
00036 
00037                 /* nprobes++; */
00038 
00039         if ( f > l || Idtable[f].i_sttindx > key || Idtable[l].i_sttindx < key) {
00040                 dbgmsg("retr1: Can't find name!\n");
00041                 /* abort(); */ return;
00042         }
00043     
00044         c = f;
00045                 if( l != f ) {
00046                   long r;
00047                   int t;
00048 
00049                   /*c +=
00050                                 ( ((long)(l-f)) * ((long)(key-Idtable[f].i_sttindx)) ) /
00051                                         ( (int) (Idtable[l].i_sttindx - Idtable[f].i_sttindx) ); */
00052 
00053                         r= ( ((long)(l-f)) * ((long)(key-Idtable[f].i_sttindx)) ); 
00054                         t=              ( (int) (Idtable[l].i_sttindx - Idtable[f].i_sttindx) );
00055                         r += t >> 1;
00056                         c += r / t;
00057                 }
00058 /*              printf("f=%d, l=%d, c=%d\n", f, l, c); */
00059                 if ( Idtable[c].i_sttindx == key )
00060                         return(c);
00061         else if ( key < Idtable[c].i_sttindx ) {
00062                 f += 1; l = c-1;
00063         } else {
00064                 f = c+1; l -= 1;
00065                 }
00066         }
00067 }

Generated on Fri Jan 25 10:39:46 2008 for russell by  doxygen 1.5.4