summaryrefslogtreecommitdiff
path: root/support/dktools/dk3sto.ctr
blob: 5c160687d3e4e5e1e7111e6d56f2caeb065ce8ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
%%	options

copyright owner	=	Dirk Krause
copyright year	=	2011-xxxx
license		=	bsd



%%	header

#include "dk3conf.h"
#include "dk3types.h"

#ifdef __cplusplus
extern "C" {
#endif

/**	Create new storage.
	@param	app	Application structure for diagnostics, may be NULL.
	@return	Pointer to new storage on succcess, NULL on error.
	Use dk3sto_close() to destroy the storage when done with it.
*/
dk3_sto_t *
dk3sto_open_app(dk3_app_t *app);

/**	Destroy storage, release memory.
	@param	st	Storage to destroy.
*/
void
dk3sto_close(dk3_sto_t *st);

/**	Remove all pointers from a storage.
	@param	st	Storage.
*/
void
dk3sto_remove_all(dk3_sto_t *st);

/**	Remove one pointer from storage.
	@param	st	Storage.
	@param	o	Object pointer to remove.
	@return	1 on success, 0 on error (not found).
*/
int
dk3sto_remove(dk3_sto_t *st, void *o);

/**	Add object pointer to storage.
	@param	st	Storage.
	@param	o	Object pointer to add.
	@return	1 on success, 0 on error (not enough memory).
*/
int
dk3sto_add(dk3_sto_t *st, void *o);

/**	Create iterator for storage.
	@param	st	Storage.
	@return	Pointer to new iterator on success, NULL on error.
	Use dk3sto_it_close() to destroy the iterator when done with it.
	When closing/destroying a storage all iterators for that
	storage are destroyed automatically.
*/
dk3_sto_it_t *
dk3sto_it_open(dk3_sto_t *st);

/**	Destroy iterator.
	@param	it	Iterator to destroy.
*/
void
dk3sto_it_close(dk3_sto_it_t *it);

/**	Reset iterator (next call to dk3sto_it_next() will return the
	first object pointer.
	@param	it	Iterator.
*/
void
dk3sto_it_reset(dk3_sto_it_t *it);

/**	Return next object pointer.
	@param	it	Iterator.
	@return	Pointer to next object on success, NULL on error
	(no more pointers available).
*/
void *
dk3sto_it_next(dk3_sto_it_t *it);

/**	Find a pointer exactly.
	@param	i	Iterator.
	@param	o	Object pointer.
	@return	Object pointer on success, NULL on error (object not found).
	The next calls to dk3sto_it_next() will return pointers to objects
	after the specified object \a o.
*/
void *
dk3sto_it_find_exact(dk3_sto_it_t *i, void const *o);

/**	Find object pointer for object evaluating equally to \a o.
	@param	i	Iterator.
	@param	o	Object pointer.
	@param	cr	Comparison criteria.
	@return	Object pointer on success, NULL on error (no such object).
*/
void *
dk3sto_it_find_like(dk3_sto_it_t *i, void const *o, int cr);

/**	Set evaluation function.
	@param	st	Storage.
	@param	f	Function evaluating a pointer to a char.
	@param	cr	Evaluation criteria.
	@return	1 on success, 0 on error.
*/
int
dk3sto_set_eval_c(dk3_sto_t *st, dk3_fct_eval_c_t *f, int cr);

/**	Set evaluation function.
	@param	st	Storage.
	@param	f	Function evaluating a pointer to an unsigned char.
	@param	cr	Evaluation criteria.
	@return	1 on success, 0 on error.
*/
int
dk3sto_set_eval_uc(dk3_sto_t *st, dk3_fct_eval_uc_t *f, int cr);

/**	Set evaluation function.
	@param	st	Storage.
	@param	f	Function evaluating a pointer to a short.
	@param	cr	Evaluation criteria.
	@return	1 on success, 0 on error.
*/
int
dk3sto_set_eval_s(dk3_sto_t *st, dk3_fct_eval_s_t *f, int cr);

/**	Set evaluation function.
	@param	st	Storage.
	@param	f	Function evaluating a pointer to an unsigned short.
	@param	cr	Evaluation criteria.
	@return	1 on success, 0 on error.
*/
int
dk3sto_set_eval_us(dk3_sto_t *st, dk3_fct_eval_us_t *f, int cr);

/**	Set evaluation function.
	@param	st	Storage.
	@param	f	Function evaluating a pointer to an int.
	@param	cr	Evaluation criteria.
	@return	1 on success, 0 on error.
*/
int
dk3sto_set_eval_i(dk3_sto_t *st, dk3_fct_eval_i_t *f, int cr);

/**	Set evaluation function.
	@param	st	Storage.
	@param	f	Function evaluating a pointer to an unsigned int.
	@param	cr	Evaluation criteria.
	@return	1 on success, 0 on error.
*/
int
dk3sto_set_eval_ui(dk3_sto_t *st, dk3_fct_eval_ui_t *f, int cr);

/**	Set evaluation function.
	@param	st	Storage.
	@param	f	Function evaluating a pointer to a long.
	@param	cr	Evaluation criteria.
	@return	1 on success, 0 on error.
*/
int
dk3sto_set_eval_l(dk3_sto_t *st, dk3_fct_eval_l_t *f, int cr);

/**	Set evaluation function.
	@param	st	Storage.
	@param	f	Function evaluating a pointer to an unsigned long.
	@param	cr	Evaluation criteria.
	@return	1 on success, 0 on error.
*/
int
dk3sto_set_eval_ul(dk3_sto_t *st, dk3_fct_eval_ul_t *f, int cr);

/**	Set evaluation function.
	@param	st	Storage.
	@param	f	Function evaluating a pointer to a float.
	@param	cr	Evaluation criteria.
	@return	1 on success, 0 on error.
*/
int
dk3sto_set_eval_f(dk3_sto_t *st, dk3_fct_eval_f_t *f, int cr);

/**	Set evaluation function.
	@param	st	Storage.
	@param	f	Function evaluating a pointer to a double.
	@param	cr	Evaluation criteria.
	@return	1 on success, 0 on error.
*/
int
dk3sto_set_eval_d(dk3_sto_t *st, dk3_fct_eval_d_t *f, int cr);

/**	Set comparison function.
	@param	st	Storage.
	@param	f	Function comparing two object pointers.
	@param	cr	Comparison criteria.
	@return	1 on success, 0 on error.
*/
int
dk3sto_set_comp(dk3_sto_t *st, dk3_fct_comp_t *f, int cr);

/**	Allow use of tree structures.
	This function must be called before adding any data.
	@param	st	Storage.
	@param	ok	Flag: Trees may be used.
	@return	1 on success, 0 on error.
*/
int
dk3sto_use_trees(dk3_sto_t *st,int ok);

/**	Find object pointer at the trees root.
	@param	s	Storage.
*/
void *
dk3sto_find_root(dk3_sto_t *s);

/**	Find object pointer for the parent node
	of the last found object.
	@param	i	Iterator.
	@return	Object pointer on success, NULL on error.
*/
void *
dk3sto_it_find_parent(dk3_sto_it_t *i);

/**	Find object pointer for node on left child of the last found object.
	@param	i	Iterator.
	@return	Object pointer on success, NULL on error.
*/
void *
dk3sto_it_find_left(dk3_sto_it_t *i);

/**	Find object pointer for node on right child of the last found object.
	@param	i	Iterator.
	@return	Object pointer on success, NULL on error.
*/
void *
dk3sto_it_find_right(dk3_sto_it_t *i);

/**	Find object pointer at the trees root.
	@param	i	Iterator.
*/
void *
dk3sto_it_find_root(dk3_sto_it_t *i);



#ifdef __cplusplus
}
#endif



%%	module

#include "dk3all.h"



$(trace-include)



/**	Comparison criteria: Do not compare the objects (unsorted storage).
*/
#define DK3STO_COMPARE_NONE		0

/**     Comparison criteria: Use comparison function.
*/
#define DK3STO_COMPARE_FCT		1

/**     Comparison criteria: Evaluate objects to char values.
*/
#define DK3STO_COMPARE_CHAR		2

/**     Comparison criteria: Evaluate objects to unsigned char values.
*/
#define DK3STO_COMPARE_UCHAR		3

/**     Comparison criteria: Evaluate objects to short values.
*/
#define DK3STO_COMPARE_SHORT		4

/**     Comparison criteria: Evaluate objects to unsigned short values.
*/
#define DK3STO_COMPARE_USHORT		5

/**     Comparison criteria: Evaluate objects to int values.
*/
#define DK3STO_COMPARE_INT		6

/**     Comparison criteria: Evaluate objects to unsigned int values.
*/
#define DK3STO_COMPARE_UINT		7

/**     Comparison criteria: Evaluate objects to long values.
*/
#define DK3STO_COMPARE_LONG		8

/**     Comparison criteria: Evaluate objects to unsigned long values.
*/
#define DK3STO_COMPARE_ULONG		9

/**     Comparison criteria: Evaluate objects to float values.
*/
#define DK3STO_COMPARE_FLOAT		10

/**	Comparison criteria: Evaluate objects to double values.
*/
#define DK3STO_COMPARE_DOUBLE		11



/*
  GENERAL STATIC FUNCTIONS
*/

/**	Initialize storage node for object.
	@param	n	Storage node.
	@param	o	Object.
	@param	s	Storage.
	@param	crit	Comparison/evaluation criteria used by storage.
*/
static void
dk3sto_node_init_for_object(dk3_sto_node_t *n, void *o, dk3_sto_t *s, int crit)
{
  $? "+ dk3sto_node_init_for_object %!8s %!8s %!8s %d", TR_8PTR(n), TR_8PTR(o), TR_8PTR(s), crit
  n->p = n->l = n->r = NULL;
  n->b = n->w = 0;
  n->o = o;
  switch(s->h) {
    case DK3STO_COMPARE_CHAR: (n->v).c = (*((s->e).c))(o,crit); break;
    case DK3STO_COMPARE_UCHAR: (n->v).uc = (*((s->e).uc))(o,crit); break;
    case DK3STO_COMPARE_SHORT: (n->v).s = (*((s->e).s))(o,crit); break;
    case DK3STO_COMPARE_USHORT: (n->v).us = (*((s->e).us))(o,crit); break;
    case DK3STO_COMPARE_INT: (n->v).i = (*((s->e).i))(o,crit); break;
    case DK3STO_COMPARE_UINT: (n->v).ui = (*((s->e).ui))(o,crit); break;
    case DK3STO_COMPARE_LONG: (n->v).l = (*((s->e).l))(o,crit); break;
    case DK3STO_COMPARE_ULONG: (n->v).ul = (*((s->e).ul))(o,crit); break;
    case DK3STO_COMPARE_FLOAT: (n->v).f = (*((s->e).f))(o,crit); break;
    case DK3STO_COMPARE_DOUBLE: (n->v).d = (*((s->e).d))(o,crit); break;
  } $? "- dk3sto_node_init_for_object"
}



/**	Copy data from one storage node to another.
	@param	d	Destination node.
	@param	s	Source node.
	@param	st	Storage.
*/
static void
dk3sto_node_data_copy(dk3_sto_node_t *d, dk3_sto_node_t *s, dk3_sto_t *st)
{
  $? "+ dk3sto_node_data_copy %!8s %!8s", TR_8PTR(d), TR_8PTR(s)
  d->o = s->o;
  switch(st->h) {
    case DK3STO_COMPARE_CHAR:   (d->v).c  = (s->v).c ; break;
    case DK3STO_COMPARE_UCHAR:  (d->v).uc = (s->v).uc ; break;
    case DK3STO_COMPARE_SHORT:  (d->v).s  = (s->v).s ; break;
    case DK3STO_COMPARE_USHORT: (d->v).us = (s->v).us ; break;
    case DK3STO_COMPARE_INT:    (d->v).i  = (s->v).i ; break;
    case DK3STO_COMPARE_UINT:   (d->v).ui = (s->v).ui ; break;
    case DK3STO_COMPARE_LONG:   (d->v).l  = (s->v).l ; break;
    case DK3STO_COMPARE_ULONG:  (d->v).ul = (s->v).ul ; break;
    case DK3STO_COMPARE_FLOAT:  (d->v).f  = (s->v).f ; break;
    case DK3STO_COMPARE_DOUBLE: (d->v).d  = (s->v).d ; break;
  }
  $? "- dk3sto_node_data_copy"
}



/**	Compare two storage nodes.
	@param	l	Left node.
	@param	r	Right node.
	@param	s	Storage.
	@param	c	Comparison criteria.
	@return	Comparison result.
*/
static int
dk3sto_node_compare(dk3_sto_node_t *l, dk3_sto_node_t *r, dk3_sto_t *s, int c)
{
  int back = 0;
  $? "+ dk3sto_node_compare %!8s %!8s %!8s %d", TR_8PTR(l), TR_8PTR(r), TR_8PTR(s), c
  switch(s->h) {
    case DK3STO_COMPARE_FCT: { $? ". compare by function"
      back = (*((s->e).comp))((void *)(l->o),(void *)(r->o),c);
      if(back < 0) back = -1;
      if(back > 0) back =  1;
    } break;
    case DK3STO_COMPARE_CHAR: { $? ". compare character"
      if(((l->v).c) > ((r->v).c)) { back = 1; }
      else { if(((l->v).c) < ((r->v).c)) { back = -1; } }
    } break;
    case DK3STO_COMPARE_UCHAR: { $? ". compare unsigned character"
      if(((l->v).uc) > ((r->v).uc)) { back = 1; }
      else { if(((l->v).uc) < ((r->v).uc)) { back = -1; } }
    } break;
    case DK3STO_COMPARE_SHORT: { $? ". compare short"
      if(((l->v).s) > ((r->v).s)) { back = 1; }
      else { if(((l->v).s) < ((r->v).s)) { back = -1; } }
    } break;
    case DK3STO_COMPARE_USHORT: { $? ". compare unsigned short"
      if(((l->v).us) > ((r->v).us)) { back = 1; }
      else { if(((l->v).us) < ((r->v).us)) { back = -1; } }
    } break;
    case DK3STO_COMPARE_INT: { $? ". compare int"
      if(((l->v).i) > ((r->v).i)) { back = 1; }
      else { if(((l->v).i) < ((r->v).i)) { back = -1; } }
    } break;
    case DK3STO_COMPARE_UINT: { $? ". compare unsigned int"
      if(((l->v).ui) > ((r->v).ui)) { back = 1; }
      else { if(((l->v).ui) < ((r->v).ui)) { back = -1; } }
    } break;
    case DK3STO_COMPARE_LONG: { $? ". compare long"
      if(((l->v).l) > ((r->v).l)) { back = 1; }
      else { if(((l->v).l) < ((r->v).l)) { back = -1; } }
    } break;
    case DK3STO_COMPARE_ULONG: { $? ". compare unsigned long"
      if(((l->v).ul) > ((r->v).ul)) { back = 1; }
      else { if(((l->v).ul) < ((r->v).ul)) { back = -1; } }
    } break;
    case DK3STO_COMPARE_FLOAT: { $? ". compare float"
      if(((l->v).f) > ((r->v).f)) { back = 1; }
      else { if(((l->v).f) < ((r->v).f)) { back = -1; } }
    } break;
    case DK3STO_COMPARE_DOUBLE: { $? ". compare double"
      if(((l->v).d) > ((r->v).d)) { back = 1; }
      else { if(((l->v).d) < ((r->v).d)) { back = -1; } }
    } break;
  } $? "- dk3sto_node_compare %d", back
  return back;
}



/*
	UNSORTED DATA HANDLING
*/

/**	Remove node from an unsorted storage.
	@param	ro	Root node.
	@param	n	Node to remove.
	@return	New root node.
*/
static dk3_sto_node_t *
dk3sto_unsorted_remove(dk3_sto_node_t *ro, dk3_sto_node_t *n)
{
  dk3_sto_node_t	*back = NULL;	
  dk3_sto_node_t	*l = NULL;	/* Left element. */
  dk3_sto_node_t	*r = NULL;	/* Right element. */
  $? "+ dk3sto_unsorted_remove %s %s", TR_PTR(ro), TR_PTR(n)
  back = ro;
  l = n->l; r = n->r;
  if(r) {
    r->l = l;
  }
  if(l) {
    l->r = r;
  } else {
    back = r;
  } $? "- dk3sto_unsorted_remove %!8s", TR_8PTR(back)
  return back;
}



/**	Add node to an unsorted storage.
	@param	r	Old root node.
	@param	n	Node to add.
	@return	New root node or NULL.
*/
static dk3_sto_node_t *
dk3sto_unsorted_add(dk3_sto_node_t *r, dk3_sto_node_t *n)
{
  dk3_sto_node_t *back;
  $? "+ dk3sto_unsorted_add %!8s %!8s", TR_8PTR(r), TR_8PTR(n)
  back = n;
  n->r = r;
  if(r) {
    r->l = n;
  } $? "- dk3sto_unsorted_add %!8s", TR_8PTR(back)
  return back;
}



/**	Release all nodes in an unsorted storage.
	@param	r	Root node.
*/
static void
dk3sto_unsorted_release_all_nodes(dk3_sto_node_t *r)
{
  dk3_sto_node_t	*c;	/* Current element. */
  dk3_sto_node_t	*n;	/* Next element. */
  $? "+ dk3sto_unsorted_release_all_nodes %!8s", TR_8PTR(r)
  c = r;
  while(c) {
    n = c->r;
    c->p = c->l = c->r = NULL;
    c->o = NULL;
    c->b = c->w = 0;
    dk3_delete(c) ;
    c = n;
  }
  $? "- dk3sto_unsorted_release_all_nodes"
}



/**	Find next node in an unsorted storage.
	@param	n	Current node.
	@param	r	Root node.
	@return	Pointer to next node or NULL.
*/
static dk3_sto_node_t *
dk3sto_unsorted_find_next_node(dk3_sto_node_t *n, dk3_sto_node_t *r)
{
  dk3_sto_node_t *back = NULL;
  $? "+ dk3sto_unsorted_find_next_node %!8s %!8s", TR_8PTR(n), TR_8PTR(r)
  if(n) {
    back = n->r;
  } else {
    back = r;
  } $? "- dk3sto_unsorted_find_next_node %!8s", TR_8PTR(back)
  return back;
}



/**	Find last node in an unsorted storage.
	@param	n	Root node.
	@return	Last node or NULL.
*/
static dk3_sto_node_t *
dk3sto_unsorted_find_last_node(dk3_sto_node_t *n)
{
  dk3_sto_node_t *back = NULL;
  $? "+ dk3sto_unsorted_find_last_node %!8s", TR_8PTR(n)
  if(n) back = n->l;
  $? "- dk3sto_unsorted_find_last_node %!8s", TR_8PTR(back)
  return back;
}



/**	Find node for an object in an unsorted storage.
	@param	r	Root node.
	@param	o	Object.
	@return	Node for object or NULL.
*/
static dk3_sto_node_t *
dk3sto_unsorted_find_exact(dk3_sto_node_t *r, void const *o)
{
  dk3_sto_node_t *back = NULL;
  dk3_sto_node_t *c;		/* Current node. */
  $? "+ dk3sto_unsorted_find_exact %!8s %!8s", TR_8PTR(r), TR_8PTR(o)
  c = r;
  while(c && (!back)) {
    if((c->o) == o) {
      back = c;
    }
    c = c->r;
  } $? "- dk3sto_unsorted_find_exact %!8s", TR_8PTR(back)
  return back;
}



/*
	SORTED DATA HANDLING
*/



/** Go to direction: Left.
*/
#define DK3STO_WALK_LEFT  1

/** Go to direction: Right.
*/
#define DK3STO_WALK_RIGHT 2



/**	Perform left rotation at node.
	@param  p	Subpath to modify.
	@return New subpath root node or NULL.
*/
static dk3_sto_node_t *
dk3sto_left_rotation(dk3_sto_node_t *p)
{
  dk3_sto_node_t *p1;
  $? "+ dk3sto_left_rotation %!8s", TR_8PTR(p)
  p1 = p->r;
  p->r = p1->l;
  if(p->r) (p->r)->p = p;
  p1->l = p;
  if(p) p->p = p1;
  $? "- dk3sto_left_rotation %!8s", TR_8PTR(p1)
  return p1;
}



/**	Perform right rotation at node.
	@param	p	Subpath to modify.
	@return	New subpath root node or NULL.
*/
static dk3_sto_node_t *
dk3sto_right_rotation(dk3_sto_node_t *p)
{
  dk3_sto_node_t *p1;
  $? "+ dk3sto_right_rotation %!8s", TR_8PTR(p)
  p1 = p->l;
  p->l = p1->r;
  if(p->l) (p->l)->p = p;
  p1->r = p;
  if(p) p->p = p1;
  $? "- dk3sto_right_rotation %!8s", TR_8PTR(p1)
  return p1;
}



/**	Increment balance field of a storage node.
	@param	p	Node to modify.
*/
static void
dk3sto_inc_balance(dk3_sto_node_t *p)
{
  short x;	/* New balance value. */
  $? "+ dk3sto_inc_balance %!8s", TR_8PTR(p)
  x = p->b; $? ". old balance %d", x
  x++;
  if(x > 3) x = 0;
  p->b = x; $? "- dk3sto_inc_balance %d", p->b
}



/**	Decrement balance field of a storage node.
	@param	p	Storage node.
*/
static void
dk3sto_dec_balance(dk3_sto_node_t *p)
{
  short x;	/* New balance value. */
  $? "+ dk3sto_dec_balance %!8s", TR_8PTR(p)
  x = p->b; $? ". old balance %d", x
  x--;
  if(x < 0) x = 3;
  p->b = x; $? "- dk3sto_dec_balance %d", p->b
}




/**	Set mark for "left node deleted".
	@param	p	Node.
	@param	h	Pointer to balance variable.
	@return	New root node for path behind \a p.
*/
static dk3_sto_node_t *
dk3sto_left_deleted(dk3_sto_node_t *p, short *h)
{
  $? "+ dk3sto_left_deleted %!8s %!8s", TR_8PTR(p), TR_8PTR(h)
  switch(p->b) {
    case 0: *h = - *h;
    case 3:
	    $? ". going to increment balance field of %!8s", TR_8PTR(p)
	    dk3sto_inc_balance(p);
	    $? ". balance field incremented"
	    break;
    case 1: {
      switch((p->r)->b) {
	case 0:
	  (p->r)->b = 3;
	  *h = - *h;
	  p = dk3sto_left_rotation(p);
	break;
	case 1:
	  (p->r)->b = 0;
	  p->b = 0;
	  p = dk3sto_left_rotation(p);
	break;
	case 3:
	  p->b =      (((((p->r)->l)->b) == 1) ? 3 : 0);
	  (p->r)->b = (((((p->r)->l)->b) == 3) ? 1 : 0);
	  p->r      = dk3sto_right_rotation(p->r);
	  if(p->r) (p->r)->p = p;
	  p         = dk3sto_left_rotation(p);
	  p->b      = 0;
      }
    }
  }
  $? "-  dk3sto_left_deleted %!8s", TR_8PTR(p)
  return p;
}



/**	Set mark for "right node deleted".
	@param	p	Node.
	@param	h	Pointer to balance variable.
	@return	New root node for path behind \a p.
*/
static dk3_sto_node_t *
dk3sto_right_deleted(dk3_sto_node_t *p, short *h)
{
  $? "+ dk3sto_right_deleted %!8s %!8s", TR_8PTR(p), TR_8PTR(h)
  switch(p->b) {
    case 0: *h = - *h;
    case 1: dk3sto_dec_balance(p);
            break;
    case 3: {
      switch((p->l)->b) {
	case 0:
	  (p->l)->b = 1;
	  *h = - *h;
	  p = dk3sto_right_rotation(p);
	break;
	case 3:
	  (p->l)->b = 0;
	  p->b = 0;
	  p = dk3sto_right_rotation(p);
	break;
	case 1:
	  p->b =      (((((p->l)->r)->b) == 3) ? 1 : 0);
	  (p->l)->b = (((((p->l)->r)->b) == 1) ? 3 : 0);
	  p->l      = dk3sto_left_rotation(p->l);
	  if(p->l) (p->l)->p = p;
	  p         = dk3sto_right_rotation(p);
	  p->b      = 0;
      }
    } 
  }
  $? "- dk3sto_right_deleted %!8s", TR_8PTR(p)
  return p;
}



/**	Add node to tree storage.
	@param	root	Root node.
	@param	newnode	Node to add.
	@param	st	Storage.
	@return	New root node or NULL.
*/
static dk3_sto_node_t *
dk3sto_avlt_add(dk3_sto_node_t *root, dk3_sto_node_t *newnode, dk3_sto_t *st)
{
  dk3_sto_node_t	*back = NULL;
  dk3_sto_node_t	*p = NULL;	/* Current node. */
  dk3_sto_node_t	*q = NULL;	/* Father of p. */
  dk3_sto_node_t	*r = NULL;	/* Critical node. */
  dk3_sto_node_t	*s = NULL;	/* Father of r. */
  $? "+ dk3sto_avlt_add %!8s %!8s %!8s", TR_8PTR(root), TR_8PTR(newnode), TR_8PTR(st)
  back = root;
  p = r = root; q = s = NULL;
  /*
    Search place for insertion, write direction into
    the "w" field in each node.
    The final new node has an empty "w" field.
  */
  while(p) {
    if(p->b) {
      s = q; r = p;
    }
    q = p;
    if(dk3sto_node_compare(p,newnode,st,st->c) > 0) {
      p->w = DK3STO_WALK_LEFT;
      p = p->l;
    } else {
      p->w = DK3STO_WALK_RIGHT;
      p = p->r;
    }
  }
  p = newnode;
  if(!back) {
    /*
      When inserting into an empty tree we are done here.
    */
    back = p;
  } else {
    /*
      The tree is not empty.
      The new node p is concatenated to the parent q.
    */
    if(dk3sto_node_compare(q,newnode,st,st->c) > 0) {
      q->l = p;
      q->w = DK3STO_WALK_LEFT;
    } else {
      q->r = p;
      q->w = DK3STO_WALK_RIGHT;
    }
    /*
      Now we must balance the tree again if necessary.
    */
    p->p = q;
    if(r) {
      /*
	There is a critical node.
      */
      p = r;
      /*
	Modify balance fields from critial node
	until we find our new node.
      */
      while(p->w) {
	if(p->w == DK3STO_WALK_LEFT) {
	  dk3sto_dec_balance(p);
	  p = p->l;
	} else {
	  dk3sto_inc_balance(p);
	  p = p->r;
	}
      }
      p = r;
      /*
	Now look whether we are dis-balanced,
	correct if necessary.
      */
      if((p->b) == 2) {
	/* We must balance */
	if(p->w == DK3STO_WALK_LEFT) {
	  if((p->l)->b == 3) {
	    p->b = 0;
	    p = dk3sto_right_rotation(p);
	  } else {
	    p->b =      (((((p->l)->r)->b) == 3) ? 1 : 0);
	    (p->l)->b = (((((p->l)->r)->b) == 1) ? 3 : 0);
	    p->l = dk3sto_left_rotation(p->l);
	    if(p->l) (p->l)->p = p;
	    p = dk3sto_right_rotation(p);
	  }
	} else {
	  if((p->r)->b == 1) {
	    p->b = 0;
	    p = dk3sto_left_rotation(p);
	  } else {
	    p->b =      (((((p->r)->l)->b) == 1) ? 3 : 0);
	    (p->r)->b = (((((p->r)->l)->b) == 3) ? 1 : 0);
            p->r = dk3sto_right_rotation(p->r);
	    if(p->r) (p->r)->p = p;
	    p = dk3sto_left_rotation(p);
	  }
	}
	p->b = 0;
	/*
	  Balance at the critical nodes father (if
	  there is one) or create new root.
	*/
	if(s) {
          if(s->w == DK3STO_WALK_LEFT) {
	    s->l = p;
	  } else {
	    s->r = p;
	  }
	  if(p) p->p = s;
	} else {
	  back = p;
	}
      }
    }
  }
  if(back) {
    back->p = NULL;
  }
  $? "- dk3sto_avlt_add %!8s", TR_8PTR(back)
  return back;
}



/**	Remove storage node from tree storage.
	@param	root		Root object.
	@param	node		Node to remove.
	@param	delpath		Deletion path (used for tree balancing).
	@param	st		Storage.
	@param	success_indicator	Pointer to success variable.
	@param	toremove	Node to remove.
	@return	New root object.
*/
static dk3_sto_node_t *
dk3sto_avlt_delete(
  dk3_sto_node_t *root, dk3_sto_node_t *node, dk3_sto_node_t **delpath,
  dk3_sto_t *st, int *success_indicator, dk3_sto_node_t **toremove
)
{
  dk3_sto_node_t	*back = NULL;
  dk3_sto_node_t	*p = NULL;	/* Current node. */
  dk3_sto_node_t	*q = NULL;	/* Father of p. */
  dk3_sto_node_t	*r = NULL;	/* Critical node. */
  dk3_sto_node_t	*todel = NULL;	/* Node to delete. */
  short      		x1 = 0;		/* Balance value. */
  short			delroot = 0;	/* Flag: Delete tree node. */
  int			can_continue = 1;	/* Flag: Can continue. */
  back = root;
  todel = node;
  $? "+ dk3sto_avlt_delete %!8s %!8s %!8s %!8s %!8s", TR_8PTR(root), TR_8PTR(node), TR_8PTR(delpath), TR_8PTR(st), TR_8PTR(success_indicator)
  /*
    Make sure the node to delete has max.
    1 subtree.
  */
  if((todel->l) && (todel->r)) {
    $? ". finding another node to delete"
    todel = todel->l;
    while(todel->r) todel = todel->r;
    dk3sto_node_data_copy(node,todel,st);
  }
  if(!(todel->p)) { $? ". deleting the root node"
    delroot = 1;
  }
  /*
    Mark the way in the "w" fields.
  */
  *toremove = todel;
  todel->w = 0;
  while(todel->p) {
    if((todel->p)->l == todel) {
      $? ". walk left"
      (todel->p)->w = DK3STO_WALK_LEFT;
    } else {
      $? ". walk right"
      (todel->p)->w = DK3STO_WALK_RIGHT;
    }
    todel = todel->p;
  }
  p = back;
  q = r = NULL;
  x1 = 0;
  can_continue = 1;
  while(can_continue) {
    $? ". new while loop 1 %d", x1
#if VERSION_BEFORE_20151002
    if(p) { $? ". have current node"
#endif
      if(p->w) { $? ". not final node"
	if(p->b == 0) {
	  x1 = 0; $? ". current node is balanced"
	}
	delpath[x1++] = p; $? ". adding current node to delpath %d", (x1 - 1)
	if(x1 >= st->l) {	$? ". x1 out of range"
	  /* x1 too large */
	  *success_indicator = 0;
	  goto error_mark;
	}
	if(p->w == DK3STO_WALK_LEFT) { $? ". going down left"
	  p = p->l;
	} else { $? ". going down right"
	  p = p->r;
	}
      } else {
	can_continue = 0; $? ". we are at the final point"
      }
#if VERSION_BEFORE_20151002
    } else {
      can_continue = 0; $? ". no more nodes to visit"
    }
#endif
  }
#if VERSION_BEFORE_20151002
  r = p;
#endif
  /* Static code analysis: Dereference potential NULL pointer p */
  /* I think p can not be NULL. */
  if(p->l) q = p->l;
  else     q = p->r;
  if(x1 == 0) {
    if(delroot) { $? ". setting new root node"
      back = q;
    }
  }
  while(x1 > 0) { $? ". begin of while loop 2 %d", (x1 - 1)
    x1--;
    p = delpath[x1];
    if(p->w == DK3STO_WALK_LEFT) {
      $? ". going to left"
      p->l = q; if(q) q->p = p;
      q = dk3sto_left_deleted(p, &x1);
      $? ". after dk3sto_left_deleted"
    } else {
      $? ". going to right"
      p->r = q; if(q) q->p = p;
      q = dk3sto_right_deleted(p, &x1);
      $? ". after dk3sto_right_deleted"
    }
    if(x1 == 0) {
      $? ". final node"
      if(delpath[x1] == back) {
	$? ". setting new root node"
	back = q;
      }
    }
    if(x1 < 0) { $? ". finished"
      p = delpath[0 - x1 - 1];
      if(p->w == DK3STO_WALK_LEFT) {
	p->l = q;
      } else {
	p->r = q;
      }
      if(q) q->p = p;
    }
  }
error_mark:
  if(back) {
    back->p = NULL;
  }
  $? "- dk3sto_avlt_delete %!8s", TR_8PTR(back)
  return back;
}



/**	Find storage node for an object evaluated like a given object.
	@param	root		Root node.
	@param	testnode	Node of the given object.
	@param	st		Storage.
	@param	crit		Comparison criteria.
	@param	cand		Pointer for candidate.
	@return	Pointer to storage node or NULL.
*/
static dk3_sto_node_t *
dk3sto_tree_find_like(
  dk3_sto_node_t *root, dk3_sto_node_t *testnode, dk3_sto_t *st, int crit,
  dk3_sto_node_t **cand
)
{
  dk3_sto_node_t *back = NULL;
  dk3_sto_node_t *c = NULL;	/* Current node. */
  int testval = 0;		/* Comparison result. */
  $? "+ sorted_find_like %!8s %!8s %!8s %d", TR_8PTR(root), TR_8PTR(testnode), TR_8PTR(st), crit
  c = root;
  while(c) {
    testval = dk3sto_node_compare(c,testnode,st,crit);
    switch(testval) {
      case -1: {
	if(cand) *cand = c;
	c = c->r;
      } break;
      case  0: {
	back = c; c = c->l;
      } break;
      default: {
	c = c->l;
      } break;
    }
  } $? "- sorted_find_like %!8s", TR_8PTR(back)
  return back;
}



/**	Add node to a tree.
	@param	r	Root node.
	@param	n	New node to add.
	@param	s	Storage.
	@return	Node pointer on success, NULL on error.
*/
static dk3_sto_node_t *
dk3sto_tree_add(dk3_sto_node_t *r, dk3_sto_node_t *n, dk3_sto_t *s)
{
  dk3_sto_node_t *back;
  back = dk3sto_avlt_add(r,n,s);
  return back;
}



/**	Release all nodes in a tree storage.
	@param	r	Root node.
*/
static void
dk3sto_tree_release_all_nodes(dk3_sto_node_t *r)
{
  $? "+ sorted_release_all_nodes %!8s", TR_8PTR(r)
  if(r) {
    dk3sto_tree_release_all_nodes(r->l);
    dk3sto_tree_release_all_nodes(r->r);
    r->l = r->r = r->p = NULL;
    r->o = NULL;
    r->b = 0; r->w = 0;
    dk3_delete(r) ;
  } $? "- sorted_release_all_nodes"
}



/**	Find next node in a tree storage.
	@param	n	Current node.
	@param	r	Root node.
	@return	Pointer to next node or NULL.
*/
static dk3_sto_node_t *
dk3sto_tree_find_next_node(dk3_sto_node_t *n, dk3_sto_node_t *r)
{
  dk3_sto_node_t *back = NULL;
  dk3_sto_node_t *c = NULL;	/* Current node. */
  dk3_sto_node_t *p = NULL;	/* Parent of c. */
  $? "+ sorted_find_next_node %!8s %!8s", TR_8PTR(n), TR_8PTR(r)
  /*
  if(n) {
    if(n->r) {
      back = n->r;
      while(back->l) { back = back->l; }
    } else {
      c = n; p = c->p;
      while(p && (!back)) {
	if((p->l) == c) {
	  back = p;
	} else {
	  c = p; p = c->p;
	}
      }
    }
  } else {
    back = r;
    if(back) { while(back->l) { back = back->l; } }
  }
  */
  if(n) {
    if(n->r) {
      back = n->r;
      while(back->l) back = back->l;
    } else {
      c = n; p = c->p;
      while(p && (!back)) {
	if(p->l == c) {
	  back = p;
	} else {
	  c = p; p = c->p;
	}
      }
    }
  } else {
    back = r;
    if(back) {
      while(back->l) back = back->l;
    }
  }
  $? "- sorted_find_next_node %!8s", TR_8PTR(back)
  return back;
}



/**	Find last node in a tree storage.
	@param	n	Node to start search from.
	@return	Last node or NULL.
*/
static dk3_sto_node_t *
dk3sto_tree_find_last_node(dk3_sto_node_t *n)
{
  dk3_sto_node_t *back = NULL;
  dk3_sto_node_t *c;		/* Current node. */
  dk3_sto_node_t *p;		/* Father of c. */
  $? "+ sorted_find_last_node %!8s", TR_8PTR(n)
  if(n->l) {
    back = n->l;
    while(back->r) { back = back->r; }
  } else {
    c = n; p = c->p;
    while(p && (!back)) {
      if((p->r) == c) {
	back = p;
      } else {
	c = p; p = c->p;
      }
    }
  } $? "- sorted_find_last_node %!8s", TR_8PTR(back)
  return back;
}



/**	Find node for object in tree storage (exact search).
	@param	r	Root node.
	@param	o	Object to find node for.
	@param	s	Storage.
	@return	Pointer to node or NULL.
*/
static dk3_sto_node_t *
dk3sto_tree_find_exact(dk3_sto_node_t *r, void const *o, dk3_sto_t *s)
{
  dk3_sto_node_t *back = NULL;
  dk3_sto_node_t testnode;	/* Test node for comparisons. */
  dk3_sto_node_t *c;		/* Current node to test. */
  dk3_sto_node_t *candidate;	/* Candidate for found node. */
  int testval = 0;		/* Comparison result. */
  $? "+ sorted_find_exact %!8s %!8s %!8s", TR_8PTR(r), TR_8PTR(o), TR_8PTR(s)
  dk3sto_node_init_for_object(&testnode, (void *)o, s, s->c);
  c = dk3sto_tree_find_like(r, &testnode, s, s->c, &candidate);
  while(c && (!back)) {
    testval = dk3sto_node_compare(c, &testnode, s, s->c);
    if(testval == 0) {
      if((c->o) == o) {
	back = c;
      } else {
        c = dk3sto_tree_find_next_node(c, r);
      }
    } else {
      c = NULL;
    }
  } $? "- sorted_find_exact %!8s", TR_8PTR(back)
  return back;
}



/**	Remove storage node from tree storage.
	@param	ro	Root node.
	@param	n	Node to delete.
	@param	st	Storage.
	@param	sci	???
	@param	toremove	Node to remove.
	@return	New root node.
*/
static dk3_sto_node_t *
dk3sto_tree_remove(
  dk3_sto_node_t *ro, dk3_sto_node_t *n, dk3_sto_t *st, int *sci,
  dk3_sto_node_t **toremove
)
{
  dk3_sto_node_t *back;
  back = dk3sto_avlt_delete(ro,n,st->d,st,sci,toremove);
  return back;
}



/*
	USE DOUBLE LINKED LIST
*/

/**	Find node for an object evaluated like a given object in a list storage.
	@param	root	Root node.
	@param	testnode	Node with object for comparison.
	@param	st		Storage.
	@param	crit		Comparison criteria.
	@param	cand		Test candidate.
	@return	Pointer to storage node or NULL.
*/
static dk3_sto_node_t *
dk3sto_list_find_like(
  dk3_sto_node_t *root, dk3_sto_node_t *testnode, dk3_sto_t *st, int crit,
  dk3_sto_node_t **cand
)
{
  dk3_sto_node_t *back = NULL;
  dk3_sto_node_t *c = NULL;	/* Current node. */
  int testval = 0;		/* Comparison result. */
  $? "+ sorted_find_like %!8s %!8s %!8s %d", TR_8PTR(root), TR_8PTR(testnode), TR_8PTR(st), crit
  c = root;
  while(c && (!back)) {
    testval = dk3sto_node_compare(c,testnode,st,crit);
    switch(testval) {
      case -1: {
	if(cand) *cand = c;
	c = c->r;
      } break;
      case 0: {
	back = c; c = NULL;
      } break;
      default : {
	c = NULL;
      } break;
    }
  } $? "- sorted_find_like %!8s", TR_8PTR(back)
  return back;
}



/**	Find node for an object (exact search).
	@param	r	Root node.
	@param	o	Object.
	@param	s	Storage.
	@return	Pointer to the objects node or NULL.
*/
static dk3_sto_node_t *
dk3sto_list_find_exact(dk3_sto_node_t *r, void const *o, dk3_sto_t *s)
{
  dk3_sto_node_t *back;
  $? "+ sorted_find_exact %!8s %!8s %!8s", TR_8PTR(r), TR_8PTR(o), TR_8PTR(s)
  back = dk3sto_unsorted_find_exact(r,o);
  $? "- sorted_find_exact %!8s", TR_8PTR(back)
  return back;
}



/**	Add node to list storage.
	@param	r	Root node.
	@param	n	New node.
	@param	s	Storage.
	@return	Pointer on success, NULL on error.
*/
static dk3_sto_node_t *
dk3sto_list_add(dk3_sto_node_t *r, dk3_sto_node_t *n, dk3_sto_t *s)
{
  dk3_sto_node_t *back;
  dk3_sto_node_t *larger = NULL;	/* Last found larger entry. */
  dk3_sto_node_t *current = NULL;	/* Current node. */
  dk3_sto_node_t *smaller = NULL;	/* Last found smaller entry. */
  int ende;
  $? "+ sorted_add %!8s %!8s %!8s", TR_8PTR(r), TR_8PTR(n), TR_8PTR(s)
  back = r;
  if(r) {
    larger = smaller = NULL;
    current = r;
    ende = 0;
    while(!ende) {
      if(dk3sto_node_compare(current,n,s,s->c) >= 0) {
        larger = current; ende = 1;
      } else {
        smaller = current;
      }
      if(current->r) {
        current = current->r;
      } else {
        ende = 1;
      }
    }
    if(larger) {
      n->r = larger;
      larger->l = n;
      if(smaller) {
	smaller->r = n;
	n->l = smaller;
      } else {
	back = n;
      }
    } else {
      if(smaller) {
	smaller->r = n;
	n->l = smaller;
      }
    }
  } else {
    back = n;
  } $? "- sorted_add %!8s", TR_8PTR(back)
  return back;
}



/**	Release all nodes of a list storage.
	@param	r	Root node.
*/
static void
dk3sto_list_release_all_nodes(dk3_sto_node_t *r)
{
  $? "+ sorted_release_all_nodes"
  dk3sto_unsorted_release_all_nodes(r);
  $? "- sorted_release_all_nodes"
}



/**	Find next node.
	@param	n	Current node.
	@param	r	Root node.
	@return	Pointer to next node or NULL.
*/
static dk3_sto_node_t *
dk3sto_list_find_next_node(dk3_sto_node_t *n, dk3_sto_node_t *r)
{
  dk3_sto_node_t *back;
  $? "+ sorted_find_next_node %!8s %!8s", TR_8PTR(n), TR_8PTR(r)
  back = dk3sto_unsorted_find_next_node(n,r);
  $? "- sorted_find_next_node %!8s", TR_8PTR(back)
  return back;
}



/**	Find last (previous) node.
	@param	n	Current node.
	@return	Pointer to previous node or NULL.
*/
static dk3_sto_node_t *
dk3sto_list_find_last_node(dk3_sto_node_t *n)
{
  dk3_sto_node_t *back;
  $? "+ sorted_find_last_node %!8s", TR_8PTR(n)
  back = dk3sto_unsorted_find_last_node(n);
  $? "- sorted_find_last_node %!8s", TR_8PTR(back)
  return back;
}



/**	Remove storage node from list storage.
	@param	ro		Root node.
	@param	n		Node to remove.
	@param	st		Storage.
	@param	sci		???
	@param	toremove	???
*/
static dk3_sto_node_t *
dk3sto_list_remove(
  dk3_sto_node_t *ro, dk3_sto_node_t *n, dk3_sto_t *st, int *sci,
  dk3_sto_node_t **toremove
)
{
  dk3_sto_node_t *back;
  $? "+ sorted_remove %!8s %!8s %!8s", TR_8PTR(ro), TR_8PTR(n), TR_8PTR(st)
  back = dk3sto_unsorted_remove(ro,n);
  $? "- sorted_remove %!8s", TR_8PTR(back)
  return back;
}


/*
	COMMON STATIC FUNCTIONS
*/


/**	Get object node (traverse storage).
	@param	it	Storage iterator.
	@param	o	Object to find storage node.
	@return	Pointer to node or NULL.
*/
static dk3_sto_node_t *
dk3sto_traverse_iterators_for(void *it, void *o)
{
  dk3_sto_node_t *back = NULL;
  dk3_sto_it_t *c = NULL;	/* Current node. */
  $? "+ dk3sto_traverse_iterators_for %!8s %!8s", TR_8PTR(it), TR_8PTR(o)
  if(it) {
    c = (dk3_sto_it_t *)it;
    while(c && (!back)) {
      if(c->c) {
	if(((c->c)->o) == o) {
	  back = c->c;
	}
      }
      if(!back) c = c->r;
    }
  } $? "- dk3sto_traverse_iterators_for %!8s", TR_8PTR(back)
  return back;
}



/**	Find last storage node.
	@param	n	Current storage node.
	@param	st	Storage.
	@return	Pointer to last node or NULL.
*/
static dk3_sto_node_t *
dk3sto_find_last_node(dk3_sto_node_t *n, dk3_sto_t *st)
{
  dk3_sto_node_t *back = NULL;
  $? "+ dk3sto_find_last_node %!8s %!8s", TR_8PTR(n), TR_8PTR(st)
  if(st->h) {
    if(st->t) {
      back = dk3sto_tree_find_last_node(n);
    } else {
      back = dk3sto_list_find_last_node(n);
    }
  } else {
    back = dk3sto_unsorted_find_last_node(n);
  }
  $? "- dk3sto_find_last_node %!8s", TR_8PTR(back)
  return back;
}



/**	Initialize storage.
	@param	st	Storage to initialize.
	@param	app	Application structure for diagnostics, may be NULL.
	@return	1 on success, 0 on error.
*/
static int
dk3sto_storage_init(dk3_sto_t *st, dk3_app_t *app)
{
  int back = 0;
  short l = 0;	/* Critical path length. */
  $? "+ dk3sto_storage_init %!8s", TR_8PTR(st)
  /* delpath begin address and length */
  st->d = NULL; st->l = 0;
  /* root node */
  st->r = NULL;
  /* comparison method */
  st->h = 0;
  /* comparison criteria */
  st->c = 0;
  /* iterators list */
  st->i = NULL;
  st->l = l = 1536;
  st->app = app;
  st->d = dk3_new_app(dk3_sto_node_p,l,app);
  st->t = 1;
  if(st->d) {
    back = 1;
  } $? "- dk3sto_storage_init %d", back
  return back;
}



/**	Close the storage, release memory.
	@param	st	Storage to close.
*/
static void
dk3sto_storage_end(dk3_sto_t *st)
{
  $? "+ dk3sto_storage_end %!8s", TR_8PTR(st)
  /* release iterators */
  {
    dk3_sto_it_t *c = NULL;	/* Current iterator. */
    dk3_sto_it_t *n = NULL;	/* Next iterator. */
    c = (dk3_sto_it_t *)(st->i);
    st->i = NULL;
    while(c) {
      $? ". going to release iterator %!8s", TR_8PTR(c)
      n = c->r;
      c->r = NULL;
      c->l = NULL;
      c->c = NULL;
      c->s = NULL;
      dk3_delete(c) ;
      c = n;
    }
    st->i = NULL;
  }
  $? ". iterators released"
  /* release nodes */
  {
    if(st->h) {
      if(st->t) {
	dk3sto_tree_release_all_nodes(st->r);
      } else {
	dk3sto_list_release_all_nodes(st->r);
      }
    } else {
      dk3sto_unsorted_release_all_nodes(st->r);
    }
    st->r = NULL;
  }
  $? ". nodes released"
  /* release delpath */
  {
    dk3_sto_node_p *p;
    p = st->d;
    dk3_delete(p);
    st->d = NULL; st->l = 0;
  }
  $? ". delpath released"
  /* set pointers to NULL */
  {
    st->h = 0;
    st->c = 0;
  }
  $? ". function pointers resetted"
  $? "- dk3sto_storage_end"
}



/*
	PUBLIC INTERFACES
*/


dk3_sto_t *
dk3sto_open_app(dk3_app_t *app)
{
  dk3_sto_t *back = NULL;
  $? "+ dk3sto_open"
  back = dk3_new_app(dk3_sto_t,1,app) ;
  if(back) {
    if(!dk3sto_storage_init(back,app)) {
      dk3_delete(back);
      back = NULL;
    }
  } $? "- dk3sto_open %!8s", TR_8PTR(back)
  return back;
}



void
dk3sto_close(dk3_sto_t *st)
{
  $? "+ dk3sto_close %!8s", TR_8PTR(st)
  if(st) {
    dk3sto_storage_end(st);
    dk3_delete(st) ;
  } $? "- dk3sto_close"
}



void
dk3sto_remove_all(dk3_sto_t *st)
{
  if(st) {
    /* reset all iterators */
    dk3_sto_it_t	*c = NULL;	/* Curent iterator. */
    dk3_sto_it_t	*n = NULL;	/* Next iterator. */
    c = (dk3_sto_it_t *)(st->i);
    while(c) {
      n = c->r;
      c->c = NULL;
      c = n;
    }
    /* remove all nodes */
    if(st->r) {
      if(st->h) {
        if(st->t) {
          dk3sto_tree_release_all_nodes(st->r);
        } else {
          dk3sto_list_release_all_nodes(st->r);
        }
      } else {
        dk3sto_unsorted_release_all_nodes(st->r);
      }
    }
    st->r = NULL;
  }
}



int
dk3sto_remove(dk3_sto_t *st, void *o)
{
  int back = 0;
  dk3_sto_node_t *node_to_remove = NULL;	/* Node to remove. */
  dk3_sto_node_t *ln = NULL;			/* Last node. */
  dk3_sto_it_t *iterator = NULL;		/* Traverse all iterators. */
  $? "+ dk3sto_remove %!8s %!8s", TR_8PTR(st), TR_8PTR(o)
  if(st && o) {
    node_to_remove = dk3sto_traverse_iterators_for(st->i, o);
    if(!node_to_remove) {
      if(st->h) {
	if(st->t) {
	  node_to_remove = dk3sto_tree_find_exact(st->r,o,st);
	} else {
	  node_to_remove = dk3sto_list_find_exact(st->r,o,st);
	}
      } else {
	node_to_remove = dk3sto_unsorted_find_exact(st->r,o);
      }
    }
    if(node_to_remove) {
      back = 1;
      ln = dk3sto_find_last_node(node_to_remove,st);
      iterator = (dk3_sto_it_t *)(st->i);
      while(iterator) {
	if((iterator->c) == node_to_remove) {
	  iterator->c = ln;
	}
	iterator = iterator->r;
      }
      if(st->h) {
	if(st->t) {
	  st->r = dk3sto_tree_remove(st->r,node_to_remove,st,&back,&node_to_remove);
	} else {
	  st->r = dk3sto_list_remove(st->r,node_to_remove,st,&back,&node_to_remove);
	}
      } else {
	st->r = dk3sto_unsorted_remove(st->r,node_to_remove);
      }
      node_to_remove->l = node_to_remove->r = node_to_remove->p = NULL;
      node_to_remove->o = NULL;
      dk3_delete(node_to_remove);
    }
  } $? "- dk3sto_remove %d", back
  return back;
}



int
dk3sto_add(dk3_sto_t *st, void *o)
{
  int back = 0;
  dk3_sto_node_t *n = NULL;	/* New node. */
  $? "+ dk3sto_add %!8s %!8s", TR_8PTR(st), TR_8PTR(o)
  if(st && o) {
    if(st->app) {
      n = dk3_new_app(dk3_sto_node_t,1,((dk3_app_t *)(st->app))) ;
    } else {
      n = dk3_new(dk3_sto_node_t,1);
    }
    if(n) {
      dk3sto_node_init_for_object(n,o,st,st->c);
      if(st->h) {
	if(st->t) {
	  st->r = dk3sto_tree_add(st->r, n, st);
	} else {
	  st->r = dk3sto_list_add(st->r, n, st);
	}
      } else {
	st->r = dk3sto_unsorted_add(st->r, n);
      }
      back = 1;
    }
  } $? "- dk3sto_add %d", back
  return back;
}



dk3_sto_it_t *
dk3sto_it_open(dk3_sto_t *st)
{
  dk3_sto_it_t *back = NULL;
  $? "+ dk3sto_it_open %!8s", TR_8PTR(st)
  if(st) {
    if(st->app) {
      back = dk3_new_app(dk3_sto_it_t,1,((dk3_app_t *)(st->app))) ;
    } else {
      back = dk3_new(dk3_sto_it_t,1);
    }
    if(back) {
      back->s = st;
      back->l = NULL;
      back->r = (dk3_sto_it_t *)(st->i);
      back->c = NULL;
      st->i = (void *)back;
    }
  } $? "- dk3sto_it_open %!8s", TR_8PTR(back)
  return back;
}



void
dk3sto_it_close(dk3_sto_it_t *it)
{
  dk3_sto_it_t *l = NULL;	/* Left iterator. */
  dk3_sto_it_t *r = NULL;	/* Right iterator. */
  dk3_sto_t *s = NULL;		/* The storage. */
  $? "+ dk3sto_it_close %!8s", TR_8PTR(it)
  if(it) {
    s = it->s;
    l = it->l;
    r = it->r;
    if(l) {
      l->r = r;
    } else {
      s->i = (void *)(r);
    }
    if(r) {
      r->l = l;
    }
    it->s = NULL;
    it->l = it->r = NULL;
    it->c = NULL;
    dk3_delete(it) ;
  } $? "- dk3sto_it_close"
}



void
dk3sto_it_reset(dk3_sto_it_t *it)
{
  $? "+ dk3sto_it_reset %!8s", TR_8PTR(it)
  if(it) {
    it->c = NULL;
  } $? "- dk3sto_it_reset"
}



void *
dk3sto_it_next(dk3_sto_it_t *it)
{
  void *back = NULL;
  $? "+ dk3sto_it_next %!8s", TR_8PTR(it)
  if(it) {
    if(it->s) {
      if((it->s)->h) {
	if((it->s)->t) {
	  it->c = dk3sto_tree_find_next_node(it->c, (it->s)->r);
	} else {
	  it->c = dk3sto_list_find_next_node(it->c, (it->s)->r);
	}
      } else {
	it->c = dk3sto_unsorted_find_next_node(it->c, (it->s)->r);
      }
      if(it->c) {
	back = (it->c)->o;
      }
    }
  } $? "- dk3sto_it_next %!8s", TR_8PTR(back)
  return back;
}



void *
dk3sto_it_find_exact(dk3_sto_it_t *i, void const *o)
{
  void *back = NULL;
  $? "+ dk3sto_it_find_exact %!8s %!8s", TR_8PTR(i), TR_8PTR(o)
  if(i && o) {
    if(i->s) {
      if((i->s)->h) {
	if((i->s)->t) {
	  i->c = dk3sto_tree_find_exact((i->s)->r, o, i->s);
	} else {
	  i->c = dk3sto_list_find_exact((i->s)->r, o, i->s);
	}
      } else {
	i->c = dk3sto_unsorted_find_exact((i->s)->r, o);
      }
    }
    if(i->c) {
      back = (i->c)->o;
    }
  } $? "- dk3sto_it_find_exact %!8s", TR_8PTR(back)
  return back;
}



void *
dk3sto_it_find_like(dk3_sto_it_t *i, void const *o, int cr)
{
  void *back = NULL;
  dk3_sto_node_t testnode;		/* Test node for comparisons. */
  dk3_sto_node_t *candidate = NULL;	/* Candicate node. */
  $? "+ dk3sto_it_find_like %!8s %!8s %d", TR_8PTR(i), TR_8PTR(o), cr
  if(i && o) {
    if(i->s) {
      candidate = NULL;
      if((i->s)->h) {
	dk3sto_node_init_for_object(&testnode, (void *)o, (i->s), cr);
	if((i->s)->t) {
	  i->c = dk3sto_tree_find_like((i->s)->r, &testnode, i->s, cr, &candidate);
	} else {
	  i->c = dk3sto_list_find_like((i->s)->r, &testnode, i->s, cr, &candidate);
	}
      } else {
	i->c = dk3sto_unsorted_find_exact((i->s)->r, o);
      }
      if(i->c) {
	back = (i->c)->o;
      } else {
	i->c = candidate;
      }
    }
  } $? "- dk3sto_it_find_like %!8s", TR_8PTR(back)
  return back;
}



int
dk3sto_set_eval_c(dk3_sto_t *st, dk3_fct_eval_c_t *f, int cr)
{
  int back = 0;
  $? "+ dk3sto_set_eval_c %!8s %!8s %d", TR_8PTR(st), TR_8PTR(f), cr
  if(st) {
    if(!(st->r)) {
      back = 1;
      (st->e).c = f;
      st->c = cr;
      st->h = DK3STO_COMPARE_CHAR;
    }
  } $? "- dk3sto_set_eval_c %d", back
  return back;
}



int
dk3sto_set_eval_uc(dk3_sto_t *st, dk3_fct_eval_uc_t *f, int cr)
{
  int back = 0;
  $? "+ dk3sto_set_eval_uc %!8s %!8s %d", TR_8PTR(st), TR_8PTR(f), cr
  if(st) {
    if(!(st->r)) {
      back = 1;
      (st->e).uc = f;
      st->c = cr;
      st->h = DK3STO_COMPARE_UCHAR;
    }
  } $? "- dk3sto_set_eval_uc %d", back
  return back;
}



int
dk3sto_set_eval_s(dk3_sto_t *st, dk3_fct_eval_s_t *f, int cr)
{
  int back = 0;
  $? "+ dk3sto_set_eval_s %!8s %!8s %d", TR_8PTR(st), TR_8PTR(f), cr
  if(st) {
    if(!(st->r)) {
      back = 1;
      (st->e).s = f;
      st->c = cr;
      st->h = DK3STO_COMPARE_SHORT;
    }
  } $? "- dk3sto_set_eval_s %d", back
  return back;
}



int
dk3sto_set_eval_us(dk3_sto_t *st, dk3_fct_eval_us_t *f, int cr)
{
  int back = 0;
  $? "+ dk3sto_set_eval_us %!8s %!8s %d", TR_8PTR(st), TR_8PTR(f), cr
  if(st) {
    if(!(st->r)) {
      back = 1;
      (st->e).us = f;
      st->c = cr;
      st->h = DK3STO_COMPARE_USHORT;
    }
  } $? "- dk3sto_set_eval_us %d", back
  return back;
}



int
dk3sto_set_eval_i(dk3_sto_t *st, dk3_fct_eval_i_t *f, int cr)
{
  int back = 0;
  $? "+ dk3sto_set_eval_i %!8s %!8s %d", TR_8PTR(st), TR_8PTR(f), cr
  if(st) {
    if(!(st->r)) {
      back = 1;
      (st->e).i = f;
      st->c = cr;
      st->h = DK3STO_COMPARE_INT;
    }
  } $? "- dk3sto_set_eval_i %d", back
  return back;
}



int
dk3sto_set_eval_ui(dk3_sto_t *st, dk3_fct_eval_ui_t *f, int cr)
{
  int back = 0;
  $? "+ dk3sto_set_eval_ui %!8s %!8s %d", TR_8PTR(st), TR_8PTR(f), cr
  if(st) {
    if(!(st->r)) {
      back = 1;
      (st->e).ui = f;
      st->c = cr;
      st->h = DK3STO_COMPARE_UINT;
    }
  } $? "- dk3sto_set_eval_ui %d", back
  return back;
}



int
dk3sto_set_eval_l(dk3_sto_t *st, dk3_fct_eval_l_t *f, int cr)
{
  int back = 0;
  $? "+ dk3sto_set_eval_l %!8s %!8s %d", TR_8PTR(st), TR_8PTR(f), cr
  if(st) {
    if(!(st->r)) {
      back = 1;
      (st->e).l = f;
      st->c = cr;
      st->h = DK3STO_COMPARE_LONG;
    }
  } $? "- dk3sto_set_eval_l %d", back
  return back;
}



int
dk3sto_set_eval_ul(dk3_sto_t *st, dk3_fct_eval_ul_t *f, int cr)
{
  int back = 0;
  $? "+ dk3sto_set_eval_ul %!8s %!8s %d", TR_8PTR(st), TR_8PTR(f), cr
  if(st) {
    if(!(st->r)) {
      back = 1;
      (st->e).ul = f;
      st->c = cr;
      st->h = DK3STO_COMPARE_ULONG;
    }
  } $? "- dk3sto_set_eval_ul %d", back
  return back;
}



int
dk3sto_set_eval_f(dk3_sto_t *st, dk3_fct_eval_f_t *f, int cr)
{
  int back = 0;
  $? "+ dk3sto_set_eval_f %!8s %!8s %d", TR_8PTR(st), TR_8PTR(f), cr
  if(st) {
    if(!(st->r)) {
      back = 1;
      (st->e).f = f;
      st->c = cr;
      st->h = DK3STO_COMPARE_FLOAT;
    }
  } $? "- dk3sto_set_eval_f %d", back
  return back;
}



int
dk3sto_set_eval_d(dk3_sto_t *st, dk3_fct_eval_d_t *f, int cr)
{
  int back = 0;
  $? "+ dk3sto_set_eval_d %!8s %!8s %d", TR_8PTR(st), TR_8PTR(f), cr
  if(st) {
    if(!(st->r)) {
      back = 1;
      (st->e).d = f;
      st->c = cr;
      st->h = DK3STO_COMPARE_DOUBLE;
    }
  } $? "- dk3sto_set_eval_d %d", back
  return back;
}



int
dk3sto_set_comp(dk3_sto_t *st, dk3_fct_comp_t *f, int cr)
{
  int back = 0;
  $? "+ dk3sto_set_eval_d %!8s %!8s %d", TR_8PTR(st), TR_8PTR(f), cr
  if(st) {
    if(!(st->r)) {
      back = 1;
      (st->e).comp = f;
      st->c = cr;
      st->h = DK3STO_COMPARE_FCT;
    }
  } $? "- dk3sto_set_eval_d %d", back
  return back;
}



int
dk3sto_use_trees(dk3_sto_t *st,int ok)
{
  int back = 0;
  if(st) {
    if(!(st->r)) {
      st->t = (ok ? 1 : 0);
      back = 1;
    }
  }
  return back;
}


void *
dk3sto_find_root(dk3_sto_t *s)
{
  void *back = NULL;
  if(s) {
    if(s->r) {
      back = (s->r)->o;
    }
  }
  return back;
}



void *
dk3sto_it_find_parent(dk3_sto_it_t *i)
{
  void *back = NULL;
  if(i) {
    if(i->c) {
      if((i->c)->p) {
        back = ((i->c)->p)->o;
      }
    }
  }
  return back;
}



void *
dk3sto_it_find_left(dk3_sto_it_t *i)
{
  void *back = NULL;
  if(i) {
    if(i->c) {
      if((i->c)->l) {
        back = ((i->c)->l)->o;
      }
    }
  }
  return back;
}



void *
dk3sto_it_find_right(dk3_sto_it_t *i)
{
  void *back = NULL;
  if(i) {
    if(i->c) {
      if((i->c)->r) {
        back = ((i->c)->r)->o;
      }
    }
  }
  return back;
}



void *
dk3sto_it_find_root(dk3_sto_it_t *i)
{
  void *back = NULL;
  if(i) {
    if(i->s) {
      back = dk3sto_find_root(i->s);
    }
  }
  return back;
}



/* vim: set ai sw=2 : */