Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
dtrenew.c
Go to the documentation of this file.
1#include <cdt/dthdr.h>
2#include <stddef.h>
3
4/* Renew the object at the current finger.
5**
6** Written by Kiem-Phong Vo (5/25/96)
7*/
8
9void* dtrenew(Dt_t* dt, void* obj)
10{
11 void* key;
12 Dtlink_t *e, *t, **s;
13 Dtdisc_t* disc = dt->disc;
14
15 UNFLATTEN(dt);
16
17 if (!(e = dt->data.here) || _DTOBJ(e,disc->link) != obj)
18 return NULL;
19
20 if (dt->data.type & (DT_OSET|DT_OBAG))
21 { if(!e->right ) /* make left child the new root */
22 dt->data.here = e->left;
23 else /* make right child the new root */
24 { dt->data.here = e->right;
25
26 /* merge left subtree to right subtree */
27 if(e->left)
28 { for(t = e->right; t->left; t = t->left)
29 ;
30 t->left = e->left;
31 }
32 }
33 }
34 else // if (dt.data->type & (DT_SET|DT_BAG))
35 { s = dt->data.htab + HINDEX(dt->data.ntab, e->hash);
36 if((t = *s) == e)
37 *s = e->right;
38 else
39 { for(; t->right != e; t = t->right)
40 ;
41 t->right = e->right;
42 }
43 key = _DTKEY(obj,disc->key,disc->size);
44 e->hash = dtstrhash(key, disc->size);
45 dt->data.here = NULL;
46 }
47
48 --dt->data.size;
49 return dt->meth->searchf(dt, e, DT_RENEW) ? obj : NULL;
50}
#define _DTKEY(o, ky, sz)
Definition cdt.h:169
#define DT_OBAG
Definition cdt.h:122
CDT_API unsigned int dtstrhash(void *, int)
Definition dtstrhash.c:21
#define DT_RENEW
Definition cdt.h:131
#define DT_OSET
Definition cdt.h:121
#define _DTOBJ(e, lk)
Definition cdt.h:168
#define HINDEX(n, h)
Definition dthdr.h:25
#define UNFLATTEN(dt)
Definition dthdr.h:27
void * dtrenew(Dt_t *dt, void *obj)
Definition dtrenew.c:9
static Dtdisc_t disc
Definition exparse.y:209
node NULL
Definition grammar.y:163
int size
Definition cdt.h:79
Dtlink_t * here
Definition cdt.h:73
int type
Definition cdt.h:72
int ntab
Definition cdt.h:78
Dtsearch_f searchf
Definition cdt.h:66
Definition cdt.h:100
Dtmethod_t * meth
Definition cdt.h:103
Dtdata_t data
sharable data
Definition cdt.h:102
Dtdisc_t * disc
Definition cdt.h:101
int key
Definition cdt.h:85
int size
Definition cdt.h:86
int link
Definition cdt.h:87
Definition grammar.c:93