USG_PG3/usr/source/agen/aahash.c

Compare this file to the similar file:
Show the results in this format:

int aatsize, aapr1, aapr2;
aahash(tbl,vi,li,s,len,ex)
	char *s;
	int *vi;
	struct hnode tbl[];
{
struct hnode *p, *op, *r, *st;
	char *cp;
	int i, key, c, p1, p2, q1, *v, l, *ip, k;
cp = s;
key =0;
v = vi; l = li;
while (l--)
	key = key + (key<<5) + *v++;
while (c = *cp++)
	key = key + (key<<5) + c;
key =& 077777;
q1 = 0;
p1 = key%aapr1;
p2 = key%aapr2;
if (p2==0) p2=17;
for(i=0; i<aatsize; i++)
	{
	if (tbl[p1].aakey==0)
		{ /* new item */
		if (ex ==0)
			{
			if(q1) p1=q1;
			ip = tbl[p1].aakey =
				calloc(aaclen(s)+li*sizeof(li),1);
			v = vi;
			for(l=li; li > 0 ; li--)
				*ip++ = *v++;
			for(cp=ip; *cp++ = *s++;);
			cp = tbl[p1].aadata = calloc(len,1);
			while (len--)
				*cp++ = 0;
			return(tbl[p1].aadata);
			}
		else
		if (ex == 2)
			{
			for (p1=0; p1 <aatsize; p1++)
				if ((k=tbl[p1].aakey) && k != -1)
					return(k);
			return(0);
			}
		else
			return(0);
		}
	else if (tbl[p1].aakey== -1)
		{
		if (q1==0) q1=p1;
		}
	else
	if(aacomp(tbl[p1].aakey, vi,li,s)== '=')
		{
		if (ex == 2)
			{
			while (++p1 < aatsize)
				if ((k=tbl[p1].aakey) && k!= -1)
					return(k);
			return(0);
				if (p1 >= aatsize)
					return(0);
			return(tbl[p1].aakey);
			}
		if (ex>=0)
			return(tbl[p1].aadata);
		else
			{
			cfree(tbl[p1].aakey,0,0);
			cfree(tbl[p1].aadata,0,0);
			tbl[p1].aakey= -1;
			}
		}
	p1 = (p1+p2)%aatsize;
	}
printf(2, "hash table full\n");
exit();
}