Debian Codegraph @

src/gen/lib/cdt/dttree__c.java

raw symbols SCIP
1 /* ========================================================================
2 * PlantUML : a free UML diagram generator
3 * ========================================================================
4 *
5 * Project Info: http://plantuml.com
6 *
7 * If you like this project or if you find it useful, you can support us at:
8 *
9 * http://plantuml.com/patreon (only 1$ per month!)
10 * http://plantuml.com/paypal
11 *
12 * This file is part of Smetana.
13 * Smetana is a partial translation of Graphviz/Dot sources from C to Java.
14 *
15 * (C) Copyright 2009-2020, Arnaud Roques
16 *
17 * This translation is distributed under the same Licence as the original C program:
18 *
19 *************************************************************************
20 * Copyright (c) 2011 AT&T Intellectual Property
21 * All rights reserved. This program and the accompanying materials
22 * are made available under the terms of the Eclipse Public License v1.0
23 * which accompanies this distribution, and is available at
24 * http://www.eclipse.org/legal/epl-v10.html
25 *
26 * Contributors: See CVS logs. Details at http://www.graphviz.org/
27 *************************************************************************
28 *
29 * THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
30 * LICENSE ("AGREEMENT"). [Eclipse Public License - v 1.0]
31 *
32 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
33 * RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
34 *
35 * You may obtain a copy of the License at
36 *
37 * http://www.eclipse.org/legal/epl-v10.html
38 *
39 * Unless required by applicable law or agreed to in writing, software
40 * distributed under the License is distributed on an "AS IS" BASIS,
41 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42 * See the License for the specific language governing permissions and
43 * limitations under the License.
44 *
45 */
46 package gen.lib.cdt;
47 import static gen.lib.cdt.dtrestore__c.dtrestore;
48 import static smetana.core.JUtils.NEQ;
49 import static smetana.core.JUtils.sizeof;
50 import static smetana.core.JUtils.strcmp;
51 import static smetana.core.JUtilsDebug.ENTERING;
52 import static smetana.core.JUtilsDebug.LEAVING;
53 import static smetana.core.Macro.N;
54 import static smetana.core.Macro.UNSUPPORTED;
55 import static smetana.core.Macro.UNSUPPORTED_INT;
56 import h.Dtcompar_f;
57 import h.ST_dt_s;
58 import h.ST_dtdisc_s;
59 import h.ST_dthold_s;
60 import h.ST_dtlink_s;
61 import h.ST_dthold_s;
62 import smetana.core.CFunction;
63 import smetana.core.CString;
64 import smetana.core.__ptr__;
65
66 public class dttree__c {
67 //1 9k44uhd5foylaeoekf3llonjq
68 // extern Dtmethod_t* Dtset
69
70
71 //1 1ahfywsmzcpcig2oxm7pt9ihj
72 // extern Dtmethod_t* Dtbag
73
74
75 //1 anhghfj3k7dmkudy2n7rvt31v
76 // extern Dtmethod_t* Dtoset
77
78
79 //1 5l6oj1ux946zjwvir94ykejbc
80 // extern Dtmethod_t* Dtobag
81
82
83 //1 2wtf222ak6cui8cfjnw6w377z
84 // extern Dtmethod_t* Dtlist
85
86
87 //1 d1s1s6ibtcsmst88e3057u9r7
88 // extern Dtmethod_t* Dtstack
89
90
91 //1 axa7mflo824p6fspjn1rdk0mt
92 // extern Dtmethod_t* Dtqueue
93
94
95 //1 ega812utobm4xx9oa9w9ayij6
96 // extern Dtmethod_t* Dtdeque
97
98
99 //1 cyfr996ur43045jv1tjbelzmj
100 // extern Dtmethod_t* Dtorder
101
102
103 //1 wlofoiftbjgrrabzb2brkycg
104 // extern Dtmethod_t* Dttree
105
106
107 //1 12bds94t7voj7ulwpcvgf6agr
108 // extern Dtmethod_t* Dthash
109
110
111 //1 9lqknzty480cy7zsubmabkk8h
112 // extern Dtmethod_t _Dttree
113
114
115 //1 bvn6zkbcp8vjdhkccqo1xrkrb
116 // extern Dtmethod_t _Dthash
117
118
119 //1 9lidhtd6nsmmv3e7vjv9e10gw
120 // extern Dtmethod_t _Dtlist
121
122
123 //1 34ujfamjxo7xn89u90oh2k6f8
124 // extern Dtmethod_t _Dtqueue
125
126
127 //1 3jy4aceckzkdv950h89p4wjc8
128 // extern Dtmethod_t _Dtstack
129
130
131
132
133 static class no_root extends RuntimeException {}
134 static class has_root extends RuntimeException {}
135 static class do_search extends RuntimeException {}
136 static class dt_delete extends RuntimeException {}
137 static class dt_insert extends RuntimeException {}
138 static class dt_next extends RuntimeException {}
139 //3 abqfzg1d1vkzk51225tcdlik5
140 //static void* dttree(Dt_t* dt, void* obj, int type)
141 public static Object dttree(ST_dt_s dt, __ptr__ obj, int type) {
142 ENTERING("abqfzg1d1vkzk51225tcdlik5","dttree");
143 try {
144 ST_dtlink_s root, t;
145 int cmp, lk, sz, ky;
146 ST_dtlink_s l, r, me=null;
147 final ST_dtlink_s link = new ST_dtlink_s();
148 Object o, k, key = null;
149 int n, minp; //, turn[(sizeof(size_t)*8 - 2)];
150 Dtcompar_f cmpf;
151 ST_dtdisc_s disc;
152 if (((dt.data.type) & 010000) !=0) { dtrestore(dt,null); }
153 disc = (ST_dtdisc_s) dt.disc; ky = disc.key;
154 sz = disc.size;
155 lk = disc.link;
156 cmpf = (Dtcompar_f) disc.comparf;
157 dt.setInt("type", dt.type&~0100000);
158 root = (ST_dtlink_s) dt.data.here;
159 if(N(obj))
160 { if(N(root) || N(type&(0000100|0000200|0000400)) )
161 return null;
162 if((type&0000100)!=0) /* delete all objects */
163 {
164 if(disc.freef!=null || disc.link < 0) {
165 do {
166 while((t = (ST_dtlink_s) root._left)!=null ) {
167 root._left = t.right;
168 t.right = root;
169 root = t;
170 }
171 t = (ST_dtlink_s) root.right;
172 if(disc.freef!=null)
173 throw new UnsupportedOperationException();
174 // (*disc->freef)(dt,(lk < 0 ? ((Dthold_t*)(root))->obj : (void*)((char*)(root) - lk) ),disc);
175 if(disc.link < 0)
176 dt.memoryf.exe(dt, root, null, disc);
177 } while((root = t)!=null );
178 }
179 dt.data.setInt("size", 0);
180 dt.data.here = null;
181 return null;
182 }
183 else /* computing largest/smallest element */
184 { if((type&0000400)!=0)
185 { while((t = (ST_dtlink_s) root.right)!=null ) {
186 root.right = t._left;
187 t._left = root;
188 root = t;
189 }
190 }
191 else /* type&DT_FIRST */
192 { while((t = (ST_dtlink_s) root._left)!=null ) {
193 root._left = t.right;
194 t.right = root;
195 root = t;
196 }
197 }
198 dt.data.here = root;
199 return (lk < 0 ? root.castTo_ST_dthold_s().obj : root.addVirtualBytes(-lk) );
200 }
201 }
202 /* note that link.right is LEFT tree and link.left is RIGHT tree */
203 l = r = link;
204 /* allow apps to delete an object "actually" in the dictionary */
205 try {
206 if(dt.meth.type == 0000010 && ((type&(0000002|0010000))!=0) ) {
207 throw new UnsupportedOperationException();
208 // { key = (void*)(sz < 0 ? *((char**)((char*)(obj)+ky)) : ((char*)(obj)+ky));
209 // for(o = (*(((Dt_t*)(dt))->searchf))((dt),(void*)(obj),0000004); o; o = (*(((Dt_t*)(dt))->searchf))((dt),(void*)(o),0000010) )
210 // { k = (void*)(sz < 0 ? *((char**)((char*)(o)+ky)) : ((char*)(o)+ky));
211 // if((cmpf ? (*cmpf)(dt,key,k,disc) : (sz <= 0 ? strcmp(key,k) : memcmp(key,k,sz)) ) != 0)
212 // break;
213 // if(o == obj)
214 // { root = dt->data->here;
215 // l->right = root->hl._left;
216 // r->hl._left = root->right;
217 // goto dt_delete;
218 // }
219 // }
220 }
221 try {
222 if(((type&(0001000|0000004|0000001|0004000))!=0))
223 { key = ((type&0001000)!=0) ? obj : (sz < 0 ? ((__ptr__)obj).addVirtualBytes(ky) : ((__ptr__)obj).addVirtualBytes(ky));
224 if(root!=null)
225 throw new do_search();
226 }
227 else if((type&0000040)!=0) {
228 throw new UnsupportedOperationException();
229 // { me = (Dtlink_t*)obj;
230 // obj = (lk < 0 ? ((Dthold_t*)(me))->obj : (void*)((char*)(me) - lk) );
231 // key = (void*)(sz < 0 ? *((char**)((char*)(obj)+ky)) : ((char*)(obj)+ky));
232 // if(root)
233 // goto do_search;
234 }
235 else if(root!=null && (lk < 0 ? (root.castTo_ST_dthold_s().obj!=null): NEQ(root.addVirtualBytes(-lk), obj)))
236 { key = (sz < 0 ? ((__ptr__)obj).addVirtualBytes(ky) : ((__ptr__)obj).addVirtualBytes(ky));
237 throw new do_search();
238 }
239 } catch (do_search do_search) {
240 // do_search:
241 if(dt.meth.type == 0000004 &&
242 (minp = dt.data.minp) != 0 && (type&(0001000|0000004))!=0)
243 { /* simple search, note that minp should be even */
244 // for(t = root, n = 0; n < minp; ++n)
245 // { k = (lk < 0 ? ((Dthold_t*)(t))->obj : (void*)((char*)(t) - lk) ); k = (void*)(sz < 0 ? *((char**)((char*)(k)+ky)) : ((char*)(k)+ky));
246 // if((cmp = (cmpf ? (*cmpf)(dt,key,k,disc) : (sz <= 0 ? strcmp(key,k) : memcmp(key,k,sz)) )) == 0)
247 // return (lk < 0 ? ((Dthold_t*)(t))->obj : (void*)((char*)(t) - lk) );
248 // else
249 // { turn[n] = cmp;
250 // if(!(t = cmp < 0 ? t->hl._left : t->right) )
251 // return ((void*)0);
252 // }
253 // }
254 // /* exceed search length, top-down splay now */
255 // for(n = 0; n < minp; n += 2)
256 // { if(turn[n] < 0)
257 // { t = root->hl._left;
258 // if(turn[n+1] < 0)
259 // { ((root)->hl._left = (t)->right, (t)->right = (root));
260 // ((r) = (r)->hl._left = (t) );
261 // root = t->hl._left;
262 // }
263 // else
264 // { ((l) = (l)->right = (t) );
265 // ((r) = (r)->hl._left = (root) );
266 // root = t->right;
267 // }
268 // }
269 // else
270 // { t = root->right;
271 // if(turn[n+1] > 0)
272 // { ((root)->right = (t)->hl._left, (t)->hl._left = (root));
273 // ((l) = (l)->right = (t) );
274 // root = t->right;
275 // }
276 // else
277 // { ((r) = (r)->hl._left = (t) );
278 // ((l) = (l)->right = (root) );
279 // root = t->hl._left;
280 // }
281 // }
282 // }
283 throw new UnsupportedOperationException("do_search1");
284 }
285 while(true) {
286 k = lk < 0 ? root.castTo_ST_dthold_s().obj : root.addVirtualBytes(-lk);
287 k = sz < 0 ? ((__ptr__)k).addVirtualBytes(ky) : ((__ptr__)k).addVirtualBytes(ky);
288 if((cmp = (cmpf!=null ? (Integer)((CFunction)cmpf).exe(dt,key,k,disc) :
289 (sz <= 0 ? strcmp((CString)key,(CString)k) : UNSUPPORTED_INT("memcmp(key,k,sz))") ))) == 0)
290 break;
291 else if(cmp < 0)
292 { if((t = (ST_dtlink_s) root._left)!=null )
293 {
294 k = lk < 0 ? t.castTo_ST_dthold_s().obj : t.addVirtualBytes(-lk);
295 k = sz < 0 ? ((__ptr__)k).addVirtualBytes(ky) : ((__ptr__)k).addVirtualBytes(ky);
296 if((cmp = (cmpf!=null ? (Integer)((CFunction)cmpf).exe(dt,key,k,disc)
297 : (sz <= 0 ? strcmp((CString)key,(CString)k) : UNSUPPORTED_INT("memcmp(key,k,sz))") ))) < 0)
298 { root._left = t.right;
299 t.right = root;
300 r._left = t;
301 r = t;
302 if(N(root = (ST_dtlink_s) t._left) )
303 break;
304 }
305 else if(cmp == 0)
306 { r._left = root;
307 r = root;
308 root = t;
309 break;
310 }
311 else /* if(cmp > 0) */
312 { l.right = t;
313 l = t;
314 r._left = root;
315 r = root;
316 if(N(root = (ST_dtlink_s) t.right) )
317 break;
318 }
319 }
320 else
321 {
322 r._left = root;
323 r = root;
324 root = null;
325 break;
326 }
327 }
328 else /* if(cmp > 0) */
329 { if ((t = (ST_dtlink_s) root.right)!=null )
330 {
331 k = (lk < 0 ? t.castTo_ST_dthold_s().obj : t.addVirtualBytes(-lk) );
332 k = sz < 0 ? ((__ptr__)k).addVirtualBytes(ky) : ((__ptr__)k).addVirtualBytes(ky);
333 if((cmp = (cmpf!=null ? (Integer)((CFunction)cmpf).exe(dt,key,k,disc)
334 : (sz <= 0 ? strcmp((CString)key,(CString)k) : UNSUPPORTED_INT("memcmp(key,k,sz))") ))) > 0)
335 {
336 root.right = t._left;
337 t._left = root;
338 l.right = t;
339 l = t;
340 if(N(root = (ST_dtlink_s) t.right ))
341 break;
342 }
343 else if(cmp == 0)
344 { l.right = root;
345 l = root;
346 root = t;
347 break;
348 }
349 else /* if(cmp < 0) */
350 { r._left = t;
351 r = t;
352 l.right = root;
353 l = root;
354 if(N(root = (ST_dtlink_s) t._left ))
355 break;
356 }
357 }
358 else
359 { l.right = root;
360 l = root;
361 root = null;
362 break;
363 }
364 }
365 }
366 }
367 if(root!=null)
368 { /* found it, now isolate it */
369 dt.setInt("type", dt.type | 0100000);
370 l.right = root._left;
371 r._left = root.right;
372 if((type&(0000004|0001000))!=0)
373 { /*has_root:*/
374 throw new has_root();
375 }
376 else if((type&0000010)!=0)
377 { root._left = link.right;
378 root.right = null;
379 link.right = root;
380 //dt_next:
381 if((root = (ST_dtlink_s) link._left)!=null )
382 { while((t = (ST_dtlink_s) root._left)!=null ) {
383 root._left = t.right;
384 t.right = root;
385 root = t;
386 }
387 link._left = root.right;
388 throw new has_root();
389 }
390 else throw new no_root();
391 }
392 else if((type&0000020)!=0) {
393 throw new UnsupportedOperationException();
394 // { root->right = link.hl._left;
395 // root->hl._left = ((Dtlink_t*)0);
396 // link.hl._left = root;
397 // dt_prev:
398 // if((root = link.right) )
399 // { while((t = root->right) )
400 // (((root)->right = (t)->hl._left, (t)->hl._left = (root)), (root) = (t));
401 // link.right = root->hl._left;
402 // goto has_root;
403 // }
404 // else goto no_root;
405 }
406 else if((type&(0000002|0010000))!=0) {
407 throw new UnsupportedOperationException();
408 // { /* taking an object out of the dictionary */
409 // dt_delete:
410 // obj = (lk < 0 ? ((Dthold_t*)(root))->obj : (void*)((char*)(root) - lk) );
411 // if(disc->freef && (type&0000002))
412 // (*disc->freef)(dt,obj,disc);
413 // if(disc->link < 0)
414 // (*dt->memoryf)(dt,(void*)root,0,disc);
415 // if((dt->data->size -= 1) < 0)
416 // dt->data->size = -1;
417 // goto no_root;
418 }
419 else if((type&(0000001|0004000))!=0)
420 { if((dt.meth.type&0000004)!=0)
421 throw new has_root();
422 else
423 {
424 root._left = null;
425 root.right = link._left;
426 link._left = root;
427 /*dt_insert: DUPLICATION*/
428 if(disc.makef!=null && (type&0000001)!=0)
429 obj = (__ptr__) disc.makef.exe(dt,obj,disc);
430 if(obj!=null)
431 {
432 if(lk >= 0)
433 root = (ST_dtlink_s) ((__ptr__)obj.addVirtualBytes(lk)).castTo(ST_dtlink_s.class);
434 else
435 {
436 root = (ST_dtlink_s)(((ST_dthold_s)dt.memoryf.exe(
437 dt,null,sizeof(ST_dthold_s.class),disc)).castTo(ST_dtlink_s.class));
438 if(root!=null)
439 root.castTo(ST_dthold_s.class).setPtr("obj", obj);
440 else if(disc.makef!=null && disc.freef!=null &&
441 ((type&0000001))!=0)
442 UNSUPPORTED("(*disc->freef)(dt,obj,disc);");
443 }
444 }
445 if(root!=null)
446 { if(dt.data.size >= 0)
447 dt.data.setInt("size", dt.data.size+1 );
448 throw new has_root();
449 }
450 else throw new UnsupportedOperationException("goto no_root");
451 }
452 }
453 else if((type&0000040)!=0) /* a duplicate */ {
454 throw new UnsupportedOperationException();
455 // { if(dt->meth->type&0000004)
456 // { if(disc->freef)
457 // (*disc->freef)(dt,obj,disc);
458 // if(disc->link < 0)
459 // (*dt->memoryf)(dt,(void*)me,0,disc);
460 // }
461 // else
462 // { me->hl._left = ((Dtlink_t*)0);
463 // me->right = link.hl._left;
464 // link.hl._left = me;
465 // dt->data->size += 1;
466 // }
467 // goto has_root;
468 }
469 }
470 else
471 { /* not found, finish up LEFT and RIGHT trees */
472 r._left = null;
473 l.right = null;
474 if((type&0000010)!=0)
475 {
476 //goto dt_next:
477 if((root = (ST_dtlink_s) link._left)!=null )
478 { while((t = (ST_dtlink_s) root._left)!=null ) {
479 root._left = t.right;
480 t.right = root;
481 root = t;
482 }
483 link._left = root.right;
484 throw new has_root();
485 }
486 else throw new no_root();
487
488 }
489 else if((type&0000020)!=0)
490 throw new UnsupportedOperationException("goto dt_prev");
491 else if((type&(0000004|0001000))!=0)
492 {
493 throw new no_root();
494 }
495 else if((type&(0000001|0004000))!=0)
496 { /*dt_insert: DUPLICATION*/
497 if(disc.makef!=null && (type&0000001)!=0)
498 obj = (__ptr__) disc.makef.exe(dt,obj,disc);
499 if(obj!=null)
500 {
501 if(lk >= 0)
502 root = (ST_dtlink_s) ((__ptr__)obj.addVirtualBytes(lk)).castTo(ST_dtlink_s.class);
503 else
504 {
505 root = (ST_dtlink_s)(((ST_dthold_s)dt.memoryf.exe(
506 dt,null,sizeof(ST_dthold_s.class),disc)).castTo(ST_dtlink_s.class));
507 if(root!=null)
508 root.castTo(ST_dthold_s.class).setPtr("obj", obj);
509 else if(disc.makef!=null && disc.freef!=null &&
510 ((type&0000001))!=0)
511 UNSUPPORTED("(*disc->freef)(dt,obj,disc);");
512 }
513 }
514 if(root!=null)
515 { if(dt.data.size >= 0)
516 dt.data.setInt("size", dt.data.size+1 );
517 throw new has_root();
518 }
519 else throw new UnsupportedOperationException("goto no_root");
520 }
521 else if((type&0000040)!=0)
522 { root = me;
523 dt.data.setInt("size", dt.data.size+1 );
524 throw new UnsupportedOperationException("goto has_root");
525 }
526 else /*if(type&DT_DELETE)*/
527 { obj = null;
528 throw new UnsupportedOperationException("goto no_root");
529 }
530 // throw new UnsupportedOperationException();
531 }
532 // return ((void*)0);
533 } catch (has_root has_root) {
534 root = (ST_dtlink_s) root.castTo(ST_dtlink_s.class);
535 root._left = link.right;
536 root.right = link._left;
537 if((dt.meth.type&0000010)!=0 && (type&(0000004|0001000))!=0 )
538 { //key = (lk < 0 ? ((Dthold_t*)(root))->obj : (void*)((char*)(root) - lk) ); key = (void*)(sz < 0 ? *((char**)((char*)(key)+ky)) : ((char*)(key)+ky));
539 throw new UnsupportedOperationException();
540 // while((t = root->hl._left) )
541 // { /* find max of left subtree */
542 // while((r = t->right) )
543 // (((t)->right = (r)->hl._left, (r)->hl._left = (t)), (t) = (r));
544 // root->hl._left = t;
545 // /* now see if it's in the same group */
546 // k = (lk < 0 ? ((Dthold_t*)(t))->obj : (void*)((char*)(t) - lk) ); k = (void*)(sz < 0 ? *((char**)((char*)(k)+ky)) : ((char*)(k)+ky));
547 // if((cmpf ? (*cmpf)(dt,key,k,disc) : (sz <= 0 ? strcmp(key,k) : memcmp(key,k,sz)) ) != 0)
548 // break;
549 // (((root)->hl._left = (t)->right, (t)->right = (root)), (root) = (t));
550 // }
551 }
552 dt.data.here = root;
553 return (lk < 0 ? root.castTo_ST_dthold_s().obj : root.addVirtualBytes(-lk));
554 } catch (no_root no_root) {
555 while((t = (ST_dtlink_s) r._left)!=null)
556 r = t;
557 r._left = link.right;
558 dt.data.here = link._left;
559 return (type&0000002)!=0 ? obj : null;
560 }
561 throw new UnsupportedOperationException();
562 } finally {
563 LEAVING("abqfzg1d1vkzk51225tcdlik5","dttree");
564 }
565 }
566
567
568 //1 9g22bw0wprm2n836sva9a545j
569 // static Dtmethod_t _Dtoset =
570
571
572 //1 6lntjtw57dbb52lukeu9qbjm0
573 // static Dtmethod_t _Dtobag =
574
575
576 //1 23jnfpje5fw0aejl101d0mofi
577 // Dtmethod_t* Dtoset = &_Dtoset
578
579
580 //1 b8q5rjkvf93u0f27esfu3h9ay
581 // Dtmethod_t* Dtobag = &_Dtobag
582
583
584 //1 5kf1n1yhdy9ojgc0mc3pyowaz
585 // Dtmethod_t _Dttree =
586 /*public static final __struct__<_dtmethod_s> _Dttree = JUtils.from(_dtmethod_s.class);
587 static {
588 _Dttree.setPtr("searchf", function(dttree__c.class, "dttree"));
589 _Dttree.setInt("type", 0000004);
590 }*/
591
592 //1 bvfgwxg0ik8j0au3xhv5ear7h
593 // Dtmethod_t* Dtorder = &_Dttree
594
595
596 //1 avyrqfvu00yyj95dihtoiwmao
597 // Dtmethod_t* Dttree = &_Dttree
598 //public static _dtmethod_s Dttree = _Dttree.amp();
599 }