1*4887Schin /*********************************************************************** 2*4887Schin * * 3*4887Schin * This software is part of the ast package * 4*4887Schin * Copyright (c) 1985-2007 AT&T Knowledge Ventures * 5*4887Schin * and is licensed under the * 6*4887Schin * Common Public License, Version 1.0 * 7*4887Schin * by AT&T Knowledge Ventures * 8*4887Schin * * 9*4887Schin * A copy of the License is available at * 10*4887Schin * http://www.opensource.org/licenses/cpl1.0.txt * 11*4887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 12*4887Schin * * 13*4887Schin * Information and Software Systems Research * 14*4887Schin * AT&T Research * 15*4887Schin * Florham Park NJ * 16*4887Schin * * 17*4887Schin * Glenn Fowler <gsf@research.att.com> * 18*4887Schin * David Korn <dgk@research.att.com> * 19*4887Schin * Phong Vo <kpv@research.att.com> * 20*4887Schin * * 21*4887Schin ***********************************************************************/ 22*4887Schin #include "dthdr.h" 23*4887Schin 24*4887Schin 25*4887Schin /* Renew the object at the current finger. 26*4887Schin ** 27*4887Schin ** Written by Kiem-Phong Vo (5/25/96) 28*4887Schin */ 29*4887Schin 30*4887Schin #if __STD_C 31*4887Schin Void_t* dtrenew(Dt_t* dt, reg Void_t* obj) 32*4887Schin #else 33*4887Schin Void_t* dtrenew(dt, obj) 34*4887Schin Dt_t* dt; 35*4887Schin reg Void_t* obj; 36*4887Schin #endif 37*4887Schin { 38*4887Schin reg Void_t* key; 39*4887Schin reg Dtlink_t *e, *t, **s; 40*4887Schin reg Dtdisc_t* disc = dt->disc; 41*4887Schin 42*4887Schin UNFLATTEN(dt); 43*4887Schin 44*4887Schin if(!(e = dt->data->here) || _DTOBJ(e,disc->link) != obj) 45*4887Schin return NIL(Void_t*); 46*4887Schin 47*4887Schin if(dt->data->type&(DT_STACK|DT_QUEUE|DT_LIST)) 48*4887Schin return obj; 49*4887Schin else if(dt->data->type&(DT_OSET|DT_OBAG) ) 50*4887Schin { if(!e->right ) /* make left child the new root */ 51*4887Schin dt->data->here = e->left; 52*4887Schin else /* make right child the new root */ 53*4887Schin { dt->data->here = e->right; 54*4887Schin 55*4887Schin /* merge left subtree to right subtree */ 56*4887Schin if(e->left) 57*4887Schin { for(t = e->right; t->left; t = t->left) 58*4887Schin ; 59*4887Schin t->left = e->left; 60*4887Schin } 61*4887Schin } 62*4887Schin } 63*4887Schin else /*if(dt->data->type&(DT_SET|DT_BAG))*/ 64*4887Schin { s = dt->data->htab + HINDEX(dt->data->ntab,e->hash); 65*4887Schin if((t = *s) == e) 66*4887Schin *s = e->right; 67*4887Schin else 68*4887Schin { for(; t->right != e; t = t->right) 69*4887Schin ; 70*4887Schin t->right = e->right; 71*4887Schin } 72*4887Schin key = _DTKEY(obj,disc->key,disc->size); 73*4887Schin e->hash = _DTHSH(dt,key,disc,disc->size); 74*4887Schin dt->data->here = NIL(Dtlink_t*); 75*4887Schin } 76*4887Schin 77*4887Schin dt->data->size -= 1; 78*4887Schin return (*dt->meth->searchf)(dt,(Void_t*)e,DT_RENEW) ? obj : NIL(Void_t*); 79*4887Schin } 80