Graphviz 14.1.3~dev.20260201.2050
Loading...
Searching...
No Matches
dtrenew.c
Go to the documentation of this file.
1#include "config.h"
2
3#include <cdt/dthdr.h>
4#include <stddef.h>
5
6/* Renew the object at the current finger.
7**
8** Written by Kiem-Phong Vo (5/25/96)
9*/
10
11void* dtrenew(Dt_t* dt, void* obj)
12{
13 void* key;
14 Dtlink_t *e, *t, **s;
15 Dtdisc_t* disc = dt->disc;
16
17 UNFLATTEN(dt);
18
19 if (!(e = dt->data.here) || _DTOBJ(e,disc->link) != obj)
20 return NULL;
21
22 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 = dtstrhash(key, disc->size);
47 dt->data.here = NULL;
48 }
49
50 --dt->data.size;
51 return dt->meth->searchf(dt, e, DT_RENEW) ? obj : NULL;
52}
#define _DTKEY(o, ky, sz)
Definition cdt.h:169
#define DT_OBAG
Definition cdt.h:121
CDT_API unsigned int dtstrhash(void *, int)
Definition dtstrhash.c:23
#define DT_RENEW
Definition cdt.h:130
#define DT_OSET
Definition cdt.h:120
#define _DTOBJ(e, lk)
Definition cdt.h:167
#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:11
static Dtdisc_t disc
Definition exparse.y:209
node NULL
Definition grammar.y:181
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:98
Dtmethod_t * meth
Definition cdt.h:102
Dtdata_t data
sharable data
Definition cdt.h:101
Dtdisc_t * disc
Definition cdt.h:100
int key
Definition cdt.h:85
int size
Definition cdt.h:86
int link
Definition cdt.h:87
Definition grammar.c:90