14887Schin /***********************************************************************
24887Schin * *
34887Schin * This software is part of the ast package *
4*12068SRoger.Faulkner@Oracle.COM * Copyright (c) 1985-2010 AT&T Intellectual Property *
54887Schin * and is licensed under the *
64887Schin * Common Public License, Version 1.0 *
78462SApril.Chin@Sun.COM * by AT&T Intellectual Property *
84887Schin * *
94887Schin * A copy of the License is available at *
104887Schin * http://www.opensource.org/licenses/cpl1.0.txt *
114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
124887Schin * *
134887Schin * Information and Software Systems Research *
144887Schin * AT&T Research *
154887Schin * Florham Park NJ *
164887Schin * *
174887Schin * Glenn Fowler <gsf@research.att.com> *
184887Schin * David Korn <dgk@research.att.com> *
194887Schin * Phong Vo <kpv@research.att.com> *
204887Schin * *
214887Schin ***********************************************************************/
224887Schin #include "dthdr.h"
234887Schin
244887Schin
254887Schin /* Renew the object at the current finger.
264887Schin **
274887Schin ** Written by Kiem-Phong Vo (5/25/96)
284887Schin */
294887Schin
304887Schin #if __STD_C
dtrenew(Dt_t * dt,reg Void_t * obj)314887Schin Void_t* dtrenew(Dt_t* dt, reg Void_t* obj)
324887Schin #else
334887Schin Void_t* dtrenew(dt, obj)
344887Schin Dt_t* dt;
354887Schin reg Void_t* obj;
364887Schin #endif
374887Schin {
384887Schin reg Void_t* key;
394887Schin reg Dtlink_t *e, *t, **s;
404887Schin reg Dtdisc_t* disc = dt->disc;
414887Schin
424887Schin UNFLATTEN(dt);
434887Schin
444887Schin if(!(e = dt->data->here) || _DTOBJ(e,disc->link) != obj)
454887Schin return NIL(Void_t*);
464887Schin
474887Schin if(dt->data->type&(DT_STACK|DT_QUEUE|DT_LIST))
484887Schin return obj;
494887Schin else if(dt->data->type&(DT_OSET|DT_OBAG) )
504887Schin { if(!e->right ) /* make left child the new root */
514887Schin dt->data->here = e->left;
524887Schin else /* make right child the new root */
534887Schin { dt->data->here = e->right;
544887Schin
554887Schin /* merge left subtree to right subtree */
564887Schin if(e->left)
574887Schin { for(t = e->right; t->left; t = t->left)
584887Schin ;
594887Schin t->left = e->left;
604887Schin }
614887Schin }
624887Schin }
634887Schin else /*if(dt->data->type&(DT_SET|DT_BAG))*/
644887Schin { s = dt->data->htab + HINDEX(dt->data->ntab,e->hash);
654887Schin if((t = *s) == e)
664887Schin *s = e->right;
674887Schin else
684887Schin { for(; t->right != e; t = t->right)
694887Schin ;
704887Schin t->right = e->right;
714887Schin }
724887Schin key = _DTKEY(obj,disc->key,disc->size);
734887Schin e->hash = _DTHSH(dt,key,disc,disc->size);
744887Schin dt->data->here = NIL(Dtlink_t*);
754887Schin }
764887Schin
774887Schin dt->data->size -= 1;
784887Schin return (*dt->meth->searchf)(dt,(Void_t*)e,DT_RENEW) ? obj : NIL(Void_t*);
794887Schin }
80