home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume23
/
sps2
/
part03
/
hashuid.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-08
|
2KB
|
64 lines
# ifndef lint
static char SccsId[] = "@(#)hashuid.c 1.1\t10/1/88" ;
# endif
# include "sps.h"
/* The hashing functions themselves ... */
# define HASHFN1( a ) (((unsigned)(a)*91 + 17) % MAXUSERS)
# define HASHFN2( a ) (((unsigned)(a) + 47) % MAXUSERS)
/*
** HASHUID - Returns a pointer to a slot in the hash table that corresponds
** to the hash table entry for `uid'. It returns a null pointer if there is
** no such slot.
*/
struct hashtab *hashuid ( uid )
int uid ;
{
register struct hashtab *hp ;
register int i ;
register int j ;
extern struct info Info ;
j = HASHFN1( uid ) ;
for ( i = 0 ; i < MAXUSERS ; i++ )
{
hp = &Info.i_hnames[ j ] ;
if ( !hp->h_uname[0] )
return ( (struct hashtab*)0 ) ;
if ( hp->h_uid == uid )
return ( hp ) ;
j = HASHFN2( j ) ;
}
return ( (struct hashtab*)0 ) ;
}
/*
** HASHNEXT - Returns a pointer to the next slot in the hash table that
** may be use for storing information for `uid'. It returns a null pointer
** if there are no more free slots available.
*/
struct hashtab *hashnext ( uid )
int uid ;
{
register struct hashtab *hp ;
register int i ;
register int j ;
extern struct info Info ;
j = HASHFN1( uid ) ;
for ( i = 0 ; i < MAXUSERS ; i++ )
{
hp = &Info.i_hnames[ j ] ;
if ( !hp->h_uname[0] )
return ( hp ) ;
j = HASHFN2( j ) ;
}
return ( (struct hashtab*)0 ) ;
}