/usr/include/tcutil.h is in libtokyocabinet-dev 1.4.48-10.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 | /*************************************************************************************************
* The utility API of Tokyo Cabinet
* Copyright (C) 2006-2012 FAL Labs
* This file is part of Tokyo Cabinet.
* Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
* version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* You should have received a copy of the GNU Lesser General Public License along with Tokyo
* Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA.
*************************************************************************************************/
#ifndef _TCUTIL_H /* duplication check */
#define _TCUTIL_H
#if defined(__cplusplus)
#define __TCUTIL_CLINKAGEBEGIN extern "C" {
#define __TCUTIL_CLINKAGEEND }
#else
#define __TCUTIL_CLINKAGEBEGIN
#define __TCUTIL_CLINKAGEEND
#endif
__TCUTIL_CLINKAGEBEGIN
#include <stdlib.h>
#if ! defined(__cplusplus)
#include <stdbool.h>
#endif
#include <stdint.h>
#include <time.h>
#include <limits.h>
#include <math.h>
/*************************************************************************************************
* basic utilities
*************************************************************************************************/
/* String containing the version information. */
extern const char *tcversion;
/* Pointer to the call back function for handling a fatal error.
The argument specifies the error message.
The initial value of this variable is `NULL'. If the value is `NULL', the default function is
called when a fatal error occurs. A fatal error occurs when memory allocation is failed. */
extern void (*tcfatalfunc)(const char *);
/* Allocate a region on memory.
`size' specifies the size of the region.
The return value is the pointer to the allocated region.
This function handles failure of memory allocation implicitly. Because the region of the
return value is allocated with the `malloc' call, it should be released with the `free' call
when it is no longer in use. */
void *tcmalloc(size_t size);
/* Allocate a nullified region on memory.
`nmemb' specifies the number of elements.
`size' specifies the size of each element.
The return value is the pointer to the allocated nullified region.
This function handles failure of memory allocation implicitly. Because the region of the
return value is allocated with the `calloc' call, it should be released with the `free' call
when it is no longer in use. */
void *tccalloc(size_t nmemb, size_t size);
/* Re-allocate a region on memory.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is the pointer to the re-allocated region.
This function handles failure of memory allocation implicitly. Because the region of the
return value is allocated with the `realloc' call, it should be released with the `free' call
when it is no longer in use. */
void *tcrealloc(void *ptr, size_t size);
/* Duplicate a region on memory.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is the pointer to the allocated region of the duplicate.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when
it is no longer in use. */
void *tcmemdup(const void *ptr, size_t size);
/* Duplicate a string on memory.
`str' specifies the string.
The return value is the allocated string equivalent to the specified string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcstrdup(const void *str);
/* Free a region on memory.
`ptr' specifies the pointer to the region. If it is `NULL', this function has no effect.
Although this function is just a wrapper of `free' call, this is useful in applications using
another package of the `malloc' series. */
void tcfree(void *ptr);
/*************************************************************************************************
* basic utilities (for experts)
*************************************************************************************************/
/* type of the pointer to a comparison function.
`aptr' specifies the pointer to the region of one key.
`asiz' specifies the size of the region of one key.
`bptr' specifies the pointer to the region of the other key.
`bsiz' specifies the size of the region of the other key.
`op' specifies the pointer to the optional opaque object.
The return value is positive if the former is big, negative if the latter is big, 0 if both
are equivalent. */
typedef int (*TCCMP)(const char *aptr, int asiz, const char *bptr, int bsiz, void *op);
/* type of the pointer to a encoding or decoding function.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
`op' specifies the pointer to the optional opaque object.
If successful, the return value is the pointer to the result object allocated with `malloc'
call, else, it is `NULL'. */
typedef void *(*TCCODEC)(const void *ptr, int size, int *sp, void *op);
/* type of the pointer to a callback function to process record duplication.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
`op' specifies the pointer to the optional opaque object.
The return value is the pointer to the result object allocated with `malloc'. It is
released by the caller. If it is `NULL', the record is not modified. */
typedef void *(*TCPDPROC)(const void *vbuf, int vsiz, int *sp, void *op);
/* type of the pointer to a iterator function.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
`op' specifies the pointer to the optional opaque object.
The return value is true to continue iteration or false to stop iteration. */
typedef bool (*TCITER)(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op);
/*************************************************************************************************
* extensible string
*************************************************************************************************/
typedef struct { /* type of structure for an extensible string object */
char *ptr; /* pointer to the region */
int size; /* size of the region */
int asize; /* size of the allocated region */
} TCXSTR;
/* Create an extensible string object.
The return value is the new extensible string object. */
TCXSTR *tcxstrnew(void);
/* Create an extensible string object from a character string.
`str' specifies the string of the initial content.
The return value is the new extensible string object containing the specified string. */
TCXSTR *tcxstrnew2(const char *str);
/* Create an extensible string object with the initial allocation size.
`asiz' specifies the initial allocation size.
The return value is the new extensible string object. */
TCXSTR *tcxstrnew3(int asiz);
/* Copy an extensible string object.
`xstr' specifies the extensible string object.
The return value is the new extensible string object equivalent to the specified object. */
TCXSTR *tcxstrdup(const TCXSTR *xstr);
/* Delete an extensible string object.
`xstr' specifies the extensible string object.
Note that the deleted object and its derivatives can not be used anymore. */
void tcxstrdel(TCXSTR *xstr);
/* Concatenate a region to the end of an extensible string object.
`xstr' specifies the extensible string object.
`ptr' specifies the pointer to the region to be appended.
`size' specifies the size of the region. */
void tcxstrcat(TCXSTR *xstr, const void *ptr, int size);
/* Concatenate a character string to the end of an extensible string object.
`xstr' specifies the extensible string object.
`str' specifies the string to be appended. */
void tcxstrcat2(TCXSTR *xstr, const char *str);
/* Get the pointer of the region of an extensible string object.
`xstr' specifies the extensible string object.
The return value is the pointer of the region of the object.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. */
const void *tcxstrptr(const TCXSTR *xstr);
/* Get the size of the region of an extensible string object.
`xstr' specifies the extensible string object.
The return value is the size of the region of the object. */
int tcxstrsize(const TCXSTR *xstr);
/* Clear an extensible string object.
`xstr' specifies the extensible string object.
The internal buffer of the object is cleared and the size is set zero. */
void tcxstrclear(TCXSTR *xstr);
/* Perform formatted output into an extensible string object.
`xstr' specifies the extensible string object.
`format' specifies the printf-like format string. The conversion character `%' can be used
with such flag characters as `s', `d', `o', `u', `x', `X', `c', `e', `E', `f', `g', `G', `@',
`?', `b', and `%'. `@' works as with `s' but escapes meta characters of XML. `?' works as
with `s' but escapes meta characters of URL. `b' converts an integer to the string as binary
numbers. The other conversion character work as with each original.
The other arguments are used according to the format string. */
void tcxstrprintf(TCXSTR *xstr, const char *format, ...);
/* Allocate a formatted string on memory.
`format' specifies the printf-like format string. The conversion character `%' can be used
with such flag characters as `s', `d', `o', `u', `x', `X', `c', `e', `E', `f', `g', `G', `@',
`?', `b', and `%'. `@' works as with `s' but escapes meta characters of XML. `?' works as
with `s' but escapes meta characters of URL. `b' converts an integer to the string as binary
numbers. The other conversion character work as with each original.
The other arguments are used according to the format string.
The return value is the pointer to the region of the result string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcsprintf(const char *format, ...);
/*************************************************************************************************
* extensible string (for experts)
*************************************************************************************************/
/* Convert an extensible string object into a usual allocated region.
`xstr' specifies the extensible string object.
The return value is the pointer to the allocated region of the object.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when it
is no longer in use. Because the region of the original object is deleted, it should not be
deleted again. */
void *tcxstrtomalloc(TCXSTR *xstr);
/* Create an extensible string object from an allocated region.
`ptr' specifies the pointer to the region allocated with `malloc' call.
`size' specifies the size of the region.
The return value is the new extensible string object wrapping the specified region.
Note that the specified region is released when the object is deleted. */
TCXSTR *tcxstrfrommalloc(void *ptr, int size);
/*************************************************************************************************
* array list
*************************************************************************************************/
typedef struct { /* type of structure for an element of a list */
char *ptr; /* pointer to the region */
int size; /* size of the effective region */
} TCLISTDATUM;
typedef struct { /* type of structure for an array list */
TCLISTDATUM *array; /* array of data */
int anum; /* number of the elements of the array */
int start; /* start index of used elements */
int num; /* number of used elements */
} TCLIST;
/* Create a list object.
The return value is the new list object. */
TCLIST *tclistnew(void);
/* Create a list object with expecting the number of elements.
`anum' specifies the number of elements expected to be stored in the list.
The return value is the new list object. */
TCLIST *tclistnew2(int anum);
/* Create a list object with initial string elements.
`str' specifies the string of the first element.
The other arguments are other elements. They should be trailed by a `NULL' argument.
The return value is the new list object. */
TCLIST *tclistnew3(const char *str, ...);
/* Copy a list object.
`list' specifies the list object.
The return value is the new list object equivalent to the specified object. */
TCLIST *tclistdup(const TCLIST *list);
/* Delete a list object.
`list' specifies the list object.
Note that the deleted object and its derivatives can not be used anymore. */
void tclistdel(TCLIST *list);
/* Get the number of elements of a list object.
`list' specifies the list object.
The return value is the number of elements of the list. */
int tclistnum(const TCLIST *list);
/* Get the pointer to the region of an element of a list object.
`list' specifies the list object.
`index' specifies the index of the element.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the value.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. If `index' is equal to or more than
the number of elements, the return value is `NULL'. */
const void *tclistval(const TCLIST *list, int index, int *sp);
/* Get the string of an element of a list object.
`list' specifies the list object.
`index' specifies the index of the element.
The return value is the string of the value.
If `index' is equal to or more than the number of elements, the return value is `NULL'. */
const char *tclistval2(const TCLIST *list, int index);
/* Add an element at the end of a list object.
`list' specifies the list object.
`ptr' specifies the pointer to the region of the new element.
`size' specifies the size of the region. */
void tclistpush(TCLIST *list, const void *ptr, int size);
/* Add a string element at the end of a list object.
`list' specifies the list object.
`str' specifies the string of the new element. */
void tclistpush2(TCLIST *list, const char *str);
/* Remove an element of the end of a list object.
`list' specifies the list object.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the removed element.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when it
is no longer in use. If the list is empty, the return value is `NULL'. */
void *tclistpop(TCLIST *list, int *sp);
/* Remove a string element of the end of a list object.
`list' specifies the list object.
The return value is the string of the removed element.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. If the list is empty, the return
value is `NULL'. */
char *tclistpop2(TCLIST *list);
/* Add an element at the top of a list object.
`list' specifies the list object.
`ptr' specifies the pointer to the region of the new element.
`size' specifies the size of the region. */
void tclistunshift(TCLIST *list, const void *ptr, int size);
/* Add a string element at the top of a list object.
`list' specifies the list object.
`str' specifies the string of the new element. */
void tclistunshift2(TCLIST *list, const char *str);
/* Remove an element of the top of a list object.
`list' specifies the list object.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the removed element.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when it
is no longer in use. If the list is empty, the return value is `NULL'. */
void *tclistshift(TCLIST *list, int *sp);
/* Remove a string element of the top of a list object.
`list' specifies the list object.
The return value is the string of the removed element.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. If the list is empty, the return
value is `NULL'. */
char *tclistshift2(TCLIST *list);
/* Add an element at the specified location of a list object.
`list' specifies the list object.
`index' specifies the index of the new element.
`ptr' specifies the pointer to the region of the new element.
`size' specifies the size of the region.
If `index' is equal to or more than the number of elements, this function has no effect. */
void tclistinsert(TCLIST *list, int index, const void *ptr, int size);
/* Add a string element at the specified location of a list object.
`list' specifies the list object.
`index' specifies the index of the new element.
`str' specifies the string of the new element.
If `index' is equal to or more than the number of elements, this function has no effect. */
void tclistinsert2(TCLIST *list, int index, const char *str);
/* Remove an element at the specified location of a list object.
`list' specifies the list object.
`index' specifies the index of the element to be removed.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the removed element.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when it
is no longer in use. If `index' is equal to or more than the number of elements, no element
is removed and the return value is `NULL'. */
void *tclistremove(TCLIST *list, int index, int *sp);
/* Remove a string element at the specified location of a list object.
`list' specifies the list object.
`index' specifies the index of the element to be removed.
The return value is the string of the removed element.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. If `index' is equal to or more
than the number of elements, no element is removed and the return value is `NULL'. */
char *tclistremove2(TCLIST *list, int index);
/* Overwrite an element at the specified location of a list object.
`list' specifies the list object.
`index' specifies the index of the element to be overwritten.
`ptr' specifies the pointer to the region of the new content.
`size' specifies the size of the new content.
If `index' is equal to or more than the number of elements, this function has no effect. */
void tclistover(TCLIST *list, int index, const void *ptr, int size);
/* Overwrite a string element at the specified location of a list object.
`list' specifies the list object.
`index' specifies the index of the element to be overwritten.
`str' specifies the string of the new content.
If `index' is equal to or more than the number of elements, this function has no effect. */
void tclistover2(TCLIST *list, int index, const char *str);
/* Sort elements of a list object in lexical order.
`list' specifies the list object. */
void tclistsort(TCLIST *list);
/* Search a list object for an element using liner search.
`list' specifies the list object.
`ptr' specifies the pointer to the region of the key.
`size' specifies the size of the region.
The return value is the index of a corresponding element or -1 if there is no corresponding
element.
If two or more elements correspond, the former returns. */
int tclistlsearch(const TCLIST *list, const void *ptr, int size);
/* Search a list object for an element using binary search.
`list' specifies the list object. It should be sorted in lexical order.
`ptr' specifies the pointer to the region of the key.
`size' specifies the size of the region.
The return value is the index of a corresponding element or -1 if there is no corresponding
element.
If two or more elements correspond, which returns is not defined. */
int tclistbsearch(const TCLIST *list, const void *ptr, int size);
/* Clear a list object.
`list' specifies the list object.
All elements are removed. */
void tclistclear(TCLIST *list);
/* Serialize a list object into a byte array.
`list' specifies the list object.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the result serial region.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
void *tclistdump(const TCLIST *list, int *sp);
/* Create a list object from a serialized byte array.
`ptr' specifies the pointer to the region of serialized byte array.
`size' specifies the size of the region.
The return value is a new list object.
Because the object of the return value is created with the function `tclistnew', it should
be deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tclistload(const void *ptr, int size);
/*************************************************************************************************
* array list (for experts)
*************************************************************************************************/
/* Add an allocated element at the end of a list object.
`list' specifies the list object.
`ptr' specifies the pointer to the region allocated with `malloc' call.
`size' specifies the size of the region.
Note that the specified region is released when the object is deleted. */
void tclistpushmalloc(TCLIST *list, void *ptr, int size);
/* Sort elements of a list object in case-insensitive lexical order.
`list' specifies the list object. */
void tclistsortci(TCLIST *list);
/* Sort elements of a list object by an arbitrary comparison function.
`list' specifies the list object.
`cmp' specifies the pointer to the comparison function. The structure TCLISTDATUM has the
member "ptr" which is the pointer to the region of the element, and the member "size" which is
the size of the region. */
void tclistsortex(TCLIST *list, int (*cmp)(const TCLISTDATUM *, const TCLISTDATUM *));
/* Invert elements of a list object.
`list' specifies the list object. */
void tclistinvert(TCLIST *list);
/* Perform formatted output into a list object.
`list' specifies the list object.
`format' specifies the printf-like format string. The conversion character `%' can be used
with such flag characters as `s', `d', `o', `u', `x', `X', `c', `e', `E', `f', `g', `G', `@',
`?', `b', and `%'. `@' works as with `s' but escapes meta characters of XML. `?' works as
with `s' but escapes meta characters of URL. `b' converts an integer to the string as binary
numbers. The other conversion character work as with each original.
The other arguments are used according to the format string. */
void tclistprintf(TCLIST *list, const char *format, ...);
/*************************************************************************************************
* hash map
*************************************************************************************************/
typedef struct _TCMAPREC { /* type of structure for an element of a map */
int32_t ksiz; /* size of the region of the key */
int32_t vsiz; /* size of the region of the value */
struct _TCMAPREC *left; /* pointer to the left child */
struct _TCMAPREC *right; /* pointer to the right child */
struct _TCMAPREC *prev; /* pointer to the previous element */
struct _TCMAPREC *next; /* pointer to the next element */
} TCMAPREC;
typedef struct { /* type of structure for a map */
TCMAPREC **buckets; /* bucket array */
TCMAPREC *first; /* pointer to the first element */
TCMAPREC *last; /* pointer to the last element */
TCMAPREC *cur; /* pointer to the current element */
uint32_t bnum; /* number of buckets */
uint64_t rnum; /* number of records */
uint64_t msiz; /* total size of records */
} TCMAP;
/* Create a map object.
The return value is the new map object. */
TCMAP *tcmapnew(void);
/* Create a map object with specifying the number of the buckets.
`bnum' specifies the number of the buckets.
The return value is the new map object. */
TCMAP *tcmapnew2(uint32_t bnum);
/* Create a map object with initial string elements.
`str' specifies the string of the first element.
The other arguments are other elements. They should be trailed by a `NULL' argument.
The return value is the new map object.
The key and the value of each record are situated one after the other. */
TCMAP *tcmapnew3(const char *str, ...);
/* Copy a map object.
`map' specifies the map object.
The return value is the new map object equivalent to the specified object. */
TCMAP *tcmapdup(const TCMAP *map);
/* Delete a map object.
`map' specifies the map object.
Note that the deleted object and its derivatives can not be used anymore. */
void tcmapdel(TCMAP *map);
/* Store a record into a map object.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If a record with the same key exists in the map, it is overwritten. */
void tcmapput(TCMAP *map, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Store a string record into a map object.
`map' specifies the map object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If a record with the same key exists in the map, it is overwritten. */
void tcmapput2(TCMAP *map, const char *kstr, const char *vstr);
/* Store a new record into a map object.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the map, this function has no effect. */
bool tcmapputkeep(TCMAP *map, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Store a new string record into a map object.
`map' specifies the map object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the map, this function has no effect. */
bool tcmapputkeep2(TCMAP *map, const char *kstr, const char *vstr);
/* Concatenate a value at the end of the value of the existing record in a map object.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If there is no corresponding record, a new record is created. */
void tcmapputcat(TCMAP *map, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Concatenate a string value at the end of the value of the existing record in a map object.
`map' specifies the map object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If there is no corresponding record, a new record is created. */
void tcmapputcat2(TCMAP *map, const char *kstr, const char *vstr);
/* Remove a record of a map object.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
If successful, the return value is true. False is returned when no record corresponds to
the specified key. */
bool tcmapout(TCMAP *map, const void *kbuf, int ksiz);
/* Remove a string record of a map object.
`map' specifies the map object.
`kstr' specifies the string of the key.
If successful, the return value is true. False is returned when no record corresponds to
the specified key. */
bool tcmapout2(TCMAP *map, const char *kstr);
/* Retrieve a record in a map object.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the value of the
corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. */
const void *tcmapget(const TCMAP *map, const void *kbuf, int ksiz, int *sp);
/* Retrieve a string record in a map object.
`map' specifies the map object.
`kstr' specifies the string of the key.
If successful, the return value is the string of the value of the corresponding record.
`NULL' is returned when no record corresponds. */
const char *tcmapget2(const TCMAP *map, const char *kstr);
/* Move a record to the edge of a map object.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of a key.
`ksiz' specifies the size of the region of the key.
`head' specifies the destination which is the head if it is true or the tail if else.
If successful, the return value is true. False is returned when no record corresponds to
the specified key. */
bool tcmapmove(TCMAP *map, const void *kbuf, int ksiz, bool head);
/* Move a string record to the edge of a map object.
`map' specifies the map object.
`kstr' specifies the string of a key.
`head' specifies the destination which is the head if it is true or the tail if else.
If successful, the return value is true. False is returned when no record corresponds to
the specified key. */
bool tcmapmove2(TCMAP *map, const char *kstr, bool head);
/* Initialize the iterator of a map object.
`map' specifies the map object.
The iterator is used in order to access the key of every record stored in the map object. */
void tcmapiterinit(TCMAP *map);
/* Get the next key of the iterator of a map object.
`map' specifies the map object.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the next key, else, it is
`NULL'. `NULL' is returned when no record can be fetched from the iterator.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string.
The order of iteration is assured to be the same as the stored order. */
const void *tcmapiternext(TCMAP *map, int *sp);
/* Get the next key string of the iterator of a map object.
`map' specifies the map object.
If successful, the return value is the pointer to the region of the next key, else, it is
`NULL'. `NULL' is returned when no record can be fetched from the iterator.
The order of iteration is assured to be the same as the stored order. */
const char *tcmapiternext2(TCMAP *map);
/* Get the number of records stored in a map object.
`map' specifies the map object.
The return value is the number of the records stored in the map object. */
uint64_t tcmaprnum(const TCMAP *map);
/* Get the total size of memory used in a map object.
`map' specifies the map object.
The return value is the total size of memory used in a map object. */
uint64_t tcmapmsiz(const TCMAP *map);
/* Create a list object containing all keys in a map object.
`map' specifies the map object.
The return value is the new list object containing all keys in the map object.
Because the object of the return value is created with the function `tclistnew', it should
be deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tcmapkeys(const TCMAP *map);
/* Create a list object containing all values in a map object.
`map' specifies the map object.
The return value is the new list object containing all values in the map object.
Because the object of the return value is created with the function `tclistnew', it should
be deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tcmapvals(const TCMAP *map);
/* Add an integer to a record in a map object.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`num' specifies the additional value.
The return value is the summation value.
If the corresponding record exists, the value is treated as an integer and is added to. If no
record corresponds, a new record of the additional value is stored. */
int tcmapaddint(TCMAP *map, const void *kbuf, int ksiz, int num);
/* Add a real number to a record in a map object.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`num' specifies the additional value.
The return value is the summation value.
If the corresponding record exists, the value is treated as a real number and is added to. If
no record corresponds, a new record of the additional value is stored. */
double tcmapadddouble(TCMAP *map, const void *kbuf, int ksiz, double num);
/* Clear a map object.
`map' specifies the map object.
All records are removed. */
void tcmapclear(TCMAP *map);
/* Remove front records of a map object.
`map' specifies the map object.
`num' specifies the number of records to be removed. */
void tcmapcutfront(TCMAP *map, int num);
/* Serialize a map object into a byte array.
`map' specifies the map object.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the result serial region.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
void *tcmapdump(const TCMAP *map, int *sp);
/* Create a map object from a serialized byte array.
`ptr' specifies the pointer to the region of serialized byte array.
`size' specifies the size of the region.
The return value is a new map object.
Because the object of the return value is created with the function `tcmapnew', it should be
deleted with the function `tcmapdel' when it is no longer in use. */
TCMAP *tcmapload(const void *ptr, int size);
/*************************************************************************************************
* hash map (for experts)
*************************************************************************************************/
/* Store a record and make it semivolatile in a map object.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If a record with the same key exists in the map, it is overwritten. The record is moved to
the tail. */
void tcmapput3(TCMAP *map, const void *kbuf, int ksiz, const char *vbuf, int vsiz);
/* Store a record of the value of two regions into a map object.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`fvbuf' specifies the pointer to the former region of the value.
`fvsiz' specifies the size of the former region of the value.
`lvbuf' specifies the pointer to the latter region of the value.
`lvsiz' specifies the size of the latter region of the value.
If a record with the same key exists in the map, it is overwritten. */
void tcmapput4(TCMAP *map, const void *kbuf, int ksiz,
const void *fvbuf, int fvsiz, const void *lvbuf, int lvsiz);
/* Concatenate a value at the existing record and make it semivolatile in a map object.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If there is no corresponding record, a new record is created. */
void tcmapputcat3(TCMAP *map, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Store a record into a map object with a duplication handler.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value. `NULL' means that record addition is
ommited if there is no corresponding record.
`vsiz' specifies the size of the region of the value.
`proc' specifies the pointer to the callback function to process duplication. It receives
four parameters. The first parameter is the pointer to the region of the value. The second
parameter is the size of the region of the value. The third parameter is the pointer to the
variable into which the size of the region of the return value is assigned. The fourth
parameter is the pointer to the optional opaque object. It returns the pointer to the result
object allocated with `malloc'. It is released by the caller. If it is `NULL', the record is
not modified. If it is `(void *)-1', the record is removed.
`op' specifies an arbitrary pointer to be given as a parameter of the callback function. If
it is not needed, `NULL' can be specified.
If successful, the return value is true, else, it is false. */
bool tcmapputproc(TCMAP *map, const void *kbuf, int ksiz, const void *vbuf, int vsiz,
TCPDPROC proc, void *op);
/* Retrieve a semivolatile record in a map object.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the value of the
corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. The internal region of the returned
record is moved to the tail so that the record will survive for a time under LRU cache
algorithm removing records from the head. */
const void *tcmapget3(TCMAP *map, const void *kbuf, int ksiz, int *sp);
/* Retrieve a string record in a map object with specifying the default value string.
`map' specifies the map object.
`kstr' specifies the string of the key.
`dstr' specifies the string of the default value.
The return value is the string of the value of the corresponding record or the default value
string. */
const char *tcmapget4(TCMAP *map, const char *kstr, const char *dstr);
/* Initialize the iterator of a map object at the record corresponding a key.
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
If there is no record corresponding the condition, the iterator is not modified. */
void tcmapiterinit2(TCMAP *map, const void *kbuf, int ksiz);
/* Initialize the iterator of a map object at the record corresponding a key string.
`map' specifies the map object.
`kstr' specifies the string of the key.
If there is no record corresponding the condition, the iterator is not modified. */
void tcmapiterinit3(TCMAP *map, const char *kstr);
/* Get the value bound to the key fetched from the iterator of a map object.
`kbuf' specifies the pointer to the region of the iteration key.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the value of the corresponding record.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. */
const void *tcmapiterval(const void *kbuf, int *sp);
/* Get the value string bound to the key fetched from the iterator of a map object.
`kstr' specifies the string of the iteration key.
The return value is the pointer to the region of the value of the corresponding record. */
const char *tcmapiterval2(const char *kstr);
/* Create an array of strings of all keys in a map object.
`map' specifies the map object.
`np' specifies the pointer to a variable into which the number of elements of the return value
is assigned.
The return value is the pointer to the array of all string keys in the map object.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. Note that elements of the array
point to the inner objects, whose life duration is synchronous with the map object. */
const char **tcmapkeys2(const TCMAP *map, int *np);
/* Create an array of strings of all values in a map object.
`map' specifies the map object.
`np' specifies the pointer to a variable into which the number of elements of the return value
is assigned.
The return value is the pointer to the array of all string values in the map object.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. Note that elements of the array
point to the inner objects, whose life duration is synchronous with the map object. */
const char **tcmapvals2(const TCMAP *map, int *np);
/* Extract a map record from a serialized byte array.
`ptr' specifies the pointer to the region of serialized byte array.
`size' specifies the size of the region.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the value of the
corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. */
void *tcmaploadone(const void *ptr, int size, const void *kbuf, int ksiz, int *sp);
/* Perform formatted output into a map object.
`map' specifies the map object.
`kstr' specifies the string of the key.
`format' specifies the printf-like format string. The conversion character `%' can be used
with such flag characters as `s', `d', `o', `u', `x', `X', `c', `e', `E', `f', `g', `G', `@',
`?', `b', and `%'. `@' works as with `s' but escapes meta characters of XML. `?' works as
with `s' but escapes meta characters of URL. `b' converts an integer to the string as binary
numbers. The other conversion character work as with each original.
The other arguments are used according to the format string. */
void tcmapprintf(TCMAP *map, const char *kstr, const char *format, ...);
/*************************************************************************************************
* ordered tree
*************************************************************************************************/
typedef struct _TCTREEREC { /* type of structure for an element of a tree */
int32_t ksiz; /* size of the region of the key */
int32_t vsiz; /* size of the region of the value */
struct _TCTREEREC *left; /* pointer to the left child */
struct _TCTREEREC *right; /* pointer to the right child */
} TCTREEREC;
typedef struct { /* type of structure for a tree */
TCTREEREC *root; /* pointer to the root element */
TCTREEREC *cur; /* pointer to the current element */
uint64_t rnum; /* number of records */
uint64_t msiz; /* total size of records */
TCCMP cmp; /* pointer to the comparison function */
void *cmpop; /* opaque object for the comparison function */
} TCTREE;
/* Create a tree object.
The return value is the new tree object. */
TCTREE *tctreenew(void);
/* Create a tree object with specifying the custom comparison function.
`cmp' specifies the pointer to the custom comparison function. It receives five parameters.
The first parameter is the pointer to the region of one key. The second parameter is the size
of the region of one key. The third parameter is the pointer to the region of the other key.
The fourth parameter is the size of the region of the other key. The fifth parameter is the
pointer to the optional opaque object. It returns positive if the former is big, negative if
the latter is big, 0 if both are equivalent.
`cmpop' specifies an arbitrary pointer to be given as a parameter of the comparison function.
If it is not needed, `NULL' can be specified.
The return value is the new tree object.
The default comparison function compares keys of two records by lexical order. The functions
`tccmplexical' (dafault), `tccmpdecimal', `tccmpint32', and `tccmpint64' are built-in. */
TCTREE *tctreenew2(TCCMP cmp, void *cmpop);
/* Copy a tree object.
`tree' specifies the tree object.
The return value is the new tree object equivalent to the specified object. */
TCTREE *tctreedup(const TCTREE *tree);
/* Delete a tree object.
`tree' specifies the tree object.
Note that the deleted object and its derivatives can not be used anymore. */
void tctreedel(TCTREE *tree);
/* Store a record into a tree object.
`tree' specifies the tree object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If a record with the same key exists in the tree, it is overwritten. */
void tctreeput(TCTREE *tree, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Store a string record into a tree object.
`tree' specifies the tree object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If a record with the same key exists in the tree, it is overwritten. */
void tctreeput2(TCTREE *tree, const char *kstr, const char *vstr);
/* Store a new record into a tree object.
`tree' specifies the tree object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the tree, this function has no effect. */
bool tctreeputkeep(TCTREE *tree, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Store a new string record into a tree object.
`tree' specifies the tree object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the tree, this function has no effect. */
bool tctreeputkeep2(TCTREE *tree, const char *kstr, const char *vstr);
/* Concatenate a value at the end of the value of the existing record in a tree object.
`tree' specifies the tree object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If there is no corresponding record, a new record is created. */
void tctreeputcat(TCTREE *tree, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Concatenate a string value at the end of the value of the existing record in a tree object.
`tree' specifies the tree object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If there is no corresponding record, a new record is created. */
void tctreeputcat2(TCTREE *tree, const char *kstr, const char *vstr);
/* Store a record into a tree object with a duplication handler.
`tree' specifies the tree object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value. `NULL' means that record addition is
ommited if there is no corresponding record.
`vsiz' specifies the size of the region of the value.
`proc' specifies the pointer to the callback function to process duplication. It receives
four parameters. The first parameter is the pointer to the region of the value. The second
parameter is the size of the region of the value. The third parameter is the pointer to the
variable into which the size of the region of the return value is assigned. The fourth
parameter is the pointer to the optional opaque object. It returns the pointer to the result
object allocated with `malloc'. It is released by the caller. If it is `NULL', the record is
not modified. If it is `(void *)-1', the record is removed.
`op' specifies an arbitrary pointer to be given as a parameter of the callback function. If
it is not needed, `NULL' can be specified.
If successful, the return value is true, else, it is false. */
bool tctreeputproc(TCTREE *tree, const void *kbuf, int ksiz, const void *vbuf, int vsiz,
TCPDPROC proc, void *op);
/* Remove a record of a tree object.
`tree' specifies the tree object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
If successful, the return value is true. False is returned when no record corresponds to
the specified key. */
bool tctreeout(TCTREE *tree, const void *kbuf, int ksiz);
/* Remove a string record of a tree object.
`tree' specifies the tree object.
`kstr' specifies the string of the key.
If successful, the return value is true. False is returned when no record corresponds to
the specified key. */
bool tctreeout2(TCTREE *tree, const char *kstr);
/* Retrieve a record in a tree object.
`tree' specifies the tree object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the value of the
corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. */
const void *tctreeget(TCTREE *tree, const void *kbuf, int ksiz, int *sp);
/* Retrieve a string record in a tree object.
`tree' specifies the tree object.
`kstr' specifies the string of the key.
If successful, the return value is the string of the value of the corresponding record.
`NULL' is returned when no record corresponds. */
const char *tctreeget2(TCTREE *tree, const char *kstr);
/* Initialize the iterator of a tree object.
`tree' specifies the tree object.
The iterator is used in order to access the key of every record stored in the tree object. */
void tctreeiterinit(TCTREE *tree);
/* Get the next key of the iterator of a tree object.
`tree' specifies the tree object.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the next key, else, it is
`NULL'. `NULL' is returned when no record can be fetched from the iterator.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string.
The order of iteration is assured to be ascending of the keys. */
const void *tctreeiternext(TCTREE *tree, int *sp);
/* Get the next key string of the iterator of a tree object.
`tree' specifies the tree object.
If successful, the return value is the pointer to the region of the next key, else, it is
`NULL'. `NULL' is returned when no record can be fetched from the iterator.
The order of iteration is assured to be ascending of the keys. */
const char *tctreeiternext2(TCTREE *tree);
/* Get the number of records stored in a tree object.
`tree' specifies the tree object.
The return value is the number of the records stored in the tree object. */
uint64_t tctreernum(const TCTREE *tree);
/* Get the total size of memory used in a tree object.
`tree' specifies the tree object.
The return value is the total size of memory used in a tree object. */
uint64_t tctreemsiz(const TCTREE *tree);
/* Create a list object containing all keys in a tree object.
`tree' specifies the tree object.
The return value is the new list object containing all keys in the tree object.
Because the object of the return value is created with the function `tclistnew', it should
be deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tctreekeys(const TCTREE *tree);
/* Create a list object containing all values in a tree object.
`tree' specifies the tree object.
The return value is the new list object containing all values in the tree object.
Because the object of the return value is created with the function `tclistnew', it should
be deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tctreevals(const TCTREE *tree);
/* Add an integer to a record in a tree object.
`tree' specifies the tree object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`num' specifies the additional value.
The return value is the summation value.
If the corresponding record exists, the value is treated as an integer and is added to. If no
record corresponds, a new record of the additional value is stored. */
int tctreeaddint(TCTREE *tree, const void *kbuf, int ksiz, int num);
/* Add a real number to a record in a tree object.
`tree' specifies the tree object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`num' specifies the additional value.
The return value is the summation value.
If the corresponding record exists, the value is treated as a real number and is added to. If
no record corresponds, a new record of the additional value is stored. */
double tctreeadddouble(TCTREE *tree, const void *kbuf, int ksiz, double num);
/* Clear a tree object.
`tree' specifies the tree object.
All records are removed. */
void tctreeclear(TCTREE *tree);
/* Remove fringe records of a tree object.
`tree' specifies the tree object.
`num' specifies the number of records to be removed. */
void tctreecutfringe(TCTREE *tree, int num);
/* Serialize a tree object into a byte array.
`tree' specifies the tree object.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the result serial region.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
void *tctreedump(const TCTREE *tree, int *sp);
/* Create a tree object from a serialized byte array.
`ptr' specifies the pointer to the region of serialized byte array.
`size' specifies the size of the region.
`cmp' specifies the pointer to the custom comparison function.
`cmpop' specifies an arbitrary pointer to be given as a parameter of the comparison function.
If it is not needed, `NULL' can be specified.
The return value is a new tree object.
Because the object of the return value is created with the function `tctreenew', it should be
deleted with the function `tctreedel' when it is no longer in use. */
TCTREE *tctreeload(const void *ptr, int size, TCCMP cmp, void *cmpop);
/*************************************************************************************************
* ordered tree (for experts)
*************************************************************************************************/
/* Store a record into a tree object without balancing nodes.
`tree' specifies the tree object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If a record with the same key exists in the tree, it is overwritten. The structure of the
tree is not modifed by this function. */
void tctreeput3(TCTREE *tree, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Store a new record into a tree object without balancing nodes.
`tree' specifies the tree object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the tree, this function has no effect. The structure
of the tree is not modifed by this function. */
bool tctreeputkeep3(TCTREE *tree, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Concatenate a value at the existing record in a tree object without balancing nodes.
`tree' specifies the tree object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If there is no corresponding record, a new record is created. The structure of the tree is
not modifed by this function. */
void tctreeputcat3(TCTREE *tree, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Retrieve a record in a tree object without balancing nodes.
`tree' specifies the tree object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the value of the
corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. The structure of the tree is not
modifed by this function. */
const void *tctreeget3(const TCTREE *tree, const void *kbuf, int ksiz, int *sp);
/* Retrieve a string record in a tree object with specifying the default value string.
`tree' specifies the tree object.
`kstr' specifies the string of the key.
`dstr' specifies the string of the default value.
The return value is the string of the value of the corresponding record or the default value
string. */
const char *tctreeget4(TCTREE *tree, const char *kstr, const char *dstr);
/* Initialize the iterator of a tree object in front of records corresponding a key.
`tree' specifies the tree object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
The iterator is set to the first record corresponding the key or the next substitute if
completely matching record does not exist. */
void tctreeiterinit2(TCTREE *tree, const void *kbuf, int ksiz);
/* Initialize the iterator of a tree object in front of records corresponding a key string.
`tree' specifies the tree object.
`kstr' specifies the string of the key.
The iterator is set to the first record corresponding the key or the next substitute if
completely matching record does not exist. */
void tctreeiterinit3(TCTREE *tree, const char *kstr);
/* Get the value bound to the key fetched from the iterator of a tree object.
`kbuf' specifies the pointer to the region of the iteration key.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the value of the corresponding record.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. */
const void *tctreeiterval(const void *kbuf, int *sp);
/* Get the value string bound to the key fetched from the iterator of a tree object.
`kstr' specifies the string of the iteration key.
The return value is the pointer to the region of the value of the corresponding record. */
const char *tctreeiterval2(const char *kstr);
/* Create an array of strings of all keys in a tree object.
`tree' specifies the tree object.
`np' specifies the pointer to a variable into which the number of elements of the return value
is assigned.
The return value is the pointer to the array of all string keys in the tree object.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. Note that elements of the array
point to the inner objects, whose life duration is synchronous with the tree object. */
const char **tctreekeys2(const TCTREE *tree, int *np);
/* Create an array of strings of all values in a tree object.
`tree' specifies the tree object.
`np' specifies the pointer to a variable into which the number of elements of the return value
is assigned.
The return value is the pointer to the array of all string values in the tree object.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. Note that elements of the array
point to the inner objects, whose life duration is synchronous with the tree object. */
const char **tctreevals2(const TCTREE *tree, int *np);
/* Extract a tree record from a serialized byte array.
`ptr' specifies the pointer to the region of serialized byte array.
`size' specifies the size of the region.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the value of the
corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. */
void *tctreeloadone(const void *ptr, int size, const void *kbuf, int ksiz, int *sp);
/* Perform formatted output into a tree object.
`map' specifies the tree object.
`kstr' specifies the string of the key.
`format' specifies the printf-like format string. The conversion character `%' can be used
with such flag characters as `s', `d', `o', `u', `x', `X', `c', `e', `E', `f', `g', `G', `@',
`?', `b', and `%'. `@' works as with `s' but escapes meta characters of XML. `?' works as
with `s' but escapes meta characters of URL. `b' converts an integer to the string as binary
numbers. The other conversion character work as with each original.
The other arguments are used according to the format string. */
void tctreeprintf(TCTREE *tree, const char *kstr, const char *format, ...);
/*************************************************************************************************
* on-memory hash database
*************************************************************************************************/
typedef struct { /* type of structure for a on-memory hash database */
void **mmtxs; /* mutexes for method */
void *imtx; /* mutex for iterator */
TCMAP **maps; /* internal map objects */
int iter; /* index of maps for the iterator */
} TCMDB;
/* Create an on-memory hash database object.
The return value is the new on-memory hash database object.
The object can be shared by plural threads because of the internal mutex. */
TCMDB *tcmdbnew(void);
/* Create an on-memory hash database object with specifying the number of the buckets.
`bnum' specifies the number of the buckets.
The return value is the new on-memory hash database object.
The object can be shared by plural threads because of the internal mutex. */
TCMDB *tcmdbnew2(uint32_t bnum);
/* Delete an on-memory hash database object.
`mdb' specifies the on-memory hash database object. */
void tcmdbdel(TCMDB *mdb);
/* Store a record into an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If a record with the same key exists in the database, it is overwritten. */
void tcmdbput(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Store a string record into an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If a record with the same key exists in the database, it is overwritten. */
void tcmdbput2(TCMDB *mdb, const char *kstr, const char *vstr);
/* Store a new record into an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this function has no effect. */
bool tcmdbputkeep(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Store a new string record into an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this function has no effect. */
bool tcmdbputkeep2(TCMDB *mdb, const char *kstr, const char *vstr);
/* Concatenate a value at the end of the existing record in an on-memory hash database.
`mdb' specifies the on-memory hash database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If there is no corresponding record, a new record is created. */
void tcmdbputcat(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Concatenate a string at the end of the existing record in an on-memory hash database.
`mdb' specifies the on-memory hash database object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If there is no corresponding record, a new record is created. */
void tcmdbputcat2(TCMDB *mdb, const char *kstr, const char *vstr);
/* Remove a record of an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
If successful, the return value is true. False is returned when no record corresponds to
the specified key. */
bool tcmdbout(TCMDB *mdb, const void *kbuf, int ksiz);
/* Remove a string record of an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kstr' specifies the string of the key.
If successful, the return value is true. False is returned when no record corresponds to
the specified key. */
bool tcmdbout2(TCMDB *mdb, const char *kstr);
/* Retrieve a record in an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the value of the
corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when
it is no longer in use. */
void *tcmdbget(TCMDB *mdb, const void *kbuf, int ksiz, int *sp);
/* Retrieve a string record in an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kstr' specifies the string of the key.
If successful, the return value is the string of the value of the corresponding record.
`NULL' is returned when no record corresponds.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcmdbget2(TCMDB *mdb, const char *kstr);
/* Get the size of the value of a record in an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
If successful, the return value is the size of the value of the corresponding record, else,
it is -1. */
int tcmdbvsiz(TCMDB *mdb, const void *kbuf, int ksiz);
/* Get the size of the value of a string record in an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kstr' specifies the string of the key.
If successful, the return value is the size of the value of the corresponding record, else,
it is -1. */
int tcmdbvsiz2(TCMDB *mdb, const char *kstr);
/* Initialize the iterator of an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
The iterator is used in order to access the key of every record stored in the on-memory
database. */
void tcmdbiterinit(TCMDB *mdb);
/* Get the next key of the iterator of an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the next key, else, it is
`NULL'. `NULL' is returned when no record can be fetched from the iterator.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when
it is no longer in use. The order of iteration is assured to be the same as the stored
order. */
void *tcmdbiternext(TCMDB *mdb, int *sp);
/* Get the next key string of the iterator of an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
If successful, the return value is the pointer to the region of the next key, else, it is
`NULL'. `NULL' is returned when no record can be fetched from the iterator.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. The order of iteration is assured
to be the same as the stored order. */
char *tcmdbiternext2(TCMDB *mdb);
/* Get forward matching keys in an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`pbuf' specifies the pointer to the region of the prefix.
`psiz' specifies the size of the region of the prefix.
`max' specifies the maximum number of keys to be fetched. If it is negative, no limit is
specified.
The return value is a list object of the corresponding keys. This function does never fail.
It returns an empty list even if no key corresponds.
Because the object of the return value is created with the function `tclistnew', it should be
deleted with the function `tclistdel' when it is no longer in use. Note that this function
may be very slow because every key in the database is scanned. */
TCLIST *tcmdbfwmkeys(TCMDB *mdb, const void *pbuf, int psiz, int max);
/* Get forward matching string keys in an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`pstr' specifies the string of the prefix.
`max' specifies the maximum number of keys to be fetched. If it is negative, no limit is
specified.
The return value is a list object of the corresponding keys. This function does never fail.
It returns an empty list even if no key corresponds.
Because the object of the return value is created with the function `tclistnew', it should be
deleted with the function `tclistdel' when it is no longer in use. Note that this function
may be very slow because every key in the database is scanned. */
TCLIST *tcmdbfwmkeys2(TCMDB *mdb, const char *pstr, int max);
/* Get the number of records stored in an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
The return value is the number of the records stored in the database. */
uint64_t tcmdbrnum(TCMDB *mdb);
/* Get the total size of memory used in an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
The return value is the total size of memory used in the database. */
uint64_t tcmdbmsiz(TCMDB *mdb);
/* Add an integer to a record in an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`num' specifies the additional value.
The return value is the summation value.
If the corresponding record exists, the value is treated as an integer and is added to. If no
record corresponds, a new record of the additional value is stored. */
int tcmdbaddint(TCMDB *mdb, const void *kbuf, int ksiz, int num);
/* Add a real number to a record in an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`num' specifies the additional value.
The return value is the summation value.
If the corresponding record exists, the value is treated as a real number and is added to. If
no record corresponds, a new record of the additional value is stored. */
double tcmdbadddouble(TCMDB *mdb, const void *kbuf, int ksiz, double num);
/* Clear an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
All records are removed. */
void tcmdbvanish(TCMDB *mdb);
/* Remove front records of an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`num' specifies the number of records to be removed. */
void tcmdbcutfront(TCMDB *mdb, int num);
/*************************************************************************************************
* on-memory hash database (for experts)
*************************************************************************************************/
/* Store a record and make it semivolatile in an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If a record with the same key exists in the map, it is overwritten. The record is moved to
the tail. */
void tcmdbput3(TCMDB *mdb, const void *kbuf, int ksiz, const char *vbuf, int vsiz);
/* Store a record of the value of two regions into an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`fvbuf' specifies the pointer to the former region of the value.
`fvsiz' specifies the size of the former region of the value.
`lvbuf' specifies the pointer to the latter region of the value.
`lvsiz' specifies the size of the latter region of the value.
If a record with the same key exists in the database, it is overwritten. */
void tcmdbput4(TCMDB *mdb, const void *kbuf, int ksiz,
const void *fvbuf, int fvsiz, const void *lvbuf, int lvsiz);
/* Concatenate a value and make it semivolatile in on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If there is no corresponding record, a new record is created. */
void tcmdbputcat3(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Store a record into a on-memory hash database object with a duplication handler.
`mdb' specifies the on-memory hash database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value. `NULL' means that record addition is
ommited if there is no corresponding record.
`vsiz' specifies the size of the region of the value.
`proc' specifies the pointer to the callback function to process duplication. It receives
four parameters. The first parameter is the pointer to the region of the value. The second
parameter is the size of the region of the value. The third parameter is the pointer to the
variable into which the size of the region of the return value is assigned. The fourth
parameter is the pointer to the optional opaque object. It returns the pointer to the result
object allocated with `malloc'. It is released by the caller. If it is `NULL', the record is
not modified. If it is `(void *)-1', the record is removed.
`op' specifies an arbitrary pointer to be given as a parameter of the callback function. If
it is not needed, `NULL' can be specified.
If successful, the return value is true, else, it is false. */
bool tcmdbputproc(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz,
TCPDPROC proc, void *op);
/* Retrieve a record and move it astern in an on-memory hash database object.
`mdb' specifies the on-memory hash database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the value of the
corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return value
is allocated with the `malloc' call, it should be released with the `free' call when it is no
longer in use. The internal region of the returned record is moved to the tail so that the
record will survive for a time under LRU cache algorithm removing records from the head. */
void *tcmdbget3(TCMDB *mdb, const void *kbuf, int ksiz, int *sp);
/* Initialize the iterator of an on-memory map database object in front of a key.
`mdb' specifies the on-memory map database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
If there is no record corresponding the condition, the iterator is not modified. */
void tcmdbiterinit2(TCMDB *mdb, const void *kbuf, int ksiz);
/* Initialize the iterator of an on-memory map database object in front of a key string.
`mdb' specifies the on-memory map database object.
`kstr' specifies the string of the key.
If there is no record corresponding the condition, the iterator is not modified. */
void tcmdbiterinit3(TCMDB *mdb, const char *kstr);
/* Process each record atomically of an on-memory hash database object.
`iter' specifies the pointer to the iterator function called for each record. It receives
five parameters. The first parameter is the pointer to the region of the key. The second
parameter is the size of the region of the key. The third parameter is the pointer to the
region of the value. The fourth parameter is the size of the region of the value. The fifth
parameter is the pointer to the optional opaque object. It returns true to continue iteration
or false to stop iteration.
`op' specifies an arbitrary pointer to be given as a parameter of the iterator function. If
it is not needed, `NULL' can be specified. */
void tcmdbforeach(TCMDB *mdb, TCITER iter, void *op);
/*************************************************************************************************
* on-memory tree database
*************************************************************************************************/
typedef struct { /* type of structure for a on-memory tree database */
void *mmtx; /* mutex for method */
TCTREE *tree; /* internal tree object */
} TCNDB;
/* Create an on-memory tree database object.
The return value is the new on-memory tree database object.
The object can be shared by plural threads because of the internal mutex. */
TCNDB *tcndbnew(void);
/* Create an on-memory tree database object with specifying the custom comparison function.
`cmp' specifies the pointer to the custom comparison function.
`cmpop' specifies an arbitrary pointer to be given as a parameter of the comparison function.
If it is not needed, `NULL' can be specified.
The return value is the new on-memory tree database object.
The default comparison function compares keys of two records by lexical order. The functions
`tccmplexical' (dafault), `tccmpdecimal', `tccmpint32', and `tccmpint64' are built-in. The
object can be shared by plural threads because of the internal mutex. */
TCNDB *tcndbnew2(TCCMP cmp, void *cmpop);
/* Delete an on-memory tree database object.
`ndb' specifies the on-memory tree database object. */
void tcndbdel(TCNDB *ndb);
/* Store a record into an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If a record with the same key exists in the database, it is overwritten. */
void tcndbput(TCNDB *ndb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Store a string record into an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If a record with the same key exists in the database, it is overwritten. */
void tcndbput2(TCNDB *ndb, const char *kstr, const char *vstr);
/* Store a new record into an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this function has no effect. */
bool tcndbputkeep(TCNDB *ndb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Store a new string record into an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this function has no effect. */
bool tcndbputkeep2(TCNDB *ndb, const char *kstr, const char *vstr);
/* Concatenate a value at the end of the existing record in an on-memory tree database.
`ndb' specifies the on-memory tree database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If there is no corresponding record, a new record is created. */
void tcndbputcat(TCNDB *ndb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Concatenate a string at the end of the existing record in an on-memory tree database.
`ndb' specifies the on-memory tree database object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If there is no corresponding record, a new record is created. */
void tcndbputcat2(TCNDB *ndb, const char *kstr, const char *vstr);
/* Remove a record of an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
If successful, the return value is true. False is returned when no record corresponds to
the specified key. */
bool tcndbout(TCNDB *ndb, const void *kbuf, int ksiz);
/* Remove a string record of an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`kstr' specifies the string of the key.
If successful, the return value is true. False is returned when no record corresponds to
the specified key. */
bool tcndbout2(TCNDB *ndb, const char *kstr);
/* Retrieve a record in an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the value of the
corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when
it is no longer in use. */
void *tcndbget(TCNDB *ndb, const void *kbuf, int ksiz, int *sp);
/* Retrieve a string record in an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`kstr' specifies the string of the key.
If successful, the return value is the string of the value of the corresponding record.
`NULL' is returned when no record corresponds.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcndbget2(TCNDB *ndb, const char *kstr);
/* Get the size of the value of a record in an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
If successful, the return value is the size of the value of the corresponding record, else,
it is -1. */
int tcndbvsiz(TCNDB *ndb, const void *kbuf, int ksiz);
/* Get the size of the value of a string record in an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`kstr' specifies the string of the key.
If successful, the return value is the size of the value of the corresponding record, else,
it is -1. */
int tcndbvsiz2(TCNDB *ndb, const char *kstr);
/* Initialize the iterator of an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
The iterator is used in order to access the key of every record stored in the on-memory
database. */
void tcndbiterinit(TCNDB *ndb);
/* Get the next key of the iterator of an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the next key, else, it is
`NULL'. `NULL' is returned when no record can be fetched from the iterator.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when
it is no longer in use. The order of iteration is assured to be the same as the stored
order. */
void *tcndbiternext(TCNDB *ndb, int *sp);
/* Get the next key string of the iterator of an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
If successful, the return value is the pointer to the region of the next key, else, it is
`NULL'. `NULL' is returned when no record can be fetched from the iterator.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. The order of iteration is assured
to be the same as the stored order. */
char *tcndbiternext2(TCNDB *ndb);
/* Get forward matching keys in an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`pbuf' specifies the pointer to the region of the prefix.
`psiz' specifies the size of the region of the prefix.
`max' specifies the maximum number of keys to be fetched. If it is negative, no limit is
specified.
The return value is a list object of the corresponding keys. This function does never fail.
It returns an empty list even if no key corresponds.
Because the object of the return value is created with the function `tclistnew', it should be
deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tcndbfwmkeys(TCNDB *ndb, const void *pbuf, int psiz, int max);
/* Get forward matching string keys in an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`pstr' specifies the string of the prefix.
`max' specifies the maximum number of keys to be fetched. If it is negative, no limit is
specified.
The return value is a list object of the corresponding keys. This function does never fail.
It returns an empty list even if no key corresponds.
Because the object of the return value is created with the function `tclistnew', it should be
deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tcndbfwmkeys2(TCNDB *ndb, const char *pstr, int max);
/* Get the number of records stored in an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
The return value is the number of the records stored in the database. */
uint64_t tcndbrnum(TCNDB *ndb);
/* Get the total size of memory used in an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
The return value is the total size of memory used in the database. */
uint64_t tcndbmsiz(TCNDB *ndb);
/* Add an integer to a record in an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`num' specifies the additional value.
The return value is the summation value.
If the corresponding record exists, the value is treated as an integer and is added to. If no
record corresponds, a new record of the additional value is stored. */
int tcndbaddint(TCNDB *ndb, const void *kbuf, int ksiz, int num);
/* Add a real number to a record in an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`num' specifies the additional value.
The return value is the summation value.
If the corresponding record exists, the value is treated as a real number and is added to. If
no record corresponds, a new record of the additional value is stored. */
double tcndbadddouble(TCNDB *ndb, const void *kbuf, int ksiz, double num);
/* Clear an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
All records are removed. */
void tcndbvanish(TCNDB *ndb);
/* Remove fringe records of an on-memory tree database object.
`ndb' specifies the on-memory tree database object.
`num' specifies the number of records to be removed. */
void tcndbcutfringe(TCNDB *ndb, int num);
/*************************************************************************************************
* ordered tree (for experts)
*************************************************************************************************/
/* Store a record into a on-memory tree database without balancing nodes.
`ndb' specifies the on-memory tree database.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If a record with the same key exists in the database, it is overwritten. The structure of the
tree is not modifed by this function. */
void tcndbput3(TCNDB *ndb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Store a new record into a on-memory tree database object without balancing nodes.
`ndb' specifies the on-memory tree database.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this function has no effect. The
structure of the tree is not modifed by this function. */
bool tcndbputkeep3(TCNDB *ndb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Concatenate a value in a on-memory tree database without balancing nodes.
`ndb' specifies the on-memory tree database.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If there is no corresponding record, a new record is created. The structure of the tree is
not modifed by this function. */
void tcndbputcat3(TCNDB *ndb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
/* Store a record into a on-memory tree database object with a duplication handler.
`ndb' specifies the on-memory tree database.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value. `NULL' means that record addition is
ommited if there is no corresponding record.
`vsiz' specifies the size of the region of the value.
`proc' specifies the pointer to the callback function to process duplication. It receives
four parameters. The first parameter is the pointer to the region of the value. The second
parameter is the size of the region of the value. The third parameter is the pointer to the
variable into which the size of the region of the return value is assigned. The fourth
parameter is the pointer to the optional opaque object. It returns the pointer to the result
object allocated with `malloc'. It is released by the caller. If it is `NULL', the record is
not modified. If it is `(void *)-1', the record is removed.
`op' specifies an arbitrary pointer to be given as a parameter of the callback function. If
it is not needed, `NULL' can be specified.
If successful, the return value is true, else, it is false. */
bool tcndbputproc(TCNDB *ndb, const void *kbuf, int ksiz, const void *vbuf, int vsiz,
TCPDPROC proc, void *op);
/* Retrieve a record in an on-memory tree database object without balancing nodes.
`ndb' specifies the on-memory tree database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the value of the
corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return value
is allocated with the `malloc' call, it should be released with the `free' call when it is no
longer in use. The structure of the tree is not modifed by this function. */
void *tcndbget3(TCNDB *ndb, const void *kbuf, int ksiz, int *sp);
/* Initialize the iterator of an on-memory tree database object in front of a key.
`ndb' specifies the on-memory tree database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
The iterator is set to the first record corresponding the key or the next substitute if
completely matching record does not exist. */
void tcndbiterinit2(TCNDB *ndb, const void *kbuf, int ksiz);
/* Initialize the iterator of an on-memory tree database object in front of a key string.
`ndb' specifies the on-memory tree database object.
`kstr' specifies the string of the key.
The iterator is set to the first record corresponding the key or the next substitute if
completely matching record does not exist. */
void tcndbiterinit3(TCNDB *ndb, const char *kstr);
/* Process each record atomically of an on-memory tree database object.
`iter' specifies the pointer to the iterator function called for each record. It receives
five parameters. The first parameter is the pointer to the region of the key. The second
parameter is the size of the region of the key. The third parameter is the pointer to the
region of the value. The fourth parameter is the size of the region of the value. The fifth
parameter is the pointer to the optional opaque object. It returns true to continue iteration
or false to stop iteration.
`op' specifies an arbitrary pointer to be given as a parameter of the iterator function. If
it is not needed, `NULL' can be specified. */
void tcndbforeach(TCNDB *ndb, TCITER iter, void *op);
/*************************************************************************************************
* memory pool
*************************************************************************************************/
typedef struct { /* type of an element of memory pool */
void *ptr; /* pointer */
void (*del)(void *); /* deleting function */
} TCMPELEM;
typedef struct { /* type of structure for a memory pool object */
void *mutex; /* mutex for operations */
TCMPELEM *elems; /* array of elements */
int anum; /* number of the elements of the array */
int num; /* number of used elements */
} TCMPOOL;
/* Create a memory pool object.
The return value is the new memory pool object. */
TCMPOOL *tcmpoolnew(void);
/* Delete a memory pool object.
`mpool' specifies the memory pool object.
Note that the deleted object and its derivatives can not be used anymore. */
void tcmpooldel(TCMPOOL *mpool);
/* Relegate an arbitrary object to a memory pool object.
`mpool' specifies the memory pool object.
`ptr' specifies the pointer to the object to be relegated. If it is `NULL', this function has
no effect.
`del' specifies the pointer to the function to delete the object.
The return value is the pointer to the given object.
This function assures that the specified object is deleted when the memory pool object is
deleted. */
void *tcmpoolpush(TCMPOOL *mpool, void *ptr, void (*del)(void *));
/* Relegate an allocated region to a memory pool object.
`mpool' specifies the memory pool object.
`ptr' specifies the pointer to the region to be relegated. If it is `NULL', this function has
no effect.
The return value is the pointer to the given object.
This function assures that the specified region is released when the memory pool object is
deleted. */
void *tcmpoolpushptr(TCMPOOL *mpool, void *ptr);
/* Relegate an extensible string object to a memory pool object.
`mpool' specifies the memory pool object.
`xstr' specifies the extensible string object. If it is `NULL', this function has no effect.
The return value is the pointer to the given object.
This function assures that the specified object is deleted when the memory pool object is
deleted. */
TCXSTR *tcmpoolpushxstr(TCMPOOL *mpool, TCXSTR *xstr);
/* Relegate a list object to a memory pool object.
`mpool' specifies the memory pool object.
`list' specifies the list object. If it is `NULL', this function has no effect.
The return value is the pointer to the given object.
This function assures that the specified object is deleted when the memory pool object is
deleted. */
TCLIST *tcmpoolpushlist(TCMPOOL *mpool, TCLIST *list);
/* Relegate a map object to a memory pool object.
`mpool' specifies the memory pool object.
`map' specifies the map object. If it is `NULL', this function has no effect.
The return value is the pointer to the given object.
This function assures that the specified object is deleted when the memory pool object is
deleted. */
TCMAP *tcmpoolpushmap(TCMPOOL *mpool, TCMAP *map);
/* Relegate a tree object to a memory pool object.
`mpool' specifies the memory pool object.
`tree' specifies the tree object. If it is `NULL', this function has no effect.
The return value is the pointer to the given object.
This function assures that the specified object is deleted when the memory pool object is
deleted. */
TCTREE *tcmpoolpushtree(TCMPOOL *mpool, TCTREE *tree);
/* Allocate a region relegated to a memory pool object.
`mpool' specifies the memory pool object.
The return value is the pointer to the allocated region under the memory pool. */
void *tcmpoolmalloc(TCMPOOL *mpool, size_t size);
/* Create an extensible string object relegated to a memory pool object.
The return value is the new extensible string object under the memory pool. */
TCXSTR *tcmpoolxstrnew(TCMPOOL *mpool);
/* Create a list object relegated to a memory pool object.
The return value is the new list object under the memory pool. */
TCLIST *tcmpoollistnew(TCMPOOL *mpool);
/* Create a map object relegated to a memory pool object.
The return value is the new map object under the memory pool. */
TCMAP *tcmpoolmapnew(TCMPOOL *mpool);
/* Create a tree object relegated to a memory pool object.
The return value is the new tree object under the memory pool. */
TCTREE *tcmpooltreenew(TCMPOOL *mpool);
/* Remove the most recently installed cleanup handler of a memory pool object.
`mpool' specifies the memory pool object.
`exe' specifies whether to execute the destructor of the removed handler. */
void tcmpoolpop(TCMPOOL *mpool, bool exe);
/* Remove all cleanup handler of a memory pool object.
`mpool' specifies the memory pool object.
`exe' specifies whether to execute the destructors of the removed handlers. */
void tcmpoolclear(TCMPOOL *mpool, bool exe);
/* Get the global memory pool object.
The return value is the global memory pool object.
The global memory pool object is a singleton and assured to be deleted when the porcess is
terminating normally. */
TCMPOOL *tcmpoolglobal(void);
/*************************************************************************************************
* miscellaneous utilities
*************************************************************************************************/
/* Get the larger value of two integers.
`a' specifies an integer.
`b' specifies the other integer.
The return value is the larger value of the two. */
long tclmax(long a, long b);
/* Get the lesser value of two integers.
`a' specifies an integer.
`b' specifies the other integer.
The return value is the lesser value of the two. */
long tclmin(long a, long b);
/* Get a random number as long integer based on uniform distribution.
The return value is the random number between 0 and `ULONG_MAX'.
This function uses the random number source device and generates a real random number if
possible. */
unsigned long tclrand(void);
/* Get a random number as double decimal based on uniform distribution.
The return value is the random number equal to or greater than 0, and less than 1.0.
This function uses the random number source device and generates a real random number if
possible. */
double tcdrand(void);
/* Get a random number as double decimal based on normal distribution.
`avg' specifies the average.
`sd' specifies the standard deviation.
The return value is the random number.
This function uses the random number source device and generates a real random number if
possible. */
double tcdrandnd(double avg, double sd);
/* Compare two strings with case insensitive evaluation.
`astr' specifies a string.
`bstr' specifies of the other string.
The return value is positive if the former is big, negative if the latter is big, 0 if both
are equivalent. */
int tcstricmp(const char *astr, const char *bstr);
/* Check whether a string begins with a key.
`str' specifies the target string.
`key' specifies the forward matching key string.
The return value is true if the target string begins with the key, else, it is false. */
bool tcstrfwm(const char *str, const char *key);
/* Check whether a string begins with a key with case insensitive evaluation.
`str' specifies the target string.
`key' specifies the forward matching key string.
The return value is true if the target string begins with the key, else, it is false. */
bool tcstrifwm(const char *str, const char *key);
/* Check whether a string ends with a key.
`str' specifies the target string.
`key' specifies the backward matching key string.
The return value is true if the target string ends with the key, else, it is false. */
bool tcstrbwm(const char *str, const char *key);
/* Check whether a string ends with a key with case insensitive evaluation.
`str' specifies the target string.
`key' specifies the backward matching key string.
The return value is true if the target string ends with the key, else, it is false. */
bool tcstribwm(const char *str, const char *key);
/* Calculate the edit distance of two strings.
`astr' specifies a string.
`bstr' specifies of the other string.
The return value is the edit distance which is known as the Levenshtein distance. The cost is
calculated by byte. */
int tcstrdist(const char *astr, const char *bstr);
/* Calculate the edit distance of two UTF-8 strings.
`astr' specifies a string.
`bstr' specifies of the other string.
The return value is the edit distance which is known as the Levenshtein distance. The cost is
calculated by Unicode character. */
int tcstrdistutf(const char *astr, const char *bstr);
/* Convert the letters of a string into upper case.
`str' specifies the string to be converted.
The return value is the string itself. */
char *tcstrtoupper(char *str);
/* Convert the letters of a string into lower case.
`str' specifies the string to be converted.
The return value is the string itself. */
char *tcstrtolower(char *str);
/* Cut space characters at head or tail of a string.
`str' specifies the string to be converted.
The return value is the string itself. */
char *tcstrtrim(char *str);
/* Squeeze space characters in a string and trim it.
`str' specifies the string to be converted.
The return value is the string itself. */
char *tcstrsqzspc(char *str);
/* Substitute characters in a string.
`str' specifies the string to be converted.
`rstr' specifies the string containing characters to be replaced.
`sstr' specifies the string containing characters to be substituted.
If the substitute string is shorter then the replacement string, corresponding characters are
removed. */
char *tcstrsubchr(char *str, const char *rstr, const char *sstr);
/* Count the number of characters in a string of UTF-8.
`str' specifies the string of UTF-8.
The return value is the number of characters in the string. */
int tcstrcntutf(const char *str);
/* Cut a string of UTF-8 at the specified number of characters.
`str' specifies the string of UTF-8.
`num' specifies the number of characters to be kept.
The return value is the string itself. */
char *tcstrcututf(char *str, int num);
/* Convert a UTF-8 string into a UCS-2 array.
`str' specifies the UTF-8 string.
`ary' specifies the pointer to the region into which the result UCS-2 codes are written. The
size of the buffer should be sufficient.
`np' specifies the pointer to a variable into which the number of elements of the result array
is assigned. */
void tcstrutftoucs(const char *str, uint16_t *ary, int *np);
/* Convert a UCS-2 array into a UTF-8 string.
`ary' specifies the array of UCS-2 codes.
`num' specifies the number of the array.
`str' specifies the pointer to the region into which the result UTF-8 string is written. The
size of the buffer should be sufficient.
The return value is the length of the result string. */
int tcstrucstoutf(const uint16_t *ary, int num, char *str);
/* Create a list object by splitting a string.
`str' specifies the source string.
`delim' specifies a string containing delimiting characters.
The return value is a list object of the split elements.
If two delimiters are successive, it is assumed that an empty element is between the two.
Because the object of the return value is created with the function `tclistnew', it should be
deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tcstrsplit(const char *str, const char *delims);
/* Create a string by joining all elements of a list object.
`list' specifies a list object.
`delim' specifies a delimiting character.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcstrjoin(const TCLIST *list, char delim);
/* Convert a string to an integer.
`str' specifies the string.
The return value is the integer. If the string does not contain numeric expression, 0 is
returned.
This function is equivalent to `atoll' except that it does not depend on the locale. */
int64_t tcatoi(const char *str);
/* Convert a string with a metric prefix to an integer.
`str' specifies the string, which can be trailed by a binary metric prefix. "K", "M", "G",
"T", "P", and "E" are supported. They are case-insensitive.
The return value is the integer. If the string does not contain numeric expression, 0 is
returned. If the integer overflows the domain, `INT64_MAX' or `INT64_MIN' is returned
according to the sign. */
int64_t tcatoix(const char *str);
/* Convert a string to a real number.
`str' specifies the string.
The return value is the real number. If the string does not contain numeric expression, 0.0
is returned.
This function is equivalent to `atof' except that it does not depend on the locale. */
double tcatof(const char *str);
/* Check whether a string matches a regular expression.
`str' specifies the target string.
`regex' specifies the regular expression string. If it begins with `*', the trailing
substring is used as a case-insensitive regular expression.
The return value is true if matching is success, else, it is false. */
bool tcregexmatch(const char *str, const char *regex);
/* Replace each substring matching a regular expression string.
`str' specifies the target string.
`regex' specifies the regular expression string for substrings. If it begins with `*', the
trailing substring is used as a case-insensitive regular expression.
`alt' specifies the alternative string with which each substrings is replaced. Each `&' in
the string is replaced with the matched substring. Each `\' in the string escapes the
following character. Special escapes "\1" through "\9" referring to the corresponding
matching sub-expressions in the regular expression string are supported.
The return value is a new converted string. Even if the regular expression is invalid, a copy
of the original string is returned.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcregexreplace(const char *str, const char *regex, const char *alt);
/* Get the MD5 hash value of a serial object.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`buf' specifies the pointer to the region into which the result string is written. The size
of the buffer should be equal to or more than 48 bytes. */
void tcmd5hash(const void *ptr, int size, char *buf);
/* Cipher or decipher a serial object with the Arcfour stream cipher.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`kbuf' specifies the pointer to the region of the cipher key.
`ksiz' specifies the size of the region of the cipher key.
`obuf' specifies the pointer to the region into which the result data is written. The size
of the buffer should be equal to or more than the input region. */
void tcarccipher(const void *ptr, int size, const void *kbuf, int ksiz, void *obuf);
/* Get the time of day in seconds.
The return value is the time of day in seconds. The accuracy is in microseconds. */
double tctime(void);
/* Get the Gregorian calendar of a time.
`t' specifies the source time in seconds from the epoch. If it is `INT64_MAX', the current
time is specified.
`jl' specifies the jet lag of a location in seconds. If it is `INT_MAX', the local jet lag is
specified.
`yearp' specifies the pointer to a variable to which the year is assigned. If it is `NULL',
it is not used.
`monp' specifies the pointer to a variable to which the month is assigned. If it is `NULL',
it is not used. 1 means January and 12 means December.
`dayp' specifies the pointer to a variable to which the day of the month is assigned. If it
is `NULL', it is not used.
`hourp' specifies the pointer to a variable to which the hours is assigned. If it is `NULL',
it is not used.
`minp' specifies the pointer to a variable to which the minutes is assigned. If it is `NULL',
it is not used.
`secp' specifies the pointer to a variable to which the seconds is assigned. If it is `NULL',
it is not used. */
void tccalendar(int64_t t, int jl, int *yearp, int *monp, int *dayp,
int *hourp, int *minp, int *secp);
/* Format a date as a string in W3CDTF.
`t' specifies the source time in seconds from the epoch. If it is `INT64_MAX', the current
time is specified.
`jl' specifies the jet lag of a location in seconds. If it is `INT_MAX', the local jet lag is
specified.
`buf' specifies the pointer to the region into which the result string is written. The size
of the buffer should be equal to or more than 48 bytes.
W3CDTF represents a date as "YYYY-MM-DDThh:mm:ddTZD". */
void tcdatestrwww(int64_t t, int jl, char *buf);
/* Format a date as a string in RFC 1123 format.
`t' specifies the source time in seconds from the epoch. If it is `INT64_MAX', the current
time is specified.
`jl' specifies the jet lag of a location in seconds. If it is `INT_MAX', the local jet lag is
specified.
`buf' specifies the pointer to the region into which the result string is written. The size
of the buffer should be equal to or more than 48 bytes.
RFC 1123 format represents a date as "Wdy, DD-Mon-YYYY hh:mm:dd TZD". */
void tcdatestrhttp(int64_t t, int jl, char *buf);
/* Get the time value of a date string.
`str' specifies the date string in decimal, hexadecimal, W3CDTF, or RFC 822 (1123). Decimal
can be trailed by "s" for in seconds, "m" for in minutes, "h" for in hours, and "d" for in
days.
The return value is the time value of the date or `INT64_MIN' if the format is invalid. */
int64_t tcstrmktime(const char *str);
/* Get the jet lag of the local time.
The return value is the jet lag of the local time in seconds. */
int tcjetlag(void);
/* Get the day of week of a date.
`year' specifies the year of a date.
`mon' specifies the month of the date.
`day' specifies the day of the date.
The return value is the day of week of the date. 0 means Sunday and 6 means Saturday. */
int tcdayofweek(int year, int mon, int day);
/*************************************************************************************************
* miscellaneous utilities (for experts)
*************************************************************************************************/
enum { /* enumeration for UCS normalization */
TCUNSPACE = 1 << 0, /* white space normalization */
TCUNLOWER = 1 << 1, /* lower case normalization */
TCUNNOACC = 1 << 2, /* strip accent marks */
TCUNWIDTH = 1 << 3 /* half-width normalization */
};
enum { /* enumeration for KWIC generator */
TCKWMUTAB = 1 << 0, /* mark up by tabs */
TCKWMUCTRL = 1 << 1, /* mark up by control characters */
TCKWMUBRCT = 1 << 2, /* mark up by brackets */
TCKWNOOVER = 1 << 24, /* no overlap */
TCKWPULEAD = 1 << 25 /* pick up the lead string */
};
typedef struct { /* type of structure for a consistent hashing node */
uint32_t seq; /* sequential number */
uint32_t hash; /* hash value */
} TCCHIDXNODE;
typedef struct { /* type of structure for a consistent hashing object */
TCCHIDXNODE *nodes; /* node array */
int nnum; /* number of the node array */
} TCCHIDX;
/* Check whether a string is numeric completely or not.
`str' specifies the string to be checked.
The return value is true if the string is numeric, else, it is false. */
bool tcstrisnum(const char *str);
/* Convert a hexadecimal string to an integer.
`str' specifies the string.
The return value is the integer. If the string does not contain numeric expression, 0 is
returned. */
int64_t tcatoih(const char *str);
/* Skip space characters at head of a string.
`str' specifies the string.
The return value is the pointer to the first non-space character. */
const char *tcstrskipspc(const char *str);
/* Normalize a UTF-8 string.
`str' specifies the string of UTF-8.
`opts' specifies options by bitwise-or: `TCUNSPACE' specifies that white space characters are
normalized into the ASCII space and they are squeezed into one, `TCUNLOWER' specifies that
alphabetical characters are normalized into lower cases, `TCUNNOACC' specifies that
alphabetical characters with accent marks are normalized without accent marks, `TCUNWIDTH'
specifies that full-width characters are normalized into half-width characters.
The return value is the string itself. */
char *tcstrutfnorm(char *str, int opts);
/* Normalize a UCS-2 array.
`ary' specifies the array of UCS-2 codes.
`num' specifies the number of elements of the array.
`opts' specifies options by bitwise-or: `TCUNSPACE' specifies that white space characters are
normalized into the ASCII space and they are squeezed into one, `TCUNLOWER' specifies that
alphabetical characters are normalized into lower cases, `TCUNNOACC' specifies that
alphabetical characters with accent marks are normalized without accent marks, `TCUNWIDTH'
specifies that full-width characters are normalized into half-width characters.
The return value is the number of elements of the result array. */
int tcstrucsnorm(uint16_t *ary, int num, int opts);
/* Generate a keyword-in-context string from a text and keywords.
`str' specifies the text string of UTF-8.
`words' specifies a list object of the keyword strings.
`width' specifies the width of strings picked up around each keyword.
`opts' specifies options by bitwise-or: `TCKWMUTAB' specifies that each keyword is marked up
between two tab characters, `TCKWMUCTRL' specifies that each keyword is marked up by the STX
(0x02) code and the ETX (0x03) code, `TCKWMUBRCT' specifies that each keyword is marked up by
the two square brackets, `TCKWNOOVER' specifies that each context does not overlap,
`TCKWPULEAD' specifies that the lead string is picked up forcibly.
The return value is the list object whose elements are strings around keywords.
Because the object of the return value is created with the function `tclistnew', it should
be deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tcstrkwic(const char *str, const TCLIST *words, int width, int opts);
/* Tokenize a text separating by white space characters.
`str' specifies the string.
The return value is the list object whose elements are extracted tokens.
Because the object of the return value is created with the function `tclistnew', it should
be deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tcstrtokenize(const char *str);
/* Create a list object by splitting a region by zero code.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is a list object of the split elements.
If two delimiters are successive, it is assumed that an empty element is between the two.
Because the object of the return value is created with the function `tclistnew', it should be
deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tcstrsplit2(const void *ptr, int size);
/* Create a map object by splitting a string.
`str' specifies the source string where the key and the value of each record are situated one
after the other.
`delim' specifies a string containing delimiting characters.
The return value is a map object of the split records.
Because the object of the return value is created with the function `tcmapnew', it should be
deleted with the function `tcmapdel' when it is no longer in use. */
TCMAP *tcstrsplit3(const char *str, const char *delims);
/* Create a map object by splitting a region by zero code.
`ptr' specifies the pointer to the region where the key and the value of each record are
situated one after the other.
`size' specifies the size of the region.
The return value is a map object of the split records.
Because the object of the return value is created with the function `tcmapnew', it should be
deleted with the function `tcmapdel' when it is no longer in use. */
TCMAP *tcstrsplit4(const void *ptr, int size);
/* Create a region separated by zero code by joining all elements of a list object.
`list' specifies a list object.
The return value is the result region.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
void *tcstrjoin2(const TCLIST *list, int *sp);
/* Create a string by joining all records of a map object.
`map' specifies a map object.
`delim' specifies a delimiting character.
The return value is the result string where the key and the value of each record are situated
one after the other.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcstrjoin3(const TCMAP *map, char delim);
/* Create a region separated by zero code by joining all records of a map object.
`list' specifies a list object.
The return value is the result region, where the key and the value of each record are
situated one after the other.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
void *tcstrjoin4(const TCMAP *map, int *sp);
/* Sort top records of an array.
`base' spacifies the pointer to an array.
`nmemb' specifies the number of elements of the array.
`size' specifies the size of each element.
`top' specifies the number of top records.
`compar' specifies the pointer to comparing function. The two arguments specify the pointers
of elements. The comparing function should returns positive if the former is big, negative
if the latter is big, 0 if both are equal. */
void tctopsort(void *base, size_t nmemb, size_t size, size_t top,
int(*compar)(const void *, const void *));
/* Suspend execution of the current thread.
`sec' specifies the interval of the suspension in seconds.
If successful, the return value is true, else, it is false. */
bool tcsleep(double sec);
/* Get the current system information.
The return value is a map object of the current system information or `NULL' on failure.
The key "utime" indicates the user time of the CPU. The key "stime" indicates the system time
of the CPU. The key "size" indicates the process size in bytes. The "rss" indicates the
resident set size in bytes. "total" indicates the total size of the real memory. "free"
indicates the free size of the real memory. "cached" indicates the cached size of the real
memory.
Because the object of the return value is created with the function `tcmapnew', it should be
deleted with the function `tcmapdel' when it is no longer in use. */
TCMAP *tcsysinfo(void);
/* Create a consistent hashing object.
`range' specifies the number of nodes. It should be more than 0. The range of hash values is
from 0 to less than the specified number.
The return value is the new consistent hashing object.
Consistent hashing is useful because the addition or removal of one node does not
significantly change the mapping of keys to nodes. */
TCCHIDX *tcchidxnew(int range);
/* Delete a consistent hashing object.
`chidx' specifies the consistent hashing object. */
void tcchidxdel(TCCHIDX *chidx);
/* Get the consistent hashing value of a record.
`chidx' specifies the consistent hashing object.
`ptr' specifies the pointer to the region of the record.
`size' specifies the size of the region.
The return value is the hash value of the record. */
int tcchidxhash(TCCHIDX *chidx, const void *ptr, int size);
/*************************************************************************************************
* filesystem utilities
*************************************************************************************************/
/* Get the canonicalized absolute path of a file.
`path' specifies the path of the file.
The return value is the canonicalized absolute path of a file, or `NULL' if the path is
invalid.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcrealpath(const char *path);
/* Get the status information of a file.
`path' specifies the path of the file.
`isdirp' specifies the pointer to a variable into which whether the file is a directory is
assigned. If it is `NULL', it is ignored.
`sizep' specifies the pointer to a variable into which the size of the file is assigned. If
it is `NULL', it is ignored.
`ntimep' specifies the pointer to a variable into which the size of the file is assigned. If
it is `NULL', it is ignored.
If successful, the return value is true, else, it is false. */
bool tcstatfile(const char *path, bool *isdirp, int64_t *sizep, int64_t *mtimep);
/* Read whole data of a file.
`path' specifies the path of the file. If it is `NULL', the standard input is specified.
`limit' specifies the limiting size of reading data. If it is not more than 0, the limitation
is not specified.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned. If it is `NULL', it is not used.
The return value is the pointer to the allocated region of the read data, or `NULL' if the
file could not be opened.
Because an additional zero code is appended at the end of the region of the return value, the
return value can be treated as a character string. Because the region of the return value is
allocated with the `malloc' call, it should be released with the `free' call when when is no
longer in use. */
void *tcreadfile(const char *path, int limit, int *sp);
/* Read every line of a file.
`path' specifies the path of the file. If it is `NULL', the standard input is specified.
The return value is a list object of every lines if successful, else it is `NULL'.
Line separators are cut out. Because the object of the return value is created with the
function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer
in use. */
TCLIST *tcreadfilelines(const char *path);
/* Write data into a file.
`path' specifies the path of the file. If it is `NULL', the standard output is specified.
`ptr' specifies the pointer to the data region.
`size' specifies the size of the region.
If successful, the return value is true, else, it is false. */
bool tcwritefile(const char *path, const void *ptr, int size);
/* Copy a file.
`src' specifies the path of the source file.
`dest' specifies the path of the destination file.
The return value is true if successful, else, it is false.
If the destination file exists, it is overwritten. */
bool tccopyfile(const char *src, const char *dest);
/* Read names of files in a directory.
`path' specifies the path of the directory.
The return value is a list object of names if successful, else it is `NULL'.
Links to the directory itself and to the parent directory are ignored.
Because the object of the return value is created with the function `tclistnew', it should
be deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tcreaddir(const char *path);
/* Expand a pattern into a list of matched paths.
`pattern' specifies the matching pattern.
The return value is a list object of matched paths. If no path is matched, an empty list is
returned.
Because the object of the return value is created with the function `tclistnew', it should
be deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tcglobpat(const char *pattern);
/* Remove a file or a directory and its sub ones recursively.
`path' specifies the path of the link.
If successful, the return value is true, else, it is false. False is returned when the link
does not exist or the permission is denied. */
bool tcremovelink(const char *path);
/* Write data into a file.
`fd' specifies the file descriptor.
`buf' specifies the buffer to be written.
`size' specifies the size of the buffer.
The return value is true if successful, else, it is false. */
bool tcwrite(int fd, const void *buf, size_t size);
/* Read data from a file.
`fd' specifies the file descriptor.
`buf' specifies the buffer to store into.
`size' specifies the size of the buffer.
The return value is true if successful, else, it is false. */
bool tcread(int fd, void *buf, size_t size);
/* Lock a file.
`fd' specifies the file descriptor.
`ex' specifies whether an exclusive lock or a shared lock is performed.
`nb' specifies whether to request with non-blocking.
The return value is true if successful, else, it is false. */
bool tclock(int fd, bool ex, bool nb);
/* Unlock a file.
`fd' specifies the file descriptor.
The return value is true if successful, else, it is false. */
bool tcunlock(int fd);
/* Execute a shell command.
`args' specifies an array of the command name and its arguments.
`anum' specifies the number of elements of the array.
The return value is the exit code of the command or `INT_MAX' on failure.
The command name and the arguments are quoted and meta characters are escaped. */
int tcsystem(const char **args, int anum);
/*************************************************************************************************
* encoding utilities
*************************************************************************************************/
/* Encode a serial object with URL encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. */
char *tcurlencode(const char *ptr, int size);
/* Decode a string encoded with URL encoding.
`str' specifies the encoded string.
`sp' specifies the pointer to a variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the result.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when
it is no longer in use. */
char *tcurldecode(const char *str, int *sp);
/* Break up a URL into elements.
`str' specifies the URL string.
The return value is the map object whose keys are the name of elements. The key "self"
specifies the URL itself. The key "scheme" indicates the scheme. The key "host" indicates
the host of the server. The key "port" indicates the port number of the server. The key
"authority" indicates the authority information. The key "path" indicates the path of the
resource. The key "file" indicates the file name without the directory section. The key
"query" indicates the query string. The key "fragment" indicates the fragment string.
Supported schema are HTTP, HTTPS, FTP, and FILE. Absolute URL and relative URL are supported.
Because the object of the return value is created with the function `tcmapnew', it should be
deleted with the function `tcmapdel' when it is no longer in use. */
TCMAP *tcurlbreak(const char *str);
/* Resolve a relative URL with an absolute URL.
`base' specifies the absolute URL of the base location.
`target' specifies the URL to be resolved.
The return value is the resolved URL. If the target URL is relative, a new URL of relative
location from the base location is returned. Else, a copy of the target URL is returned.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcurlresolve(const char *base, const char *target);
/* Encode a serial object with Base64 encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. */
char *tcbaseencode(const char *ptr, int size);
/* Decode a string encoded with Base64 encoding.
`str' specifies the encoded string.
`sp' specifies the pointer to a variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the result.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when
it is no longer in use. */
char *tcbasedecode(const char *str, int *sp);
/* Encode a serial object with Quoted-printable encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. */
char *tcquoteencode(const char *ptr, int size);
/* Decode a string encoded with Quoted-printable encoding.
`str' specifies the encoded string.
`sp' specifies the pointer to a variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the result.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when
it is no longer in use. */
char *tcquotedecode(const char *str, int *sp);
/* Encode a string with MIME encoding.
`str' specifies the string.
`encname' specifies the string of the name of the character encoding.
`base' specifies whether to use Base64 encoding. If it is false, Quoted-printable is used.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcmimeencode(const char *str, const char *encname, bool base);
/* Decode a string encoded with MIME encoding.
`str' specifies the encoded string.
`enp' specifies the pointer to the region into which the name of encoding is written. If it
is `NULL', it is not used. The size of the buffer should be equal to or more than 32 bytes.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcmimedecode(const char *str, char *enp);
/* Split a string of MIME into headers and the body.
`ptr' specifies the pointer to the region of MIME data.
`size' specifies the size of the region.
`headers' specifies a map object to store headers. If it is `NULL', it is not used. Each key
of the map is an uncapitalized header name.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the body data.
If the content type is defined, the header map has the key "TYPE" specifying the type. If the
character encoding is defined, the key "CHARSET" indicates the encoding name. If the boundary
string of multipart is defined, the key "BOUNDARY" indicates the string. If the content
disposition is defined, the key "DISPOSITION" indicates the direction. If the file name is
defined, the key "FILENAME" indicates the name. If the attribute name is defined, the key
"NAME" indicates the name. Because the region of the return value is allocated with the
`malloc' call, it should be released with the `free' call when it is no longer in use. */
char *tcmimebreak(const char *ptr, int size, TCMAP *headers, int *sp);
/* Split multipart data of MIME into its parts.
`ptr' specifies the pointer to the region of multipart data of MIME.
`size' specifies the size of the region.
`boundary' specifies the boundary string.
The return value is a list object. Each element of the list is the data of a part.
Because the object of the return value is created with the function `tclistnew', it should be
deleted with the function `tclistdel' when it is no longer in use. */
TCLIST *tcmimeparts(const char *ptr, int size, const char *boundary);
/* Encode a serial object with hexadecimal encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. */
char *tchexencode(const char *ptr, int size);
/* Decode a string encoded with hexadecimal encoding.
`str' specifies the encoded string.
`sp' specifies the pointer to a variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the result.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when
it is no longer in use. */
char *tchexdecode(const char *str, int *sp);
/* Compress a serial object with Packbits encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcpackencode(const char *ptr, int size, int *sp);
/* Decompress a serial object compressed with Packbits encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to a variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when it
is no longer in use. */
char *tcpackdecode(const char *ptr, int size, int *sp);
/* Compress a serial object with TCBS encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcbsencode(const char *ptr, int size, int *sp);
/* Decompress a serial object compressed with TCBS encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to a variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when it
is no longer in use. */
char *tcbsdecode(const char *ptr, int size, int *sp);
/* Compress a serial object with Deflate encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcdeflate(const char *ptr, int size, int *sp);
/* Decompress a serial object compressed with Deflate encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to a variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when it
is no longer in use. */
char *tcinflate(const char *ptr, int size, int *sp);
/* Compress a serial object with GZIP encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcgzipencode(const char *ptr, int size, int *sp);
/* Decompress a serial object compressed with GZIP encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to a variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when it
is no longer in use. */
char *tcgzipdecode(const char *ptr, int size, int *sp);
/* Get the CRC32 checksum of a serial object.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is the CRC32 checksum of the object. */
unsigned int tcgetcrc(const char *ptr, int size);
/* Compress a serial object with BZIP2 encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcbzipencode(const char *ptr, int size, int *sp);
/* Decompress a serial object compressed with BZIP2 encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to a variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when it
is no longer in use. */
char *tcbzipdecode(const char *ptr, int size, int *sp);
/* Encode an array of nonnegative integers with BER encoding.
`ary' specifies the pointer to the array of nonnegative integers.
`anum' specifies the size of the array.
`sp' specifies the pointer to a variable into which the size of the region of the return
value is assigned.
The return value is the pointer to the region of the result.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. */
char *tcberencode(const unsigned int *ary, int anum, int *sp);
/* Decode a serial object encoded with BER encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`np' specifies the pointer to a variable into which the number of elements of the return value
is assigned.
The return value is the pointer to the array of the result.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. */
unsigned int *tcberdecode(const char *ptr, int size, int *np);
/* Escape meta characters in a string with the entity references of XML.
`str' specifies the string.
The return value is the pointer to the escaped string.
This function escapes only `&', `<', `>', and `"'. Because the region of the return value
is allocated with the `malloc' call, it should be released with the `free' call when it is no
longer in use. */
char *tcxmlescape(const char *str);
/* Unescape entity references in a string of XML.
`str' specifies the string.
The return value is the unescaped string.
This function restores only `&', `<', `>', and `"'. Because the region of the
return value is allocated with the `malloc' call, it should be released with the `free' call
when it is no longer in use. */
char *tcxmlunescape(const char *str);
/*************************************************************************************************
* encoding utilities (for experts)
*************************************************************************************************/
/* Encode a map object into a string in the x-www-form-urlencoded format.
`params' specifies a map object of parameters.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tcwwwformencode(const TCMAP *params);
/* Decode a query string in the x-www-form-urlencoded format.
`str' specifies the query string.
`params' specifies a map object into which the result parameters are stored. */
void tcwwwformdecode(const char *str, TCMAP *params);
/* Decode a data region in the x-www-form-urlencoded or multipart-form-data format.
`ptr' specifies the pointer to the data region.
`size' specifies the size of the data region.
`type' specifies the value of the content-type header. If it is `NULL', the type is specified
as x-www-form-urlencoded.
`params' specifies a map object into which the result parameters are stored. */
void tcwwwformdecode2(const void *ptr, int size, const char *type, TCMAP *params);
/* Split an XML string into tags and text sections.
`str' specifies the string.
The return value is the list object whose elements are strings of tags or text sections.
Because the object of the return value is created with the function `tclistnew', it should
be deleted with the function `tclistdel' when it is no longer in use. Because this function
does not check validation, it can handle also HTML and SGML. */
TCLIST *tcxmlbreak(const char *str);
/* Get the map of attributes of an XML tag.
`str' specifies the pointer to the region of a tag string.
The return value is the map object containing attribute names and their values which are
unescaped. You can get the name of the tag with the key of an empty string.
Because the object of the return value is created with the function `tcmapnew', it should
be deleted with the function `tcmapdel' when it is no longer in use. */
TCMAP *tcxmlattrs(const char *str);
/* Escape meta characters in a string with backslash escaping of the C language.
`str' specifies the string.
The return value is the pointer to the escaped string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. */
char *tccstrescape(const char *str);
/* Unescape a string escaped by backslash escaping of the C language.
`str' specifies the string.
The return value is the unescaped string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. */
char *tccstrunescape(const char *str);
/* Escape meta characters in a string with backslash escaping of JSON.
`str' specifies the string.
The return value is the pointer to the escaped string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. */
char *tcjsonescape(const char *str);
/* Unescape a string escaped by backslash escaping of JSON.
`str' specifies the string.
The return value is the unescaped string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call if when is no longer in use. */
char *tcjsonunescape(const char *str);
/*************************************************************************************************
* template serializer
*************************************************************************************************/
typedef struct { /* type of structure for a template */
TCLIST *elems; /* elements separated by the separators */
char *begsep; /* beginning separator */
char *endsep; /* ending separator */
TCMAP *conf; /* configuration variables */
} TCTMPL;
/* Create a template object.
The return value is the new template object. */
TCTMPL *tctmplnew(void);
/* Delete a template object.
`tmpl' specifies the template object. */
void tctmpldel(TCTMPL *tmpl);
/* Set the separator strings of a template object.
`tmpl' specifies the template object.
`begsep' specifies the beginning separator string. By default, it is "[%".
`endsep' specifies the ending separator string. By default, it is "%]". */
void tctmplsetsep(TCTMPL *tmpl, const char *begsep, const char *endsep);
/* Load a template string into a template object.
`tmpl' specifies the template object.
`str' specifies the template string. Directives between "[%" and "%]" can be included in the
template string. If the variable name is specified in the directive, it is expanded as the
value of the variable. "." is used in order to access a record of a hash variable. For
example, "[% foo.bar.baz %]" is expanded as the value of the record whose key is "baz" in the
hash variable of the record whose key is "bar" in the hash variable whose name is "foo".
Moreover, control flow directives are also supported. "[% IF ... %]", "[% ELSE %]", and
"[% END %]" are conditional directives. "[% FOREACH ... %]" and "[% END %]" are iterator
directives for a list object. "[% SET ... %]" is a session variable setting directive.
"[% CONF ... %]" is a configuration directive. If the ending separator of a directive is
leaded by "\", the next linefeed character is ignored. Variable expansion directive needs the
parameter for the variable name. The optional parameter "DEF" trailed by a string specifies
the default value. The optional parameter "ENC" trailed by a string specifies the encoding
format. "URL" for the URL escape encoding, "XML" for the XML escape encoding, "CSTR" for
C-string escape encoding, and "JSON" for JSON escape encoding are supported. The conditional
directive needs the parameter for the variable name. If the variable exists, the block to the
correspondent ending directive is evaluated, else, the block is ignored. The optional
parameter "EQ" trailed by a string specifies the string full matching test. The optional
parameter "INC" trailed by a string specifies the string including matching test. The
optional parameter "PRT" indicates the printable test. The optional parameter "RX" trailed by
a string specifies the regular expression matching test. The optional parameter "NOT" inverts
the logical determination. The iterator directive needs the parameter for the variable name
of a list object. The block to the correspondent ending directive is evaluated for each
element of the list. The optional parameter specifies the local variable name of each
element. The session variable setting directive needs the parameters for the variable name
and its value. The configuration directive needs the parameters for the variable name and
its value. */
void tctmplload(TCTMPL *tmpl, const char *str);
/* Load a template string from a file into a template object.
`tmpl' specifies the template object.
`path' specifies the input file.
If successful, the return value is true, else, it is false. */
bool tctmplload2(TCTMPL *tmpl, const char *path);
/* Serialize the template string of a template object.
`tmpl' specifies the template object.
`vars' specifies the variables to be applied into the template.
The return value is the dumped template string.
Because the region of the return value is allocated with the `malloc' call, it should be
released with the `free' call when it is no longer in use. */
char *tctmpldump(TCTMPL *tmpl, const TCMAP *vars);
/* Get the value of a configuration variable of a template object.
`tmpl' specifies the template object.
`name' specifies the name of the configuration variable.
The return value is the string value of the configuration variable or `NULL' if it is not
defined. */
const char *tctmplconf(TCTMPL *tmpl, const char *name);
/* Store a list object into a list object with the type information.
`list' specifies the container list object.
`obj' specifies the list object to be stored. */
void tclistpushlist(TCLIST *list, const TCLIST *obj);
/* Store a map object into a list object with the type information.
`list' specifies the container list object.
`obj' specifies the map object to be stored. */
void tclistpushmap(TCLIST *list, const TCMAP *obj);
/* Store a list object into a map object with the type information.
`map' specifies the container map object.
`kstr' specifies the string of the key.
`obj' specifies the list object to be stored. */
void tcmapputlist(TCMAP *map, const char *kstr, const TCLIST *obj);
/* Store a map object into a map object with the type information.
`map' specifies the container map object.
`kstr' specifies the string of the key.
`obj' specifies the map object to be stored. */
void tcmapputmap(TCMAP *map, const char *kstr, const TCMAP *obj);
/*************************************************************************************************
* pointer list
*************************************************************************************************/
typedef struct { /* type of structure for a pointer list */
void **array; /* array of pointers */
int anum; /* number of the elements of the array */
int start; /* start index of used elements */
int num; /* number of used elements */
} TCPTRLIST;
/* Create a pointer list object.
The return value is the new pointer list object. */
TCPTRLIST *tcptrlistnew(void);
/* Create a pointer list object with expecting the number of elements.
`anum' specifies the number of elements expected to be stored in the list.
The return value is the new pointer list object. */
TCPTRLIST *tcptrlistnew2(int anum);
/* Copy a pointer list object.
`ptrlist' specifies the pointer list object.
The return value is the new pointer list object equivalent to the specified object. */
TCPTRLIST *tcptrlistdup(const TCPTRLIST *ptrlist);
/* Delete a pointer list object.
`ptrlist' specifies the pointer list object.
Note that the deleted object and its derivatives can not be used anymore. */
void tcptrlistdel(TCPTRLIST *ptrlist);
/* Get the number of elements of a pointer list object.
`ptrlist' specifies the pointer list object.
The return value is the number of elements of the list. */
int tcptrlistnum(const TCPTRLIST *ptrlist);
/* Get the pointer to the region of an element of a pointer list object.
`ptrlist' specifies the pointer list object.
`index' specifies the index of the element.
The return value is the pointer to the region of the value.
If `index' is equal to or more than the number of elements, the return value is `NULL'. */
void *tcptrlistval(const TCPTRLIST *ptrlist, int index);
/* Add an element at the end of a pointer list object.
`ptrlist' specifies the pointer list object.
`ptr' specifies the pointer to the region of the new element. */
void tcptrlistpush(TCPTRLIST *ptrlist, void *ptr);
/* Remove an element of the end of a pointer list object.
`ptrlist' specifies the pointer list object.
The return value is the pointer to the region of the removed element.
If the list is empty, the return value is `NULL'. */
void *tcptrlistpop(TCPTRLIST *ptrlist);
/* Add an element at the top of a pointer list object.
`ptrlist' specifies the pointer list object.
`ptr' specifies the pointer to the region of the new element. */
void tcptrlistunshift(TCPTRLIST *ptrlist, void *ptr);
/* Remove an element of the top of a pointer list object.
`ptrlist' specifies the pointer list object.
The return value is the pointer to the region of the removed element.
If the list is empty, the return value is `NULL'. */
void *tcptrlistshift(TCPTRLIST *ptrlist);
/* Add an element at the specified location of a pointer list object.
`ptrlist' specifies the pointer list object.
`index' specifies the index of the new element.
`ptr' specifies the pointer to the region of the new element.
If `index' is equal to or more than the number of elements, this function has no effect. */
void tcptrlistinsert(TCPTRLIST *ptrlist, int index, void *ptr);
/* Remove an element at the specified location of a pointer list object.
`ptrlist' specifies the pointer list object.
`index' specifies the index of the element to be removed.
The return value is the pointer to the region of the removed element.
If `index' is equal to or more than the number of elements, no element is removed and the
return value is `NULL'. */
void *tcptrlistremove(TCPTRLIST *ptrlist, int index);
/* Overwrite an element at the specified location of a pointer list object.
`ptrlist' specifies the pointer list object.
`index' specifies the index of the element to be overwritten.
`ptr' specifies the pointer to the region of the new content.
If `index' is equal to or more than the number of elements, this function has no effect. */
void tcptrlistover(TCPTRLIST *ptrlist, int index, void *ptr);
/* Clear a pointer list object.
`ptrlist' specifies the pointer list object.
All elements are removed. */
void tcptrlistclear(TCPTRLIST *ptrlist);
/*************************************************************************************************
* bit operation utilities
*************************************************************************************************/
typedef struct { /* type of structure for a bit stream object */
uint8_t *sp; /* start pointer */
uint8_t *cp; /* current pointer */
int idx; /* bit index */
int size; /* size of used region */
} TCBITSTRM;
typedef unsigned char TCBITMAP; /* type of a bit map object */
/* Create a bitmap object. */
#define TCBITMAPNEW(TC_num) \
tccalloc(((TC_num) >> 3) + 1, 1);
/* Delete a bitmap object */
#define TCBITMAPDEL(TC_bitmap) \
do { \
tcfree((TC_bitmap)); \
} while(false);
/* Turn on a field of a bitmap object. */
#define TCBITMAPON(TC_bitmap, TC_idx) \
do { \
(TC_bitmap)[(TC_idx)>>3] |= 0x1 << ((TC_idx) & 0x7); \
} while(false);
/* Turn off a field of a bitmap object. */
#define TCBITMAPOFF(TC_bitmap, TC_idx) \
do { \
(TC_bitmap)[(TC_idx)>>3] &= ~(0x1 << ((TC_idx) & 0x7)); \
} while(false);
/* Check a field of a bitmap object. */
#define TCBITMAPCHECK(TC_bitmap, TC_idx) \
((TC_bitmap)[(TC_idx)>>3] & 0x1 << ((TC_idx) & 0x7))
/* Initialize a bit stream object as writer. */
#define TCBITSTRMINITW(TC_bitstrm, TC_ptr) \
do { \
(TC_bitstrm).sp = (uint8_t *)(TC_ptr); \
(TC_bitstrm).cp = (TC_bitstrm).sp; \
*(TC_bitstrm).cp = 0; \
(TC_bitstrm).idx = 3; \
(TC_bitstrm).size = 1; \
} while(false);
/* Concatenate a bit to a bit stream object. */
#define TCBITSTRMCAT(TC_bitstrm, sign) \
do { \
if((TC_bitstrm).idx >= 8){ \
*(++(TC_bitstrm).cp) = 0; \
(TC_bitstrm).idx = 0; \
(TC_bitstrm).size++; \
} \
*(TC_bitstrm).cp |= (sign << (TC_bitstrm).idx); \
(TC_bitstrm).idx++; \
} while(false);
/* Set the end mark to a bit stream object. */
#define TCBITSTRMSETEND(TC_bitstrm) \
do { \
if((TC_bitstrm).idx >= 8){ \
*(++(TC_bitstrm).cp) = 0; \
(TC_bitstrm).idx = 0; \
(TC_bitstrm).size++; \
} \
*(TC_bitstrm).sp |= (TC_bitstrm).idx & 7; \
} while(false);
/* Get the size of the used region of a bit stream object. */
#define TCBITSTRMSIZE(TC_bitstrm) \
((TC_bitstrm).size)
/* Initialize a bit stream object as reader. */
#define TCBITSTRMINITR(TC_bitstrm, TC_ptr, TC_size) \
do { \
(TC_bitstrm).sp = (uint8_t *)(TC_ptr); \
(TC_bitstrm).cp = (TC_bitstrm).sp; \
(TC_bitstrm).idx = 3; \
(TC_bitstrm).size = (TC_size); \
} while(false);
/* Read a bit from a bit stream object. */
#define TCBITSTRMREAD(TC_bitstrm, TC_sign) \
do { \
if((TC_bitstrm).idx >= 8){ \
(TC_bitstrm).cp++; \
(TC_bitstrm).idx = 0; \
} \
(TC_sign) = (*((TC_bitstrm).cp) & (1 << (TC_bitstrm).idx)) > 0; \
(TC_bitstrm).idx++; \
} while(false);
/* Get the number of bits of a bit stream object. */
#define TCBITSTRMNUM(TC_bitstrm) \
((((TC_bitstrm).size - 1) << 3) + (*(TC_bitstrm).sp & 7) - 3)
/*************************************************************************************************
* features for experts
*************************************************************************************************/
#include <stdio.h>
#define _TC_VERSION "1.4.48"
#define _TC_LIBVER 911
#define _TC_FORMATVER "1.0"
enum { /* enumeration for error codes */
TCESUCCESS, /* success */
TCETHREAD, /* threading error */
TCEINVALID, /* invalid operation */
TCENOFILE, /* file not found */
TCENOPERM, /* no permission */
TCEMETA, /* invalid meta data */
TCERHEAD, /* invalid record header */
TCEOPEN, /* open error */
TCECLOSE, /* close error */
TCETRUNC, /* trunc error */
TCESYNC, /* sync error */
TCESTAT, /* stat error */
TCESEEK, /* seek error */
TCEREAD, /* read error */
TCEWRITE, /* write error */
TCEMMAP, /* mmap error */
TCELOCK, /* lock error */
TCEUNLINK, /* unlink error */
TCERENAME, /* rename error */
TCEMKDIR, /* mkdir error */
TCERMDIR, /* rmdir error */
TCEKEEP, /* existing record */
TCENOREC, /* no record found */
TCEMISC = 9999 /* miscellaneous error */
};
enum { /* enumeration for database type */
TCDBTHASH, /* hash table */
TCDBTBTREE, /* B+ tree */
TCDBTFIXED, /* fixed-length */
TCDBTTABLE /* table */
};
/* Get the message string corresponding to an error code.
`ecode' specifies the error code.
The return value is the message string of the error code. */
const char *tcerrmsg(int ecode);
/* Show error message on the standard error output and exit.
`message' specifies an error message.
This function does not return. */
void *tcmyfatal(const char *message);
/* Allocate a large nullified region.
`size' specifies the size of the region.
The return value is the pointer to the allocated nullified region.
This function handles failure of memory allocation implicitly. The region of the return value
should be released with the function `tczerounmap' when it is no longer in use. */
void *tczeromap(uint64_t size);
/* Free a large nullfied region.
`ptr' specifies the pointer to the region. */
void tczerounmap(void *ptr);
/* Lock the global mutex object.
If successful, the return value is true, else, it is false. */
bool tcglobalmutexlock(void);
/* Lock the global mutex object by shared locking.
If successful, the return value is true, else, it is false. */
bool tcglobalmutexlockshared(void);
/* Unlock the global mutex object.
If successful, the return value is true, else, it is false. */
bool tcglobalmutexunlock(void);
/* Lock the absolute path of a file.
`path' specifies the path of the file.
If successful, the return value is true, else, it is false. */
bool tcpathlock(const char *path);
/* Unock the absolute path of a file.
`path' specifies the path of the file.
If successful, the return value is true, else, it is false. */
bool tcpathunlock(const char *path);
/* Convert an integer to the string as binary numbers.
`num' specifies the integer.
`buf' specifies the pointer to the region into which the result string is written. The size
of the buffer should be equal to or more than 65 bytes.
`col' specifies the number of columns. If it is not more than 0, it depends on the integer.
`fc' specifies the filling character.
The return value is the length of the result string. */
int tcnumtostrbin(uint64_t num, char *buf, int col, int fc);
/* Compare two keys by lexical order.
`aptr' specifies the pointer to the region of one key.
`asiz' specifies the size of the region of one key.
`bptr' specifies the pointer to the region of the other key.
`bsiz' specifies the size of the region of the other key.
`op' is ignored.
The return value is positive if the former is big, negative if the latter is big, 0 if both
are equivalent. */
int tccmplexical(const char *aptr, int asiz, const char *bptr, int bsiz, void *op);
/* Compare two keys as decimal strings of real numbers.
`aptr' specifies the pointer to the region of one key.
`asiz' specifies the size of the region of one key.
`bptr' specifies the pointer to the region of the other key.
`bsiz' specifies the size of the region of the other key.
`op' is ignored.
The return value is positive if the former is big, negative if the latter is big, 0 if both
are equivalent. */
int tccmpdecimal(const char *aptr, int asiz, const char *bptr, int bsiz, void *op);
/* Compare two keys as 32-bit integers in the native byte order.
`aptr' specifies the pointer to the region of one key.
`asiz' specifies the size of the region of one key.
`bptr' specifies the pointer to the region of the other key.
`bsiz' specifies the size of the region of the other key.
`op' is ignored.
The return value is positive if the former is big, negative if the latter is big, 0 if both
are equivalent. */
int tccmpint32(const char *aptr, int asiz, const char *bptr, int bsiz, void *op);
/* Compare two keys as 64-bit integers in the native byte order.
`aptr' specifies the pointer to the region of one key.
`asiz' specifies the size of the region of one key.
`bptr' specifies the pointer to the region of the other key.
`bsiz' specifies the size of the region of the other key.
`op' is ignored.
The return value is positive if the former is big, negative if the latter is big, 0 if both
are equivalent. */
int tccmpint64(const char *aptr, int asiz, const char *bptr, int bsiz, void *op);
/* Encode a serial object with BWT encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`idxp' specifies the pointer to the variable into which the index of the original string in
the rotation array is assigned.
The return value is the pointer to the result object.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when it
is no longer in use. */
char *tcbwtencode(const char *ptr, int size, int *idxp);
/* Decode a serial object encoded with BWT encoding.
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`idx' specifies the index of the original string in the rotation array is assigned.
The return value is the pointer to the result object.
Because an additional zero code is appended at the end of the region of the return value,
the return value can be treated as a character string. Because the region of the return
value is allocated with the `malloc' call, it should be released with the `free' call when it
is no longer in use. */
char *tcbwtdecode(const char *ptr, int size, int idx);
/* Get the binary logarithm of an integer.
`num' specifies an integer.
The return value is the binary logarithm. */
long tclog2l(long num);
/* Get the binary logarithm of a real number.
`num' specifies a real number.
The return value is the binary logarithm. */
double tclog2d(double num);
/* Get the aligned offset of a file offset.
`off' specifies the file offset.
The return value is the aligned offset. */
uint64_t tcpagealign(uint64_t off);
/* Print debug information with a formatted string as with `printf'. */
#if __STDC_VERSION__ >= 199901L
#define TCDPRINTF(...) \
do { \
fprintf(stderr, "%s:%d:%s: ", __FILE__, __LINE__, __func__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} while(false);
#else
#define TCDPRINTF(TC_str) \
do { \
fprintf(stderr, "%s:%d:%s: %s\n", __FILE__, __LINE__, __func__, TC_str); \
} while(false);
#endif
/* Print hexadecimal pattern of a binary region. */
#define TCPRINTHEX(TC_ptr, TC_size) \
do { \
for(int TC_i = 0; TC_i < (TC_size); TC_i++){ \
if(TC_i > 0) putchar(' '); \
printf("%02X", ((unsigned char *)(TC_ptr))[TC_i]); \
} \
putchar('\n'); \
} while(false);
/* Print an extensible string object. */
#define TCPRINTXSTR(TC_xstr) \
do { \
fwrite(tcxstrptr((TC_xstr)), tcxstrsize((TC_xstr)), 1, stdout); \
putchar('\n'); \
} while(false);
/* Print all elements of a list object. */
#define TCPRINTLIST(TC_list) \
do { \
for(int TC_i = 0; TC_i < tclistnum((TC_list)); TC_i++){ \
int TC_size; \
const char *TC_ptr = tclistval((TC_list), TC_i, &TC_size); \
printf("%p\t", (void *)(TC_list)); \
fwrite(TC_ptr, TC_size, 1, stdout); \
putchar('\n'); \
} \
putchar('\n'); \
} while(false);
/* Print all records of a list object. */
#define TCPRINTMAP(TC_map) \
do { \
TCLIST *TC_keys = tcmapkeys((TC_map)); \
for(int TC_i = 0; TC_i < tclistnum(TC_keys); TC_i++){ \
int TC_ksiz; \
const char *TC_kbuf = tclistval(TC_keys, TC_i, &TC_ksiz); \
int TC_vsiz; \
const char *TC_vbuf = tcmapget((TC_map), TC_kbuf, TC_ksiz, &TC_vsiz); \
printf("%p\t", (void *)(TC_map)); \
fwrite(TC_kbuf, TC_ksiz, 1, stdout); \
putchar('\t'); \
fwrite(TC_vbuf, TC_vsiz, 1, stdout); \
putchar('\n'); \
} \
putchar('\n'); \
tclistdel(TC_keys); \
} while(false);
/* Alias of `tcmalloc'. */
#if defined(_MYFASTEST)
#define TCMALLOC(TC_res, TC_size) \
do { \
(TC_res) = MYMALLOC(TC_size); \
} while(false)
#else
#define TCMALLOC(TC_res, TC_size) \
do { \
if(!((TC_res) = MYMALLOC(TC_size))) tcmyfatal("out of memory"); \
} while(false)
#endif
/* Alias of `tccalloc'. */
#if defined(_MYFASTEST)
#define TCCALLOC(TC_res, TC_nmemb, TC_size) \
do { \
(TC_res) = MYCALLOC((TC_nmemb), (TC_size)); \
} while(false)
#else
#define TCCALLOC(TC_res, TC_nmemb, TC_size) \
do { \
if(!((TC_res) = MYCALLOC((TC_nmemb), (TC_size)))) tcmyfatal("out of memory"); \
} while(false)
#endif
/* Alias of `tcrealloc'. */
#if defined(_MYFASTEST)
#define TCREALLOC(TC_res, TC_ptr, TC_size) \
do { \
(TC_res) = MYREALLOC((TC_ptr), (TC_size)); \
} while(false)
#else
#define TCREALLOC(TC_res, TC_ptr, TC_size) \
do { \
if(!((TC_res) = MYREALLOC((TC_ptr), (TC_size)))) tcmyfatal("out of memory"); \
} while(false)
#endif
/* Alias of `tcmemdup'. */
#define TCMEMDUP(TC_res, TC_ptr, TC_size) \
do { \
TCMALLOC((TC_res), (TC_size) + 1); \
memcpy((TC_res), (TC_ptr), (TC_size)); \
(TC_res)[TC_size] = '\0'; \
} while(false)
/* Alias of `tcfree'. */
#define TCFREE(TC_ptr) \
do { \
MYFREE(TC_ptr); \
} while(false)
/* Get the alignment of a variable type. */
#define TCALIGNOF(TC_a) \
((int)offsetof(struct { int8_t TC_top; TC_a TC_bot; }, TC_bot))
/* Get the size of padding bytes for pointer alignment. */
typedef union { int32_t i; int64_t l; double d; void *p; TCCMP f; } tcgeneric_t;
#define TCALIGNPAD(TC_hsiz) \
(((TC_hsiz | ~-TCALIGNOF(tcgeneric_t)) + 1) - TC_hsiz)
/* Alias of `tcxstrcat'. */
#define TCXSTRCAT(TC_xstr, TC_ptr, TC_size) \
do { \
int TC_mysize = (TC_size); \
int TC_nsize = (TC_xstr)->size + TC_mysize + 1; \
if((TC_xstr)->asize < TC_nsize){ \
while((TC_xstr)->asize < TC_nsize){ \
(TC_xstr)->asize *= 2; \
if((TC_xstr)->asize < TC_nsize) (TC_xstr)->asize = TC_nsize; \
} \
TCREALLOC((TC_xstr)->ptr, (TC_xstr)->ptr, (TC_xstr)->asize); \
} \
memcpy((TC_xstr)->ptr + (TC_xstr)->size, (TC_ptr), TC_mysize); \
(TC_xstr)->size += TC_mysize; \
(TC_xstr)->ptr[(TC_xstr)->size] = '\0'; \
} while(false)
/* Alias of `tcxstrptr'. */
#define TCXSTRPTR(TC_xstr) \
((TC_xstr)->ptr)
/* Alias of `tcxstrsize'. */
#define TCXSTRSIZE(TC_xstr) \
((TC_xstr)->size)
/* Alias of `tclistnum'. */
#define TCLISTNUM(TC_list) \
((TC_list)->num)
/* Alias of `tclistval' but not checking size. */
#define TCLISTVAL(TC_ptr, TC_list, TC_index, TC_size) \
do { \
(TC_ptr) = (TC_list)->array[(TC_index)+(TC_list)->start].ptr; \
(TC_size) = (TC_list)->array[(TC_index)+(TC_list)->start].size; \
} while(false)
/* Alias of `tclistval' but not checking size and not using the third parameter. */
#define TCLISTVALPTR(TC_list, TC_index) \
((void *)((TC_list)->array[(TC_index)+(TC_list)->start].ptr))
/* Alias of `tclistval' but not checking size and returning the size of the value. */
#define TCLISTVALSIZ(TC_list, TC_index) \
((TC_list)->array[(TC_index)+(TC_list)->start].size)
/* Alias of `tclistpush'. */
#define TCLISTPUSH(TC_list, TC_ptr, TC_size) \
do { \
int TC_mysize = (TC_size); \
int TC_index = (TC_list)->start + (TC_list)->num; \
if(TC_index >= (TC_list)->anum){ \
(TC_list)->anum += (TC_list)->num + 1; \
TCREALLOC((TC_list)->array, (TC_list)->array, \
(TC_list)->anum * sizeof((TC_list)->array[0])); \
} \
TCLISTDATUM *array = (TC_list)->array; \
TCMALLOC(array[TC_index].ptr, TC_mysize + 1); \
memcpy(array[TC_index].ptr, (TC_ptr), TC_mysize); \
array[TC_index].ptr[TC_mysize] = '\0'; \
array[TC_index].size = TC_mysize; \
(TC_list)->num++; \
} while(false)
/* Alias of `tclistinsert'. */
#define TCLISTINSERT(TC_list, TC_index, TC_ptr, TC_size) \
do { \
int TC_myindex = (TC_index); \
TC_myindex += (TC_list)->start; \
if((TC_list)->start + (TC_list)->num >= (TC_list)->anum){ \
(TC_list)->anum += (TC_list)->num + 1; \
TCREALLOC((TC_list)->array, (TC_list)->array, \
(TC_list)->anum * sizeof((TC_list)->array[0])); \
} \
memmove((TC_list)->array + TC_myindex + 1, (TC_list)->array + TC_myindex, \
sizeof((TC_list)->array[0]) * ((TC_list)->start + (TC_list)->num - TC_myindex)); \
TCMALLOC((TC_list)->array[TC_myindex].ptr, (TC_size) + 1); \
memcpy((TC_list)->array[TC_myindex].ptr, (TC_ptr), (TC_size)); \
(TC_list)->array[TC_myindex].ptr[(TC_size)] = '\0'; \
(TC_list)->array[TC_myindex].size = (TC_size); \
(TC_list)->num++; \
} while(false)
/* Truncate a list object. */
#define TCLISTTRUNC(TC_list, TC_num) \
do { \
while((TC_list)->num > (TC_num)){ \
TCFREE((TC_list)->array[--(TC_list)->num].ptr); \
} \
} while(false)
/* Alias of `tcmaprnum'. */
#define TCMAPRNUM(TC_map) \
((TC_map)->rnum)
/* Alias of `tcptrlistnum'. */
#define TCPTRLISTNUM(TC_ptrlist) \
((TC_ptrlist)->num)
/* Alias of `tcptrlistval'. */
#define TCPTRLISTVAL(TC_ptrlist, TC_index) \
((void *)((TC_ptrlist)->array[(TC_index)+(TC_ptrlist)->start]))
/* Alias of `tcptrlistpush'. */
#define TCPTRLISTPUSH(TC_ptrlist, TC_ptr) \
do { \
int TC_index = (TC_ptrlist)->start + (TC_ptrlist)->num; \
if(TC_index >= (TC_ptrlist)->anum){ \
(TC_ptrlist)->anum += (TC_ptrlist)->num + 1; \
TCREALLOC((TC_ptrlist)->array, (TC_ptrlist)->array, \
(TC_ptrlist)->anum * sizeof((TC_ptrlist)->array[0])); \
} \
(TC_ptrlist)->array[TC_index] = (TC_ptr); \
(TC_ptrlist)->num++; \
} while(false)
/* Alias of `tcptrlistinsert'. */
#define TCPTRLISTINSERT(TC_ptrlist, TC_index, TC_ptr) \
do { \
int TC_myindex = (TC_index); \
TC_myindex += (TC_ptrlist)->start; \
if((TC_ptrlist)->start + (TC_ptrlist)->num >= (TC_ptrlist)->anum){ \
(TC_ptrlist)->anum += (TC_ptrlist)->num + 1; \
TCREALLOC((TC_ptrlist)->array, (TC_ptrlist)->array, \
(TC_ptrlist)->anum * sizeof((TC_ptrlist)->array[0])); \
} \
memmove((TC_ptrlist)->array + TC_myindex + 1, (TC_ptrlist)->array + TC_myindex, \
sizeof((TC_ptrlist)->array[0]) * ((TC_ptrlist)->start + \
(TC_ptrlist)->num - TC_myindex)); \
(TC_ptrlist)->array[TC_myindex] = (TC_ptr); \
(TC_ptrlist)->num++; \
} while(false)
/* Truncate a pointer list object. */
#define TCPTRLISTTRUNC(TC_ptrlist, TC_num) \
do { \
(TC_ptrlist)->num = (TC_num); \
} while(false)
/* tricks for backward compatibility */
#define BDBCMP TCCMP
#define tcbdbrange3 tcbdbfwmkeys2
#define tcbdbcmplexical tccmplexical
#define tcbdbcmpdecimal tccmpdecimal
#define tcbdbcmpint32 tccmpint32
#define tcbdbcmpint64 tccmpint64
#define tctdbqryprocout tctdbqrysearchout
#define tctdbqrysetmax(TC_tdb, TC_max) \
tctdbqrysetlimit((TC_tdb), (TC_max), 0)
__TCUTIL_CLINKAGEEND
#endif /* duplication check */
/* END OF FILE */
|