1: # include   <ingres.h>
   2: # include   <aux.h>
   3: # include   <symbol.h>
   4: # include   <access.h>
   5: # include   <lock.h>
   6: # include   <sccs.h>
   7: 
   8: SCCSID(@(#)rhash.c	8.2	1/17/85)
   9: 
  10: /*
  11: **  RHASH -- perform a randomizing hash on the full key.
  12: **
  13: **	Trace Flags:
  14: **		26.12-13
  15: */
  16: 
  17: long
  18: rhash(d, key)
  19: register DESC   *d;
  20: char        key[MAXTUP];
  21: {
  22:     register int    i;
  23:     register char   *cp;
  24:     long        bucket;
  25:     char        tmp;
  26:     int     j, *k, knt, numeric;
  27: 
  28:     bucket = 0;
  29:     knt = 0;
  30:     for (i = 1; i <= d->reldum.relatts; i++)
  31:         if (d->relxtra[i])
  32:         {
  33:             /* form pointer to field */
  34:             cp = &key[d->reloff[i]];
  35:             numeric = d->relfrmt[i] != CHAR;
  36:             for (j = 0; j < (d->relfrml[i] & I1MASK); j++)
  37:                 if (((tmp = *cp++) != ' ') || numeric)
  38:                     addabyte(tmp, &bucket, knt++);
  39:         }
  40:     /* remove sign bit from bucket the hard way */
  41:     k = &bucket;
  42:     *k &= 077777;
  43: #	ifdef xATR3
  44:     if (tTf(19, 12))
  45:         printf("rhash:hval=%ld", bucket);
  46: #	endif
  47:     bucket %= d->reldum.relprim;
  48: #	ifdef xATR3
  49:     if (tTf(19, 12))
  50:         printf(",returning %ld\n", bucket);
  51: #	endif
  52:     return (bucket);
  53: }
  54: /*
  55: ** ADDABYTE is used to map a long key into a four byte integer.
  56: ** As bytes are added, they are first rotated, then exclusive ored
  57: ** into the existing key.
  58: */
  59: 
  60: addabyte(ch, word, knt1)
  61: char    ch;
  62: long    *word;
  63: int knt1;
  64: {
  65:     register int    knt;
  66:     long        i;
  67: 
  68:     knt = knt1;
  69:     i = ch & I1MASK;    /*get rid of any sign extension*/
  70:     knt += 8 * (knt & 3);   /*alternately add 0, 8, 16 or 24 to knt */
  71:     knt &= 037;
  72:     *word ^= (i << (knt) | i >> (32 - knt));
  73: }

Defined functions

addabyte defined in line 60; used 1 times
  • in line 38
rhash defined in line 8; used 2 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 784
Valid CSS Valid XHTML 1.0 Strict