home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / sps / part1 / hashuid.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.4 KB  |  60 lines

  1. # include       "sps.h"
  2.  
  3. /* The hashing functions themselves ... */
  4. # define        HASHFN1( a )            (((a)*91 + 17) % MAXUSERID)
  5. # define        HASHFN2( a )            (((a) + 47) % MAXUSERID)
  6.  
  7. /*
  8. ** HASHUID - Returns a pointer to a slot in the hash table that corresponds
  9. ** to the hash table entry for `uid'. It returns a null pointer if there is
  10. ** no such slot.
  11. */
  12. struct hashtab  *hashuid ( uid )
  13.  
  14. int                             uid ;
  15.  
  16. {
  17.     register struct hashtab *hp ;
  18.     register int            i ;
  19.     register int            j ;
  20.     extern struct info      Info ;
  21.  
  22.     j = HASHFN1( uid ) ;
  23.     for ( i = 0 ; i < MAXUSERID ; i++ )
  24.     {
  25.         hp = &Info.i_hnames[ j ] ;
  26.         if ( !hp->h_uname[0] )
  27.             return ( (struct hashtab*)0 ) ;
  28.         if ( hp->h_uid == uid )
  29.             return ( hp ) ;
  30.         j = HASHFN2( j ) ;
  31.     }
  32.     return ( (struct hashtab*)0 ) ;
  33. }
  34.  
  35. /*
  36. ** HASHNEXT - Returns a pointer to the next slot in the hash table that
  37. ** may be use for storing information for `uid'. It returns a null pointer
  38. ** if there are no more free slots available.
  39. */
  40. struct hashtab  *hashnext ( uid )
  41.  
  42. int                             uid ;
  43.  
  44. {
  45.     register struct hashtab *hp ;
  46.     register int            i ;
  47.     register int            j ;
  48.     extern struct info      Info ;
  49.  
  50.     j = HASHFN1( uid ) ;
  51.     for ( i = 0 ; i < MAXUSERID ; i++ )
  52.     {
  53.         hp = &Info.i_hnames[ j ] ;
  54.         if ( !hp->h_uname[0] )
  55.             return ( hp ) ;
  56.         j = HASHFN2( j ) ;
  57.     }
  58.     return ( (struct hashtab*)0 ) ;
  59. }
  60.