aabinary(ru,vi,li,s,len,ex)
	char *s;
	int *vi;
{
struct node *p, *op, *r, *st, **pp, *gr;
	char *cp; int *xp;
	gr = 0;
	pp = &(aaroot[ru]);
 while (*pp)
	{
	p  = *pp;
	switch(aacomp(p->aakey, vi, li, s))
		{
		case '<': small:
			pp= &(p->rp);
			break;
		case '>':
			pp= &(p->lp);
			gr = p;
			break;
		case '=':
			if (ex == 2)
				goto small;
			if (ex >= 0)
				return(p->aadata);
			cfree (p->aadata, len, 1);
			cfree(p->aakey, aaclen(p->aakey)+ li*sizeof(li), 1);
			if (p->rp == 0)
				*pp = p->lp;
			else
			{
			r = p->rp;
			if (r->lp == 0)
				{
				r->lp = p->lp;
				*pp = r;
				}
			else
			{
			st = r->lp;
			while (st->lp != 0)
				{
				r = st;
				st = r->lp;
				}
			st->lp = p->lp;
			r->lp = st->rp;
			st->rp = p->rp;
			*pp = st;
			}
			}
			cfree (p, sizeof(**aaroot), 1);
			return(0);
		}
	op=p;
	}
/* not there */
if (ex==2)
	return (gr ? gr->aakey : 0);
if (ex != 0) return(0);
p = *pp= calloc(1, sizeof(**aaroot));
p->aakey = calloc(aaclen(s)+li*sizeof(li),1);
xp = p->aakey;
while (li--)
	*xp++ = *vi++;
cp=xp;
while (*cp++ = *s++);
p->aadata = calloc(len,1);
cp = p->aadata;
while (len--)
  *cp++ = 0;
p->rp = p->lp = 0;
return(p->aadata);
}
