Graphviz  2.41.20171026.1811
dtrenew.c
Go to the documentation of this file.
1 #include "dthdr.h"
2 
3 
4 /* Renew the object at the current finger.
5 **
6 ** Written by Kiem-Phong Vo (5/25/96)
7 */
8 
9 void* dtrenew(Dt_t* dt, reg void* obj)
10 {
11  reg void* key;
12  reg Dtlink_t *e, *t, **s;
13  reg Dtdisc_t* disc = dt->disc;
14 
15  UNFLATTEN(dt);
16 
17  if(!(e = dt->data->here) || _DTOBJ(e,disc->link) != obj)
18  return NIL(void*);
19 
20  if(dt->data->type&(DT_STACK|DT_QUEUE|DT_LIST))
21  return obj;
22  else if(dt->data->type&(DT_OSET|DT_OBAG) )
23  { if(!e->right ) /* make left child the new root */
24  dt->data->here = e->left;
25  else /* make right child the new root */
26  { dt->data->here = e->right;
27 
28  /* merge left subtree to right subtree */
29  if(e->left)
30  { for(t = e->right; t->left; t = t->left)
31  ;
32  t->left = e->left;
33  }
34  }
35  }
36  else /*if(dt->data->type&(DT_SET|DT_BAG))*/
37  { s = dt->data->htab + HINDEX(dt->data->ntab,e->hash);
38  if((t = *s) == e)
39  *s = e->right;
40  else
41  { for(; t->right != e; t = t->right)
42  ;
43  t->right = e->right;
44  }
45  key = _DTKEY(obj,disc->key,disc->size);
46  e->hash = _DTHSH(dt,key,disc,disc->size);
47  dt->data->here = NIL(Dtlink_t*);
48  }
49 
50  dt->data->size -= 1;
51  return (*dt->meth->searchf)(dt,(void*)e,DT_RENEW) ? obj : NIL(void*);
52 }
Dtdisc_t * disc
Definition: cdt.h:101
#define reg
Definition: dthdr.h:14
Definition: cdt.h:80
CDT_API void * dtrenew(Dt_t *, void *)
#define DT_QUEUE
Definition: cdt.h:131
#define HINDEX(n, h)
Definition: dthdr.h:36
int size
Definition: cdt.h:73
#define NIL(t)
Definition: dthdr.h:13
#define _DTHSH(dt, ky, dc, sz)
Definition: cdt.h:214
#define DT_OSET
Definition: cdt.h:127
#define DT_STACK
Definition: cdt.h:130
Definition: grammar.c:79
#define DT_OBAG
Definition: cdt.h:128
#define DT_LIST
Definition: cdt.h:129
Dtsearch_f searchf
Definition: cdt.h:60
#define UNFLATTEN(dt)
Definition: dthdr.h:38
Dtlink_t * here
Definition: cdt.h:67
Dtmethod_t * meth
Definition: cdt.h:104
int ntab
Definition: cdt.h:72
Definition: cdt.h:99
Dtdata_t * data
Definition: cdt.h:102
#define _DTKEY(o, ky, sz)
Definition: cdt.h:209
int type
Definition: cdt.h:66
#define _DTOBJ(e, lk)
Definition: cdt.h:208
#define DT_RENEW
Definition: cdt.h:145