/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#include "dthdr.h"
** dt: dictionary being searched
** obj: the object to look for.
** type: search type.
**
** Written by Kiem-Phong Vo (5/25/96)
*/
typedef struct _dttree_s
} Dttree_t;
#ifdef CDT_DEBUG
{
int k, rv;
return -1;
for(k = 0; k < lev; ++k)
*endb++ = '(';
*endb++ = ')';
*endb++ = ':';
*endb++ = ' ';
*endb++ = '<';
else obj = "NIL";
*endb++ = '>';
*endb++ = ' ';
*endb++ = '<';
else obj = "NIL";
*endb++ = '>';
*endb++ = '\n';
return 0;
}
#endif
/* terminal object: DT_FIRST|DT_LAST */
#if __STD_C
#else
int type;
#endif
{
}
else /* type&DT_FIRST */
}
}
/* DT_CLEAR */
#if __STD_C
#else
#endif
{
{ do
} while((root = t) );
}
}
#if __STD_C
#else
int type;
#endif
{
{ while((t = r->_left) ) /* no left children */
RROTATE(r,t);
}
}
if(type&DT_FLATTEN)
else
}
}
else /* if(type&DT_RESTORE) */
for(r = list; r; r = t)
{ t = r->_rght;
}
}
}
#if __STD_C /* compute tree depth and number of nodes */
#else
#endif
{
if(!root) /* nothing to do */
return 0;
return -1;
if(st)
if(lev < DT_MAXSIZE)
}
}
size = 1;
return -1;
else size += z;
return -1;
else size += z;
return size;
}
#if __STD_C
#else
#endif
{
if(!st)
else
}
}
#if __STD_C /* make a list into a balanced tree */
#else
#endif
{
ssize_t n;
if(size <= 2)
return list;
l = l->_rght;
return mid;
}
{
size += 1;
}
}
{
{ while((r = l->_rght) ) /* get the max elt of left subtree */
LROTATE(l,r);
break;
}
}
else
{ while((l = r->_left) ) /* get the min elt of right subtree */
RROTATE(r,l);
break;
}
}
return list;
}
{ while((r = t->_rght) ) /* make t the maximum element */
LROTATE(t,r);
break;
}
root = t;
}
else /* add t to equal list in an order-preserving manner */
}
}
{ while((l = t->_left) ) /* make t the minimum element */
RROTATE(t,l);
break;
}
root = t;
}
else /* add t to equal list in an order-preserving manner */
}
}
if(!root) /* always set a non-trivial root */
}
if(list) /* add the rest of the equal-list to the proper subtree */
}
else
}
}
return root;
}
#if __STD_C
#else
int type;
#endif
{
int cmp;
if(!(type&DT_OPERATIONS) )
}
if(!obj) /* from here on, an object prototype is required */
}
else
}
}
l = r = &link; /* link._rght(_left) will be LEFT(RIGHT) tree after splaying */
{ while(1)
break;
else if(cmp < 0)
rlink(r,t);
break;
}
else if(cmp == 0)
root = t;
break;
}
else /* if(cmp > 0) */
{ llink(l,t);
break;
}
}
else
break;
}
}
else /* if(cmp > 0) */
llink(l,t);
break;
}
else if(cmp == 0)
root = t;
break;
}
else /* if(cmp < 0) */
{ rlink(r,t);
break;
}
}
else
break;
}
}
}
}
if(root)
}
{ has_root: /* reconstitute the tree */
}
goto has_root;
}
else goto no_root;
}
goto has_root;
}
else goto no_root;
}
goto dt_delete;
else
}
}
{ dt_delete: /* remove an object from the dictionary */
goto no_root;
}
goto has_root;
}
else
goto dt_insert;
}
}
else
}
goto has_root;
}
}
else /* no matching object, tree has been split to LEFT&RIGHT subtrees */
{ no_root:
else
{ while((t = l->_rght) ) /* maximize root of LEFT tree */
{ if(t->_rght)
LLSHIFT(l,t);
else LROTATE(l,t);
}
}
}
goto dt_next;
goto dt_prev;
goto no_root;
}
{ dt_insert:
goto no_root;
}
else
goto has_root;
}
}
goto has_root;
}
}
return obj;
}
{
{ if(tree) /* already initialized */
return 0;
return -1;
}
return 1;
}
{ if(!tree)
return 0;
return 0;
}
return 0;
}
else return 0;
}
#if _UWIN
{
return (dt && dt->meth && (dt->meth->type & DT_ORDERED)) ? (Void_t*)((Dttree_t*)dt->data)->root : NIL(Void_t*);
}
#endif
/* make this method available */
/* backwards compatibility */
#if defined(__EXPORT__)
#endif
#ifdef NoF
#endif