/usr/lib/perl5/TokyoCabinet.pod is in libtokyocabinet-perl 1.34-2.
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 | #-------------------------------------------------------------------------------------------------
# Perl binding of Tokyo Cabinet
# Copyright (C) 2006-2010 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.
#-------------------------------------------------------------------------------------------------
=head1 NAME
TokyoCabinet - Perl Binding of Tokyo Cabinet
=head1 SYNOPSYS
use TokyoCabinet;
=head1 INTRODUCTION
Tokyo Cabinet is a library of routines for managing a database. The database is a simple data file containing records, each is a pair of a key and a value. Every key and value is serial bytes with variable length. Both binary data and character string can be used as a key and a value. There is neither concept of data tables nor data types. Records are organized in hash table, B+ tree, or fixed-length array.
As for database of hash table, each key must be unique within a database, so it is impossible to store two or more records with a key overlaps. The following access methods are provided to the database: storing a record with a key and a value, deleting a record by a key, retrieving a record by a key. Moreover, traversal access to every key are provided, although the order is arbitrary. These access methods are similar to ones of DBM (or its followers: NDBM and GDBM) library defined in the UNIX standard. Tokyo Cabinet is an alternative for DBM because of its higher performance.
As for database of B+ tree, records whose keys are duplicated can be stored. Access methods of storing, deleting, and retrieving are provided as with the database of hash table. Records are stored in order by a comparison function assigned by a user. It is possible to access each record with the cursor in ascending or descending order. According to this mechanism, forward matching search for strings and range search for integers are realized.
As for database of fixed-length array, records are stored with unique natural numbers. It is impossible to store two or more records with a key overlaps. Moreover, the length of each record is limited by the specified length. Provided operations are the same as ones of hash database.
Table database is also provided as a variant of hash database. Each record is identified by the primary key and has a set of named columns. Although there is no concept of data schema, it is possible to search for records with complex conditions efficiently by using indices of arbitrary columns.
=head2 Setting
Install the latest version of Tokyo Cabinet beforehand and get the package of the Perl binding of Tokyo Cabinet.
Enter the directory of the extracted package then perform installation.
perl Makefile.PL
make
make test
su
make install
The package `TokyoCabinet' should be loaded in each source file of application programs.
use TokyoCabinet;
If you want to enable runtime assertion, set the variable `$TokyoCabinet::DEBUG' to be true.
$TokyoCabinet::DEBUG = 1;
=head1 EXAMPLE
The following code is an example to use a hash database.
use TokyoCabinet;
use strict;
use warnings;
# create the object
my $hdb = TokyoCabinet::HDB->new();
# open the database
if(!$hdb->open("casket.tch", $hdb->OWRITER | $hdb->OCREAT)){
my $ecode = $hdb->ecode();
printf STDERR ("open error: %s\n", $hdb->errmsg($ecode));
}
# store records
if(!$hdb->put("foo", "hop") ||
!$hdb->put("bar", "step") ||
!$hdb->put("baz", "jump")){
my $ecode = $hdb->ecode();
printf STDERR ("put error: %s\n", $hdb->errmsg($ecode));
}
# retrieve records
my $value = $hdb->get("foo");
if(defined($value)){
printf("%s\n", $value);
} else {
my $ecode = $hdb->ecode();
printf STDERR ("get error: %s\n", $hdb->errmsg($ecode));
}
# traverse records
$hdb->iterinit();
while(defined(my $key = $hdb->iternext())){
my $value = $hdb->get($key);
if(defined($value)){
printf("%s:%s\n", $key, $value);
}
}
# close the database
if(!$hdb->close()){
my $ecode = $hdb->ecode();
printf STDERR ("close error: %s\n", $hdb->errmsg($ecode));
}
# tying usage
my %hash;
if(!tie(%hash, "TokyoCabinet::HDB", "casket.tch", TokyoCabinet::HDB::OWRITER)){
printf STDERR ("tie error\n");
}
$hash{"quux"} = "touchdown";
printf("%s\n", $hash{"quux"});
while(my ($key, $value) = each(%hash)){
printf("%s:%s\n", $key, $value);
}
untie(%hash);
The following code is an example to use a B+ tree database.
use TokyoCabinet;
use strict;
use warnings;
# create the object
my $bdb = TokyoCabinet::BDB->new();
# open the database
if(!$bdb->open("casket.tcb", $bdb->OWRITER | $bdb->OCREAT)){
my $ecode = $bdb->ecode();
printf STDERR ("open error: %s\n", $bdb->errmsg($ecode));
}
# store records
if(!$bdb->put("foo", "hop") ||
!$bdb->put("bar", "step") ||
!$bdb->put("baz", "jump")){
my $ecode = $bdb->ecode();
printf STDERR ("put error: %s\n", $bdb->errmsg($ecode));
}
# retrieve records
my $value = $bdb->get("foo");
if(defined($value)){
printf("%s\n", $value);
} else {
my $ecode = $bdb->ecode();
printf STDERR ("get error: %s\n", $bdb->errmsg($ecode));
}
# traverse records
my $cur = TokyoCabinet::BDBCUR->new($bdb);
$cur->first();
while(defined(my $key = $cur->key())){
my $value = $cur->val();
if(defined($value)){
printf("%s:%s\n", $key, $value);
}
$cur->next();
}
# close the database
if(!$bdb->close()){
my $ecode = $bdb->ecode();
printf STDERR ("close error: %s\n", $bdb->errmsg($ecode));
}
# tying usage
my %hash;
if(!tie(%hash, "TokyoCabinet::BDB", "casket.tcb", TokyoCabinet::BDB::OWRITER)){
printf STDERR ("tie error\n");
}
$hash{"quux"} = "touchdown";
printf("%s\n", $hash{"quux"});
while(my ($key, $value) = each(%hash)){
printf("%s:%s\n", $key, $value);
}
untie(%hash);
The following code is an example to use a fixed-length database.
use TokyoCabinet;
use strict;
use warnings;
# create the object
my $fdb = TokyoCabinet::FDB->new();
# open the database
if(!$fdb->open("casket.tcf", $fdb->OWRITER | $fdb->OCREAT)){
my $ecode = $fdb->ecode();
printf STDERR ("open error: %s\n", $fdb->errmsg($ecode));
}
# store records
if(!$fdb->put(1, "one") ||
!$fdb->put(12, "twelve") ||
!$fdb->put(144, "one forty four")){
my $ecode = $fdb->ecode();
printf STDERR ("put error: %s\n", $fdb->errmsg($ecode));
}
# retrieve records
my $value = $fdb->get(1);
if(defined($value)){
printf("%s\n", $value);
} else {
my $ecode = $fdb->ecode();
printf STDERR ("get error: %s\n", $fdb->errmsg($ecode));
}
# traverse records
$fdb->iterinit();
while(defined(my $key = $fdb->iternext())){
my $value = $fdb->get($key);
if(defined($value)){
printf("%s:%s\n", $key, $value);
}
}
# close the database
if(!$fdb->close()){
my $ecode = $fdb->ecode();
printf STDERR ("close error: %s\n", $fdb->errmsg($ecode));
}
# tying usage
my %hash;
if(!tie(%hash, "TokyoCabinet::FDB", "casket.tcf", TokyoCabinet::FDB::OWRITER)){
printf STDERR ("tie error\n");
}
$hash{1728} = "seventeen twenty eight";
printf("%s\n", $hash{1728});
while(my ($key, $value) = each(%hash)){
printf("%s:%s\n", $key, $value);
}
untie(%hash);
The following code is an example to use a table database.
use TokyoCabinet;
use strict;
use warnings;
# create the object
my $tdb = TokyoCabinet::TDB->new();
# open the database
if(!$tdb->open("casket.tct", $tdb->OWRITER | $tdb->OCREAT)){
my $ecode = $tdb->ecode();
printf STDERR ("open error: %s\n", $tdb->errmsg($ecode));
}
# store a record
my $pkey = $tdb->genuid();
my $cols = { "name" => "mikio", "age" => "30", "lang" => "ja,en,c" };
if(!$tdb->put($pkey, $cols)){
my $ecode = $tdb->ecode();
printf STDERR ("put error: %s\n", $tdb->errmsg($ecode));
}
# store another record
$cols = { "name" => "falcon", "age" => "31", "lang" => "ja", "skill" => "cook,blog" };
if(!$tdb->put("x12345", $cols)){
my $ecode = $tdb->ecode();
printf STDERR ("put error: %s\n", $tdb->errmsg($ecode));
}
# search for records
my $qry = TokyoCabinet::TDBQRY->new($tdb);
$qry->addcond("age", $qry->QCNUMGE, "20");
$qry->addcond("lang", $qry->QCSTROR, "ja,en");
$qry->setorder("name", $qry->QOSTRASC);
$qry->setlimit(10);
my $res = $qry->search();
foreach my $rkey (@$res){
my $rcols = $tdb->get($rkey);
printf("name:%s\n", $rcols->{name});
}
# close the database
if(!$tdb->close()){
my $ecode = $tdb->ecode();
printf STDERR ("close error: %s\n", $tdb->errmsg($ecode));
}
# tying usage
my %hash;
if(!tie(%hash, "TokyoCabinet::TDB", "casket.tct", TokyoCabinet::TDB::OWRITER)){
printf STDERR ("tie error\n");
}
$hash{"joker"} = { "name" => "ozma", "lang" => "en", "skill" => "song,dance" };
printf("%s\n", $hash{joker}->{name});
while(my ($key, $value) = each(%hash)){
printf("%s:%s\n", $key, $value->{name});
}
untie(%hash);
The following code is an example to use an abstract database.
use TokyoCabinet;
use strict;
use warnings;
# create the object
my $adb = TokyoCabinet::ADB->new();
# open the database
if(!$adb->open("casket.tch")){
printf STDERR ("open error\n");
}
# store records
if(!$adb->put("foo", "hop") ||
!$adb->put("bar", "step") ||
!$adb->put("baz", "jump")){
printf STDERR ("put error\n");
}
# retrieve records
my $value = $adb->get("foo");
if(defined($value)){
printf("%s\n", $value);
} else {
printf STDERR ("get error\n");
}
# traverse records
$adb->iterinit();
while(defined(my $key = $adb->iternext())){
my $value = $adb->get($key);
if(defined($value)){
printf("%s:%s\n", $key, $value);
}
}
# close the database
if(!$adb->close()){
printf STDERR ("close error\n");
}
# tying usage
my %hash;
if(!tie(%hash, "TokyoCabinet::ADB", "casket.tch")){
printf STDERR ("tie error\n");
}
$hash{"quux"} = "touchdown";
printf("%s\n", $hash{"quux"});
while(my ($key, $value) = each(%hash)){
printf("%s:%s\n", $key, $value);
}
untie(%hash);
=head1 DESCRIPTION
=head2 Class TokyoCabinet
The following functions are utilities to handle records by applications.
=over
=item TokyoCabinet::VERSIONZ<>()
E<10>Get the version information of Tokyo Cabinet.
E<10>The return value is the version information.
=item TokyoCabinet::atoiZ<>(I<str>)
E<10>Convert a string to an integer.
E<10>The return value is the integer value.
=item TokyoCabinet::atofZ<>(I<str>)
E<10>Convert a string to a real number.
E<10>The return value is the real number value.
=item TokyoCabinet::bercompressZ<>(I<aryref>)
E<10>Serialize an array of nonnegative integers with BER encoding.
E<10>`I<aryref>' specifies the reference to an array of nonnegative integers.
E<10>The return value is the reference to the serialized scalar.
=item TokyoCabinet::beruncompressZ<>(I<selref>)
E<10>Deserialize a BER encoded scalar to an array.
E<10>`I<selref>' specifies the reference to the BER encoded scalar.
E<10>The return value is the reference to the array of nonnegative integers.
=item TokyoCabinet::diffcompressZ<>(I<aryref>)
E<10>Serialize an array of sorted nonnegative integers with difference BER encoding.
E<10>`I<aryref>' specifies the reference to an array of sorted nonnegative integers.
E<10>The return value is the reference to the serialized scalar.
=item TokyoCabinet::diffuncompressZ<>(I<selref>)
E<10>Deserialize a difference BER encoded scalar to an array.
E<10>`I<selref>' specifies the reference to the BER encoded scalar.
E<10>The return value is the reference to the array of sorted nonnegative integers.
=item TokyoCabinet::strdistanceZ<>(I<aref>, I<bref>, I<isutf>)
E<10>Calculate the edit distance of two strings.
E<10>`I<aref>' specifies the reference to a string.
E<10>`I<bref>' specifies the reference to the other string.
E<10>`I<isutf>' specifies whether the cost is calculated by Unicode character of UTF-8 strings.
E<10>The return value is the edit distance which is known as the Levenshtein distance.
=back
=head2 Class TokyoCabinet::HDB
Hash database is a file containing a hash table and is handled with the hash database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the hash database object to it. The method `open' is used to open a database file and the method `close' is used to close the database file. To avoid data missing or corruption, it is important to close every database file when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.
=over
=item $hdb = TokyoCabinet::HDB-E<gt>newZ<>()
E<10>Create a hash database object.
E<10>The return value is the new hash database object.
=item $hdb-E<gt>errmsgZ<>(I<ecode>)
E<10>Get the message string corresponding to an error code.
E<10>`I<ecode>' specifies the error code. If it is not defined or negative, the last happened error code is specified.
E<10>The return value is the message string of the error code.
=item $hdb-E<gt>ecodeZ<>()
E<10>Get the last happened error code.
E<10>The return value is the last happened error code.
E<10>The following error codes are defined: `$hdb-E<gt>ESUCCESS' for success, `$hdb-E<gt>ETHREAD' for threading error, `$hdb-E<gt>EINVALID' for invalid operation, `$hdb-E<gt>ENOFILE' for file not found, `$hdb-E<gt>ENOPERM' for no permission, `$hdb-E<gt>EMETA' for invalid meta data, `$hdb-E<gt>ERHEAD' for invalid record header, `$hdb-E<gt>EOPEN' for open error, `$hdb-E<gt>ECLOSE' for close error, `$hdb-E<gt>ETRUNC' for trunc error, `$hdb-E<gt>ESYNC' for sync error, `$hdb-E<gt>ESTAT' for stat error, `$hdb-E<gt>ESEEK' for seek error, `$hdb-E<gt>EREAD' for read error, `$hdb-E<gt>EWRITE' for write error, `$hdb-E<gt>EMMAP' for mmap error, `$hdb-E<gt>ELOCK' for lock error, `$hdb-E<gt>EUNLINK' for unlink error, `$hdb-E<gt>ERENAME' for rename error, `$hdb-E<gt>EMKDIR' for mkdir error, `$hdb-E<gt>ERMDIR' for rmdir error, `$hdb-E<gt>EKEEP' for existing record, `$hdb-E<gt>ENOREC' for no record found, and `$hdb-E<gt>EMISC' for miscellaneous error.
=item $hdb-E<gt>tuneZ<>(I<bnum>, I<apow>, I<fpow>, I<opts>)
E<10>Set the tuning parameters.
E<10>`I<bnum>' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 131071. Suggested size of the bucket array is about from 0.5 to 4 times of the number of all records to be stored.
E<10>`I<apow>' specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^4=16.
E<10>`I<fpow>' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.
E<10>`I<opts>' specifies options by bitwise-or: `$hdb-E<gt>TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `$hdb-E<gt>TDEFLATE' specifies that each record is compressed with Deflate encoding, `$hdb-E<gt>TBZIP' specifies that each record is compressed with BZIP2 encoding, `$hdb-E<gt>TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.
E<10>If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.
=item $hdb-E<gt>setcacheZ<>(I<rcnum>)
E<10>Set the caching parameters.
E<10>`I<rcnum>' specifies the maximum number of records to be cached. If it is not defined or not more than 0, the record cache is disabled. It is disabled by default.
E<10>If successful, the return value is true, else, it is false.
E<10>Note that the caching parameters of the database should be set before the database is opened.
=item $hdb-E<gt>setxmsizZ<>(I<xmsiz>)
E<10>Set the size of the extra mapped memory.
E<10>`I<xmsiz>' specifies the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. The default size is 67108864.
E<10>If successful, the return value is true, else, it is false.
E<10>Note that the mapping parameters should be set before the database is opened.
=item $hdb-E<gt>setdfunitZ<>(I<dfunit>)
E<10>Set the unit step number of auto defragmentation.
E<10>`I<dfunit>' specifie the unit step number. If it is not more than 0, the auto defragmentation is disabled. It is disabled by default.
E<10>If successful, the return value is true, else, it is false.
E<10>Note that the defragmentation parameters should be set before the database is opened.
=item $hdb-E<gt>openZ<>(I<path>, I<omode>)
E<10>Open a database file.
E<10>`I<path>' specifies the path of the database file.
E<10>`I<omode>' specifies the connection mode: `$hdb-E<gt>OWRITER' as a writer, `$hdb-E<gt>OREADER' as a reader. If the mode is `$hdb-E<gt>OWRITER', the following may be added by bitwise-or: `$hdb-E<gt>OCREAT', which means it creates a new database if not exist, `$hdb-E<gt>OTRUNC', which means it creates a new database regardless if one exists, `$hdb-E<gt>OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `$hdb-E<gt>OREADER' and `$hdb-E<gt>OWRITER' can be added to by bitwise-or: `$hdb-E<gt>ONOLCK', which means it opens the database file without file locking, or `$hdb-E<gt>OLCKNB', which means locking is performed without blocking. If it is not defined, `$hdb-E<gt>OREADER' is specified.
E<10>If successful, the return value is true, else, it is false.
=item $hdb-E<gt>closeZ<>()
E<10>Close the database file.
E<10>If successful, the return value is true, else, it is false.
E<10>Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.
=item $hdb-E<gt>putZ<>(I<key>, I<value>)
E<10>Store a record.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, it is overwritten.
=item $hdb-E<gt>putkeepZ<>(I<key>, I<value>)
E<10>Store a new record.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, this method has no effect.
=item $hdb-E<gt>putcatZ<>(I<key>, I<value>)
E<10>Concatenate a value at the end of the existing record.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If there is no corresponding record, a new record is created.
=item $hdb-E<gt>putasyncZ<>(I<key>, I<value>)
E<10>Store a record in asynchronous fashion.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, it is overwritten. Records passed to this method are accumulated into the inner buffer and wrote into the file at a blast.
=item $hdb-E<gt>outZ<>(I<key>)
E<10>Remove a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is true, else, it is false.
=item $hdb-E<gt>getZ<>(I<key>)
E<10>Retrieve a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is the value of the corresponding record. `undef' is returned if no record corresponds.
=item $hdb-E<gt>vsizZ<>(I<key>)
E<10>Get the size of the value of a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is the size of the value of the corresponding record, else, it is -1.
=item $hdb-E<gt>iterinitZ<>()
E<10>Initialize the iterator.
E<10>If successful, the return value is true, else, it is false.
E<10>The iterator is used in order to access the key of every record stored in a database.
=item $hdb-E<gt>iternextZ<>()
E<10>Get the next key of the iterator.
E<10>If successful, the return value is the next key, else, it is `undef'. `undef' is returned when no record is to be get out of the iterator.
E<10>It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.
=item $hdb-E<gt>fwmkeysZ<>(I<prefix>, I<max>)
E<10>Get forward matching keys.
E<10>`I<prefix>' specifies the prefix of the corresponding keys.
E<10>`I<max>' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
E<10>The return value is the reference to an array of the keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.
E<10>Note that this method may be very slow because every key in the database is scanned.
=item $hdb-E<gt>addintZ<>(I<key>, I<num>)
E<10>Add an integer to a record.
E<10>`I<key>' specifies the key.
E<10>`I<num>' specifies the additional value.
E<10>If successful, the return value is the summation value, else, it is `undef'.
E<10>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. Because records are stored in binary format, they should be processed with the `unpack' function with the `i' operator after retrieval.
=item $hdb-E<gt>adddoubleZ<>(I<key>, I<num>)
E<10>Add a real number to a record.
E<10>`I<key>' specifies the key.
E<10>`I<num>' specifies the additional value.
E<10>If successful, the return value is the summation value, else, it is `undef'.
E<10>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. Because records are stored in binary format, they should be processed with the `unpack' function with the `d' operator after retrieval.
=item $hdb-E<gt>syncZ<>()
E<10>Synchronize updated contents with the file and the device.
E<10>If successful, the return value is true, else, it is false.
E<10>This method is useful when another process connects the same database file.
=item $hdb-E<gt>optimizeZ<>(I<bnum>, I<apow>, I<fpow>, I<opts>)
E<10>Optimize the database file.
E<10>`I<bnum>' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of records.
E<10>`I<apow>' specifies the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.
E<10>`I<fpow>' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.
E<10>`I<opts>' specifies options by bitwise-or: `$hdb-E<gt>TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `$hdb-E<gt>TDEFLATE' specifies that each record is compressed with Deflate encoding, `$hdb-E<gt>TBZIP' specifies that each record is compressed with BZIP2 encoding, `$hdb-E<gt>TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.
E<10>If successful, the return value is true, else, it is false.
E<10>This method is useful to reduce the size of the database file with data fragmentation by successive updating.
=item $hdb-E<gt>vanishZ<>()
E<10>Remove all records.
E<10>If successful, the return value is true, else, it is false.
=item $hdb-E<gt>copyZ<>(I<path>)
E<10>Copy the database file.
E<10>`I<path>' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.
E<10>If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.
E<10>The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.
=item $hdb-E<gt>tranbeginZ<>()
E<10>Begin the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.
=item $hdb-E<gt>trancommitZ<>()
E<10>Commit the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>Update in the transaction is fixed when it is committed successfully.
=item $hdb-E<gt>tranabortZ<>()
E<10>Abort the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.
=item $hdb-E<gt>pathZ<>()
E<10>Get the path of the database file.
E<10>The return value is the path of the database file or `undef' if the object does not connect to any database file.
=item $hdb-E<gt>rnumZ<>()
E<10>Get the number of records.
E<10>The return value is the number of records or 0 if the object does not connect to any database file.
=item $hdb-E<gt>fsizZ<>()
E<10>Get the size of the database file.
E<10>The return value is the size of the database file or 0 if the object does not connect to any database file.
=back
=head2 Tying functions of TokyoCabinet::HDB
=over
=item tieZ<>(%hash, E<quot>TokyoCabinet::HDBE<quot>, I<path>, I<omode>, I<bnum>, I<apow>, I<fpow>, I<opts>, I<rcnum>)
E<10>Tie a hash variable to a hash database file.
E<10>`I<path>' specifies the path of the database file.
E<10>`I<omode>' specifies the connection mode: `TokyoCabinet::HDB::OWRITER' as a writer, `TokyoCabinet::HDB::OREADER' as a reader. If the mode is `TokyoCabinet::HDB::OWRITER', the following may be added by bitwise-or: `TokyoCabinet::HDB::OCREAT', which means it creates a new database if not exist, `TokyoCabinet::HDB::OTRUNC', which means it creates a new database regardless if one exists, `TokyoCabinet::HDB::OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `TokyoCabinet::HDB::OREADER' and `TokyoCabinet::HDB::OWRITER' can be added to by bitwise-or: `TokyoCabinet::HDB::ONOLCK', which means it opens the database file without file locking, or `TokyoCabinet::HDB::OLCKNB', which means locking is performed without blocking. If it is not defined, `TokyoCabinet::HDB::OREADER' is specified.
E<10>`I<bnum>' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 131071. Suggested size of the bucket array is about from 0.5 to 4 times of the number of all records to be stored.
E<10>`I<apow>' specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^4=16.
E<10>`I<fpow>' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.
E<10>`I<opts>' specifies options by bitwise-or: `TokyoCabinet::HDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::HDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::HDB::TBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::HDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.
E<10>`I<rcnum>' specifies the maximum number of records to be cached. If it is not defined or not more than 0, the record cache is disabled. It is disabled by default.
E<10>If successful, the return value is true, else, it is false.
=item untieZ<>(%hash)
E<10>Untie a hash variable from the database file.
E<10>The return value is always true.
=item $hash{I<key>} = I<value>
E<10>Store a record.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, it is overwritten.
=item delete($hash{I<key>})
E<10>Remove a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is true, else, it is false.
=item $hash{I<key>}
E<10>Retrieve a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is the value of the corresponding record. `undef' is returned if no record corresponds.
=item exists($hash{I<key>})
E<10>Check whether a record corrsponding a key exists.
E<10>`I<key>' specifies the key.
E<10>The return value is true if the record exists, else it is false.
=item $hash = Z<>()
E<10>Remove all records.
E<10>The return value is always `undef'.
=item Z<>(the iterator)
E<10>The inner methods `FIRSTKEY' and `NEXTKEY' are also implemented so that you can use the tying functions `each', `keys', and so on.
=back
=head2 Class TokyoCabinet::BDB
B+ tree database is a file containing a B+ tree and is handled with the B+ tree database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the B+ tree database object to it. The method `open' is used to open a database file and the method `close' is used to close the database file. To avoid data missing or corruption, it is important to close every database file when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.
=over
=item $bdb = TokyoCabinet::BDB-E<gt>newZ<>()
E<10>Create a B+ tree database object.
E<10>The return value is the new B+ tree database object.
=item $bdb-E<gt>errmsgZ<>(I<ecode>)
E<10>Get the message string corresponding to an error code.
E<10>`I<ecode>' specifies the error code. If it is not defined or negative, the last happened error code is specified.
E<10>The return value is the message string of the error code.
=item $bdb-E<gt>ecodeZ<>()
E<10>Get the last happened error code.
E<10>The return value is the last happened error code.
E<10>The following error codes are defined: `$bdb-E<gt>ESUCCESS' for success, `$bdb-E<gt>ETHREAD' for threading error, `$bdb-E<gt>EINVALID' for invalid operation, `$bdb-E<gt>ENOFILE' for file not found, `$bdb-E<gt>ENOPERM' for no permission, `$bdb-E<gt>EMETA' for invalid meta data, `$bdb-E<gt>ERHEAD' for invalid record header, `$bdb-E<gt>EOPEN' for open error, `$bdb-E<gt>ECLOSE' for close error, `$bdb-E<gt>ETRUNC' for trunc error, `$bdb-E<gt>ESYNC' for sync error, `$bdb-E<gt>ESTAT' for stat error, `$bdb-E<gt>ESEEK' for seek error, `$bdb-E<gt>EREAD' for read error, `$bdb-E<gt>EWRITE' for write error, `$bdb-E<gt>EMMAP' for mmap error, `$bdb-E<gt>ELOCK' for lock error, `$bdb-E<gt>EUNLINK' for unlink error, `$bdb-E<gt>ERENAME' for rename error, `$bdb-E<gt>EMKDIR' for mkdir error, `$bdb-E<gt>ERMDIR' for rmdir error, `$bdb-E<gt>EKEEP' for existing record, `$bdb-E<gt>ENOREC' for no record found, and `$bdb-E<gt>EMISC' for miscellaneous error.
=item $bdb-E<gt>setcmpfuncZ<>(I<cmp>)
E<10>Set the custom comparison function.
E<10>`I<cmp>' specifies the custom comparison function. It can be either the reference of a block or the name of a function.
E<10>If successful, the return value is true, else, it is false.
E<10>The default comparison function compares keys of two records by lexical order. The constants `$bdb-E<gt>CMPLEXICAL' (dafault), `$bdb-E<gt>CMPDECIMAL', `$bdb-E<gt>CMPINT32', and `$bdb-E<gt>CMPINT64' are built-in. Note that the comparison function should be set before the database is opened. Moreover, user-defined comparison functions should be set every time the database is being opened.
=item $bdb-E<gt>tuneZ<>(I<lmemb>, I<nmemb>, I<bnum>, I<apow>, I<fpow>, I<opts>)
E<10>Set the tuning parameters.
E<10>`I<lmemb>' specifies the number of members in each leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 128.
E<10>`I<nmemb>' specifies the number of members in each non-leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 256.
E<10>`I<bnum>' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 32749. Suggested size of the bucket array is about from 1 to 4 times of the number of all pages to be stored.
E<10>`I<apow>' specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^8=256.
E<10>`I<fpow>' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.
E<10>`I<opts>' specifies options by bitwise-or: `$bdb-E<gt>TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `$bdb-E<gt>TDEFLATE' specifies that each record is compressed with Deflate encoding, `$bdb-E<gt>TBZIP' specifies that each record is compressed with BZIP2 encoding, `$bdb-E<gt>TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.
E<10>If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.
=item $bdb-E<gt>setcacheZ<>(I<lcnum>, I<ncnum>)
E<10>Set the caching parameters.
E<10>`I<lcnum>' specifies the maximum number of leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 1024.
E<10>`I<ncnum>' specifies the maximum number of non-leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 512.
E<10>If successful, the return value is true, else, it is false.
E<10>Note that the caching parameters of the database should be set before the database is opened.
=item $bdb-E<gt>setxmsizZ<>(I<xmsiz>)
E<10>Set the size of the extra mapped memory.
E<10>`I<xmsiz>' specifies the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. It is disabled by default.
E<10>If successful, the return value is true, else, it is false.
E<10>Note that the mapping parameters should be set before the database is opened.
=item $bdb-E<gt>setdfunitZ<>(I<dfunit>)
E<10>Set the unit step number of auto defragmentation.
E<10>`I<dfunit>' specifie the unit step number. If it is not more than 0, the auto defragmentation is disabled. It is disabled by default.
E<10>If successful, the return value is true, else, it is false.
E<10>Note that the defragmentation parameters should be set before the database is opened.
=item $bdb-E<gt>openZ<>(I<path>, I<omode>)
E<10>Open a database file.
E<10>`I<path>' specifies the path of the database file.
E<10>`I<omode>' specifies the connection mode: `$bdb-E<gt>OWRITER' as a writer, `$bdb-E<gt>OREADER' as a reader. If the mode is `$bdb-E<gt>OWRITER', the following may be added by bitwise-or: `$bdb-E<gt>OCREAT', which means it creates a new database if not exist, `$bdb-E<gt>OTRUNC', which means it creates a new database regardless if one exists, `$bdb-E<gt>OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `$bdb-E<gt>OREADER' and `$bdb-E<gt>OWRITER' can be added to by bitwise-or: `$bdb-E<gt>ONOLCK', which means it opens the database file without file locking, or `$bdb-E<gt>OLCKNB', which means locking is performed without blocking. If it is not defined, `$bdb-E<gt>OREADER' is specified.
E<10>If successful, the return value is true, else, it is false.
=item $bdb-E<gt>closeZ<>()
E<10>Close the database file.
E<10>If successful, the return value is true, else, it is false.
E<10>Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.
=item $bdb-E<gt>putZ<>(I<key>, I<value>)
E<10>Store a record.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, it is overwritten.
=item $bdb-E<gt>putkeepZ<>(I<key>, I<value>)
E<10>Store a new record.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, this method has no effect.
=item $bdb-E<gt>putcatZ<>(I<key>, I<value>)
E<10>Concatenate a value at the end of the existing record.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If there is no corresponding record, a new record is created.
=item $bdb-E<gt>putdupZ<>(I<key>, I<value>)
E<10>Store a record with allowing duplication of keys.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, the new record is placed after the existing one.
=item $bdb-E<gt>putlistZ<>(I<key>, I<values>)
E<10>Store records with allowing duplication of keys.
E<10>`I<key>' specifies the key.
E<10>`I<values>' specifies the reference to an array of the values.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, the new records are placed after the existing one.
=item $bdb-E<gt>outZ<>(I<key>)
E<10>Remove a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is true, else, it is false.
E<10>If the key of duplicated records is specified, the first one is selected.
=item $bdb-E<gt>outlistZ<>(I<key>)
E<10>Remove records.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is true, else, it is false.
E<10>If the key of duplicated records is specified, all of them are removed.
=item $bdb-E<gt>getZ<>(I<key>)
E<10>Retrieve a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is the value of the corresponding record. `undef' is returned if no record corresponds.
E<10>If the key of duplicated records is specified, the first one is selected.
=item $bdb-E<gt>getlistZ<>(I<key>)
E<10>Retrieve records.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is the reference to an array of the values of the corresponding records. `undef' is returned if no record corresponds.
=item $bdb-E<gt>vnumZ<>(I<key>)
E<10>Get the number of records corresponding a key.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is the number of the corresponding records, else, it is 0.
=item $bdb-E<gt>vsizZ<>(I<key>)
E<10>Get the size of the value of a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is the size of the value of the corresponding record, else, it is -1.
E<10>If the key of duplicated records is specified, the first one is selected.
=item $bdb-E<gt>rangeZ<>(I<bkey>, I<binc>, I<ekey>, I<einc>, I<max>)
E<10>Get keys of ranged records.
E<10>`I<bkey>' specifies the key of the beginning border. If it is not defined, the first record is specified.
E<10>`I<binc>' specifies whether the beginning border is inclusive or not. If it is not defined, false is specified.
E<10>`I<ekey>' specifies the key of the ending border. If it is not defined, the last record is specified.
E<10>`I<einc>' specifies whether the ending border is inclusive or not. If it is not defined, false is specified.
E<10>`I<max>' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
E<10>The return value is the reference to an array of the keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.
=item $bdb-E<gt>fwmkeysZ<>(I<prefix>, I<max>)
E<10>Get forward matching keys.
E<10>`I<prefix>' specifies the prefix of the corresponding keys.
E<10>`I<max>' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
E<10>The return value is the reference to an array of the keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.
=item $bdb-E<gt>addintZ<>(I<key>, I<num>)
E<10>Add an integer to a record.
E<10>`I<key>' specifies the key.
E<10>`I<num>' specifies the additional value.
E<10>If successful, the return value is the summation value, else, it is `undef'.
E<10>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. Because records are stored in binary format, they should be processed with the `unpack' function with the `i' operator after retrieval.
=item $bdb-E<gt>adddoubleZ<>(I<key>, I<num>)
E<10>Add a real number to a record.
E<10>`I<key>' specifies the key.
E<10>`I<num>' specifies the additional value.
E<10>If successful, the return value is the summation value, else, it is `undef'.
E<10>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. Because records are stored in binary format, they should be processed with the `unpack' function with the `d' operator after retrieval.
=item $bdb-E<gt>syncZ<>()
E<10>Synchronize updated contents with the file and the device.
E<10>If successful, the return value is true, else, it is false.
E<10>This method is useful when another process connects the same database file.
=item $bdb-E<gt>optimizeZ<>(I<lmemb>, I<nmemb>, I<bnum>, I<apow>, I<fpow>, I<opts>)
E<10>Optimize the database file.
E<10>`I<lmemb>' specifies the number of members in each leaf page. If it is not defined or not more than 0, the current setting is not changed.
E<10>`I<nmemb>' specifies the number of members in each non-leaf page. If it is not defined or not more than 0, the current setting is not changed.
E<10>`I<bnum>' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of pages.
E<10>`I<apow>' specifies the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.
E<10>`I<fpow>' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.
E<10>`I<opts>' specifies options by bitwise-or: `$bdb-E<gt>TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `$bdb-E<gt>TDEFLATE' specifies that each record is compressed with Deflate encoding, `$bdb-E<gt>TBZIP' specifies that each record is compressed with BZIP2 encoding, `$bdb-E<gt>TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.
E<10>If successful, the return value is true, else, it is false.
E<10>This method is useful to reduce the size of the database file with data fragmentation by successive updating.
=item $bdb-E<gt>vanishZ<>()
E<10>Remove all records.
E<10>If successful, the return value is true, else, it is false.
=item $bdb-E<gt>copyZ<>(I<path>)
E<10>Copy the database file.
E<10>`I<path>' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.
E<10>If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.
E<10>The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.
=item $bdb-E<gt>tranbeginZ<>()
E<10>Begin the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. Because all pages are cached on memory while the transaction, the amount of referred records is limited by the memory capacity. If the database is closed during transaction, the transaction is aborted implicitly.
=item $bdb-E<gt>trancommitZ<>()
E<10>Commit the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>Update in the transaction is fixed when it is committed successfully.
=item $bdb-E<gt>tranabortZ<>()
E<10>Abort the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.
=item $bdb-E<gt>pathZ<>()
E<10>Get the path of the database file.
E<10>The return value is the path of the database file or `undef' if the object does not connect to any database file.
=item $bdb-E<gt>rnumZ<>()
E<10>Get the number of records.
E<10>The return value is the number of records or 0 if the object does not connect to any database file.
=item $bdb-E<gt>fsizZ<>()
E<10>Get the size of the database file.
E<10>The return value is the size of the database file or 0 if the object does not connect to any database file.
=back
=head2 Class TokyoCabinet::BDBCUR
=over
=item $cur = TokyoCabinet::BDBCUR-E<gt>newZ<>(I<bdb>)
E<10>Create a cursor object.
E<10>`I<bdb>' specifies the B+ tree database object.
E<10>The return value is the new cursor object.
E<10>Note that the cursor is available only after initialization with the `first' or the `jump' methods and so on. Moreover, the position of the cursor will be indefinite when the database is updated after the initialization of the cursor.
=item $cur-E<gt>firstZ<>()
E<10>Move the cursor to the first record.
E<10>If successful, the return value is true, else, it is false. False is returned if there is no record in the database.
=item $cur-E<gt>lastZ<>()
E<10>Move the cursor to the last record.
E<10>If successful, the return value is true, else, it is false. False is returned if there is no record in the database.
=item $cur-E<gt>jumpZ<>(I<key>)
E<10>Move the cursor to the front of records corresponding a key.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is true, else, it is false. False is returned if there is no record corresponding the condition.
E<10>The cursor is set to the first record corresponding the key or the next substitute if completely matching record does not exist.
=item $cur-E<gt>prevZ<>()
E<10>Move the cursor to the previous record.
E<10>If successful, the return value is true, else, it is false. False is returned if there is no previous record.
=item $cur-E<gt>nextZ<>()
E<10>Move the cursor to the next record.
E<10>If successful, the return value is true, else, it is false. False is returned if there is no next record.
=item $cur-E<gt>putZ<>(I<value>, I<cpmode>)
E<10>Insert a record around the cursor.
E<10>`I<value>' specifies the value.
E<10>`I<cpmode>' specifies detail adjustment: `$cur-E<gt>CPCURRENT', which means that the value of the current record is overwritten, `$cur-E<gt>CPBEFORE', which means that the new record is inserted before the current record, `$cur-E<gt>CPAFTER', which means that the new record is inserted after the current record.
E<10>If successful, the return value is true, else, it is false. False is returned when the cursor is at invalid position.
E<10>After insertion, the cursor is moved to the inserted record.
=item $cur-E<gt>outZ<>()
E<10>Remove the record where the cursor is.
E<10>If successful, the return value is true, else, it is false. False is returned when the cursor is at invalid position.
E<10>After deletion, the cursor is moved to the next record if possible.
=item $cur-E<gt>keyZ<>()
E<10>Get the key of the record where the cursor is.
E<10>If successful, the return value is the key, else, it is `undef'. 'undef' is returned when the cursor is at invalid position.
=item $cur-E<gt>valZ<>()
E<10>Get the value of the record where the cursor is.
E<10>If successful, the return value is the value, else, it is `undef'. 'undef' is returned when the cursor is at invalid position.
=back
=head2 Tying functions of TokyoCabinet::BDB
=over
=item tieZ<>(%hash, E<quot>TokyoCabinet::BDBE<quot>, I<path>, I<omode>, I<lmemb>, I<nmemb>, I<bnum>, I<apow>, I<fpow>, I<opts>, I<lcnum>, I<ncnum>)
E<10>Tie a hash variable to a B+ tree database file.
E<10>`I<path>' specifies the path of the database file.
E<10>`I<omode>' specifies the connection mode: `TokyoCabinet::BDB::OWRITER' as a writer, `TokyoCabinet::BDB::OREADER' as a reader. If the mode is `TokyoCabinet::BDB::OWRITER', the following may be added by bitwise-or: `TokyoCabinet::BDB::OCREAT', which means it creates a new database if not exist, `TokyoCabinet::BDB::OTRUNC', which means it creates a new database regardless if one exists, `TokyoCabinet::BDB::OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `TokyoCabinet::BDB::OREADER' and `TokyoCabinet::BDB::OWRITER' can be added to by bitwise-or: `TokyoCabinet::BDB::ONOLCK', which means it opens the database file without file locking, or `TokyoCabinet::BDB::OLCKNB', which means locking is performed without blocking. If it is not defined, `TokyoCabinet::BDB::OREADER' is specified.
E<10>`I<lmemb>' specifies the number of members in each leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 128.
E<10>`I<nmemb>' specifies the number of members in each non-leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 256.
E<10>`I<bnum>' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 32749.
E<10>`I<apow>' specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^8=256.
E<10>`I<fpow>' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.
E<10>`I<opts>' specifies options by bitwise-or: `TokyoCabinet::BDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::BDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::BDB::TBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::BDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.
E<10>`I<lcnum>' specifies the maximum number of leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified.
E<10>`I<ncnum>' specifies the maximum number of non-leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified.
E<10>If successful, the return value is true, else, it is false.
=item untieZ<>(%hash)
E<10>Untie a hash variable from the database file.
E<10>The return value is always true.
=item $hash{I<key>} = I<value>
E<10>Store a record.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, it is overwritten.
=item delete($hash{I<key>})
E<10>Remove a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is true, else, it is false.
=item $hash{I<key>}
E<10>Retrieve a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is the value of the corresponding record. `undef' is returned if no record corresponds.
=item exists($hash{I<key>})
E<10>Check whether a record corrsponding a key exists.
E<10>`I<key>' specifies the key.
E<10>The return value is true if the record exists, else it is false.
=item $hash = Z<>()
E<10>Remove all records.
E<10>The return value is always `undef'.
=item (the iterator)
E<10>The inner methods `FIRSTKEY' and `NEXTKEY' are also implemented so that you can use the tying functions `each', `keys', and so on.
=back
=head2 Class TokyoCabinet::FDB
Fixed-length database is a file containing an array of fixed-length elements and is handled with the fixed-length database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the fixed-length database object to it. The method `open' is used to open a database file and the method `close' is used to close the database file. To avoid data missing or corruption, it is important to close every database file when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.
=over
=item $fdb = TokyoCabinet::FDB-E<gt>newZ<>()
E<10>Create a fixed-length database object.
E<10>The return value is the new fixed-length database object.
=item $fdb-E<gt>errmsgZ<>(I<ecode>)
E<10>Get the message string corresponding to an error code.
E<10>`I<ecode>' specifies the error code. If it is not defined or negative, the last happened error code is specified.
E<10>The return value is the message string of the error code.
=item $fdb-E<gt>ecodeZ<>()
E<10>Get the last happened error code.
E<10>The return value is the last happened error code.
E<10>The following error codes are defined: `$fdb-E<gt>ESUCCESS' for success, `$fdb-E<gt>ETHREAD' for threading error, `$fdb-E<gt>EINVALID' for invalid operation, `$fdb-E<gt>ENOFILE' for file not found, `$fdb-E<gt>ENOPERM' for no permission, `$fdb-E<gt>EMETA' for invalid meta data, `$fdb-E<gt>ERHEAD' for invalid record header, `$fdb-E<gt>EOPEN' for open error, `$fdb-E<gt>ECLOSE' for close error, `$fdb-E<gt>ETRUNC' for trunc error, `$fdb-E<gt>ESYNC' for sync error, `$fdb-E<gt>ESTAT' for stat error, `$fdb-E<gt>ESEEK' for seek error, `$fdb-E<gt>EREAD' for read error, `$fdb-E<gt>EWRITE' for write error, `$fdb-E<gt>EMMAP' for mmap error, `$fdb-E<gt>ELOCK' for lock error, `$fdb-E<gt>EUNLINK' for unlink error, `$fdb-E<gt>ERENAME' for rename error, `$fdb-E<gt>EMKDIR' for mkdir error, `$fdb-E<gt>ERMDIR' for rmdir error, `$fdb-E<gt>EKEEP' for existing record, `$fdb-E<gt>ENOREC' for no record found, and `$fdb-E<gt>EMISC' for miscellaneous error.
=item $fdb-E<gt>tuneZ<>(I<width>, I<limsiz>);
E<10>Set the tuning parameters.
E<10>`I<width>' specifies the width of the value of each record. If it is not defined or not more than 0, the default value is specified. The default value is 255.
E<10>`I<limsiz>' specifies the limit size of the database file. If it is not defined or not more than 0, the default value is specified. The default value is 268435456.
E<10>If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.
=item $fdb-E<gt>openZ<>(I<path>, I<omode>)
E<10>Open a database file.
E<10>`I<path>' specifies the path of the database file.
E<10>`I<omode>' specifies the connection mode: `$fdb-E<gt>OWRITER' as a writer, `$fdb-E<gt>OREADER' as a reader. If the mode is `$fdb-E<gt>OWRITER', the following may be added by bitwise-or: `$fdb-E<gt>OCREAT', which means it creates a new database if not exist, `$fdb-E<gt>OTRUNC', which means it creates a new database regardless if one exists. Both of `$fdb-E<gt>OREADER' and `$fdb-E<gt>OWRITER' can be added to by bitwise-or: `$fdb-E<gt>ONOLCK', which means it opens the database file without file locking, or `$fdb-E<gt>OLCKNB', which means locking is performed without blocking. If it is not defined, `$fdb-E<gt>OREADER' is specified.
E<10>If successful, the return value is true, else, it is false.
=item $fdb-E<gt>closeZ<>()
E<10>Close the database file.
E<10>If successful, the return value is true, else, it is false.
E<10>Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.
=item $fdb-E<gt>putZ<>(I<key>, I<value>)
E<10>Store a record.
E<10>`I<key>' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, it is overwritten.
=item $fdb-E<gt>putkeepZ<>(I<key>, I<value>)
E<10>Store a new record.
E<10>`I<key>' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, this method has no effect.
=item $fdb-E<gt>putcatZ<>(I<key>, I<value>)
E<10>Concatenate a value at the end of the existing record.
E<10>`I<key>' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If there is no corresponding record, a new record is created.
=item $fdb-E<gt>outZ<>(I<key>)
E<10>Remove a record.
E<10>`I<key>' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified.
E<10>If successful, the return value is true, else, it is false.
=item $fdb-E<gt>getZ<>(I<key>)
E<10>Retrieve a record.
E<10>`I<key>' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified.
E<10>If successful, the return value is the value of the corresponding record. `undef' is returned if no record corresponds.
=item $fdb-E<gt>vsizZ<>(I<key>)
E<10>Get the size of the value of a record.
E<10>`I<key>' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified.
E<10>If successful, the return value is the size of the value of the corresponding record, else, it is -1.
=item $fdb-E<gt>iterinitZ<>()
E<10>Initialize the iterator.
E<10>If successful, the return value is true, else, it is false.
E<10>The iterator is used in order to access the key of every record stored in a database.
=item $fdb-E<gt>iternextZ<>()
E<10>Get the next key of the iterator.
E<10>If successful, the return value is the next key, else, it is `undef'. `undef' is returned when no record is to be get out of the iterator.
E<10>It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. The order of this traversal access method is ascending of the ID number.
=item $fdb-E<gt>rangeZ<>(I<interval>, I<max>)
E<10>Get keys with an interval notation.
E<10>`I<interval>' specifies the interval notation.
E<10>`I<max>' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
E<10>The return value is the reference to an array of the keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.
=item $fdb-E<gt>addintZ<>(I<key>, I<num>)
E<10>Add an integer to a record.
E<10>`I<key>' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.
E<10>`I<num>' specifies the additional value.
E<10>If successful, the return value is the summation value, else, it is `undef'.
E<10>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. Because records are stored in binary format, they should be processed with the `unpack' function with the `i' operator after retrieval.
=item $fdb-E<gt>adddoubleZ<>(I<key>, I<num>)
E<10>Add a real number to a record.
E<10>`I<key>' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.
E<10>`I<num>' specifies the additional value.
E<10>If successful, the return value is the summation value, else, it is `undef'.
E<10>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. Because records are stored in binary format, they should be processed with the `unpack' function with the `d' operator after retrieval.
=item $fdb-E<gt>syncZ<>()
E<10>Synchronize updated contents with the file and the device.
E<10>If successful, the return value is true, else, it is false.
E<10>This method is useful when another process connects the same database file.
=item $fdb-E<gt>optimizeZ<>(I<width>, I<limsiz>)
E<10>Optimize the database file.
E<10>`I<width>' specifies the width of the value of each record. If it is not defined or not more than 0, the current setting is not changed.
E<10>`I<limsiz>' specifies the limit size of the database file. If it is not defined or not more than 0, the current setting is not changed.
E<10>If successful, the return value is true, else, it is false.
=item $fdb-E<gt>vanishZ<>()
E<10>Remove all records.
E<10>If successful, the return value is true, else, it is false.
=item $fdb-E<gt>copyZ<>(I<path>)
E<10>Copy the database file.
E<10>`I<path>' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.
E<10>If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.
E<10>The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.
=item $fdb-E<gt>tranbeginZ<>()
E<10>Begin the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.
=item $fdb-E<gt>trancommitZ<>()
E<10>Commit the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>Update in the transaction is fixed when it is committed successfully.
=item $fdb-E<gt>tranabortZ<>()
E<10>Abort the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.
=item $fdb-E<gt>pathZ<>()
E<10>Get the path of the database file.
E<10>The return value is the path of the database file or `undef' if the object does not connect to any database file.
=item $fdb-E<gt>rnumZ<>()
E<10>Get the number of records.
E<10>The return value is the number of records or 0 if the object does not connect to any database file.
=item $fdb-E<gt>fsizZ<>()
E<10>Get the size of the database file.
E<10>The return value is the size of the database file or 0 if the object does not connect to any database file.
=back
=head2 Tying functions of TokyoCabinet::FDB
=over
=item tieZ<>(%hash, E<quot>TokyoCabinet::FDBE<quot>, I<path>, I<omode>, I<width>, I<limsiz>)
E<10>Tie a hash variable to a hash database file.
E<10>`I<path>' specifies the path of the database file.
E<10>`I<omode>' specifies the connection mode: `TokyoCabinet::FDB::OWRITER' as a writer, `TokyoCabinet::FDB::OREADER' as a reader. If the mode is `TokyoCabinet::FDB::OWRITER', the following may be added by bitwise-or: `TokyoCabinet::FDB::OCREAT', which means it creates a new database if not exist, `TokyoCabinet::FDB::OTRUNC', which means it creates a new database regardless if one exists. Both of `TokyoCabinet::FDB::OREADER' and `TokyoCabinet::FDB::OWRITER' can be added to by bitwise-or: `TokyoCabinet::FDB::ONOLCK', which means it opens the database file without file locking, or `TokyoCabinet::FDB::OLCKNB', which means locking is performed without blocking. If it is not defined, `TokyoCabinet::FDB::OREADER' is specified.
E<10>`I<width>' specifies the width of the value of each record. If it is not defined or not more than 0, the default value is specified. The default value is 255.
E<10>`I<limsiz>' specifies the limit size of the database file. If it is not defined or not more than 0, the default value is specified. The default value is 268435456.
E<10>If successful, the return value is true, else, it is false.
=item untieZ<>(%hash)
E<10>Untie a hash variable from the database file.
E<10>The return value is always true.
=item $hash{I<key>} = I<value>
E<10>Store a record.
E<10>`I<key>' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, it is overwritten.
=item delete($hash{I<key>})
E<10>Remove a record.
E<10>`I<key>' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified.
E<10>If successful, the return value is true, else, it is false.
=item $hash{I<key>}
E<10>Retrieve a record.
E<10>`I<key>' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified.
E<10>If successful, the return value is the value of the corresponding record. `undef' is returned if no record corresponds.
=item exists($hash{I<key>})
E<10>Check whether a record corrsponding a key exists.
E<10>`I<key>' specifies the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified.
E<10>The return value is true if the record exists, else it is false.
=item $hash = Z<>()
E<10>Remove all records.
E<10>The return value is always `undef'.
=item Z<>(the iterator)
E<10>The inner methods `FIRSTKEY' and `NEXTKEY' are also implemented so that you can use the tying functions `each', `keys', and so on.
=back
=head2 Class TokyoCabinet::TDB
Table database is a file containing records composed of the primary keys and arbitrary columns and is handled with the table database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the table database object to it. The method `open' is used to open a database file and the method `close' is used to close the database file. To avoid data missing or corruption, it is important to close every database file when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.
=over
=item $tdb = TokyoCabinet::TDB-E<gt>newZ<>()
E<10>Create a table database object.
E<10>The return value is the new table database object.
=item $tdb-E<gt>errmsgZ<>(I<ecode>)
E<10>Get the message string corresponding to an error code.
E<10>`I<ecode>' specifies the error code. If it is not defined or negative, the last happened error code is specified.
E<10>The return value is the message string of the error code.
=item $tdb-E<gt>ecodeZ<>()
E<10>Get the last happened error code.
E<10>The return value is the last happened error code.
E<10>The following error codes are defined: `$tdb-E<gt>ESUCCESS' for success, `$tdb-E<gt>ETHREAD' for threading error, `$tdb-E<gt>EINVALID' for invalid operation, `$tdb-E<gt>ENOFILE' for file not found, `$tdb-E<gt>ENOPERM' for no permission, `$tdb-E<gt>EMETA' for invalid meta data, `$tdb-E<gt>ERHEAD' for invalid record header, `$tdb-E<gt>EOPEN' for open error, `$tdb-E<gt>ECLOSE' for close error, `$tdb-E<gt>ETRUNC' for trunc error, `$tdb-E<gt>ESYNC' for sync error, `$tdb-E<gt>ESTAT' for stat error, `$tdb-E<gt>ESEEK' for seek error, `$tdb-E<gt>EREAD' for read error, `$tdb-E<gt>EWRITE' for write error, `$tdb-E<gt>EMMAP' for mmap error, `$tdb-E<gt>ELOCK' for lock error, `$tdb-E<gt>EUNLINK' for unlink error, `$tdb-E<gt>ERENAME' for rename error, `$tdb-E<gt>EMKDIR' for mkdir error, `$tdb-E<gt>ERMDIR' for rmdir error, `$tdb-E<gt>EKEEP' for existing record, `$tdb-E<gt>ENOREC' for no record found, and `$tdb-E<gt>EMISC' for miscellaneous error.
=item $tdb-E<gt>tuneZ<>(I<bnum>, I<apow>, I<fpow>, I<opts>)
E<10>Set the tuning parameters.
E<10>`I<bnum>' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 131071. Suggested size of the bucket array is about from 0.5 to 4 times of the number of all records to be stored.
E<10>`I<apow>' specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^4=16.
E<10>`I<fpow>' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.
E<10>`I<opts>' specifies options by bitwise-or: `$tdb-E<gt>TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `$tdb-E<gt>TDEFLATE' specifies that each record is compressed with Deflate encoding, `$tdb-E<gt>TBZIP' specifies that each record is compressed with BZIP2 encoding, `$tdb-E<gt>TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.
E<10>If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.
=item $tdb-E<gt>setcacheZ<>(I<rcnum>, I<lcnum>, I<ncnum>)
E<10>Set the caching parameters.
E<10>`I<rcnum>' specifies the maximum number of records to be cached. If it is not defined or not more than 0, the record cache is disabled. It is disabled by default.
E<10>`I<lcnum>' specifies the maximum number of leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 4096.
E<10>`I<ncnum>' specifies the maximum number of non-leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 512.
E<10>If successful, the return value is true, else, it is false.
E<10>Note that the caching parameters of the database should be set before the database is opened.
=item $tdb-E<gt>setxmsizZ<>(I<xmsiz>)
E<10>Set the size of the extra mapped memory.
E<10>`I<xmsiz>' specifies the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. The default size is 67108864.
E<10>If successful, the return value is true, else, it is false.
E<10>Note that the mapping parameters should be set before the database is opened.
=item $tdb-E<gt>setdfunitZ<>(I<dfunit>)
E<10>Set the unit step number of auto defragmentation.
E<10>`I<dfunit>' specifie the unit step number. If it is not more than 0, the auto defragmentation is disabled. It is disabled by default.
E<10>If successful, the return value is true, else, it is false.
E<10>Note that the defragmentation parameters should be set before the database is opened.
=item $tdb-E<gt>openZ<>(I<path>, I<omode>)
E<10>Open a database file.
E<10>`I<path>' specifies the path of the database file.
E<10>`I<omode>' specifies the connection mode: `$tdb-E<gt>OWRITER' as a writer, `$tdb-E<gt>OREADER' as a reader. If the mode is `$tdb-E<gt>OWRITER', the following may be added by bitwise-or: `$tdb-E<gt>OCREAT', which means it creates a new database if not exist, `$tdb-E<gt>OTRUNC', which means it creates a new database regardless if one exists, `$tdb-E<gt>OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `$tdb-E<gt>OREADER' and `$tdb-E<gt>OWRITER' can be added to by bitwise-or: `$tdb-E<gt>ONOLCK', which means it opens the database file without file locking, or `$tdb-E<gt>OLCKNB', which means locking is performed without blocking. If it is not defined, `$tdb-E<gt>OREADER' is specified.
E<10>If successful, the return value is true, else, it is false.
=item $tdb-E<gt>closeZ<>()
E<10>Close the database file.
E<10>If successful, the return value is true, else, it is false.
E<10>Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.
=item $tdb-E<gt>putZ<>(I<pkey>, I<cols>)
E<10>Store a record.
E<10>`I<pkey>' specifies the primary key.
E<10>`I<cols>' specifies the reference to a hash containing columns.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, it is overwritten.
=item $tdb-E<gt>putkeepZ<>(I<pkey>, I<cols>)
E<10>Store a new record.
E<10>`I<pkey>' specifies the primary key.
E<10>`I<cols>' specifies the reference to a hash containing columns.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, this method has no effect.
=item $tdb-E<gt>putcatZ<>(I<pkey>, I<cols>)
E<10>Concatenate columns of the existing record.
E<10>`I<pkey>' specifies the primary key.
E<10>`I<cols>' specifies the reference to a hash containing columns.
E<10>If successful, the return value is true, else, it is false.
E<10>If there is no corresponding record, a new record is created.
=item $tdb-E<gt>outZ<>(I<pkey>)
E<10>Remove a record.
E<10>`I<pkey>' specifies the primary key.
E<10>If successful, the return value is true, else, it is false.
=item $tdb-E<gt>getZ<>(I<pkey>)
E<10>Retrieve a record.
E<10>`I<pkey>' specifies the primary key.
E<10>If successful, the return value is the reference to a hash of the columns of the corresponding record. `undef' is returned if no record corresponds.
=item $tdb-E<gt>vsizZ<>(I<pkey>)
E<10>Get the size of the value of a record.
E<10>`I<pkey>' specifies the primary key.
E<10>If successful, the return value is the size of the value of the corresponding record, else, it is -1.
=item $tdb-E<gt>iterinitZ<>()
E<10>Initialize the iterator.
E<10>If successful, the return value is true, else, it is false.
E<10>The iterator is used in order to access the primary key of every record stored in a database.
=item $tdb-E<gt>iternextZ<>()
E<10>Get the next primary key of the iterator.
E<10>If successful, the return value is the next primary key, else, it is `undef'. `undef' is returned when no record is to be get out of the iterator.
E<10>It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.
=item $tdb-E<gt>fwmkeysZ<>(I<prefix>, I<max>)
E<10>Get forward matching primary keys.
E<10>`I<prefix>' specifies the prefix of the corresponding keys.
E<10>`I<max>' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
E<10>The return value is the reference to an array of the keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.
E<10>Note that this method may be very slow because every key in the database is scanned.
=item $tdb-E<gt>addintZ<>(I<pkey>, I<num>)
E<10>Add an integer to a record.
E<10>`I<pkey>' specifies primary key.
E<10>`I<num>' specifies the additional value.
E<10>If successful, the return value is the summation value, else, it is `undef'.
E<10>The additional value is stored as a decimal string value of a column whose name is "_num". If no record corresponds, a new record with the additional value is stored.
=item $tdb-E<gt>adddoubleZ<>(I<pkey>, I<num>)
E<10>Add a real number to a record.
E<10>`I<pkey>' specifies primary key.
E<10>`I<num>' specifies the additional value.
E<10>If successful, the return value is the summation value, else, it is `undef'.
E<10>The additional value is stored as a decimal string value of a column whose name is "_num". If no record corresponds, a new record with the additional value is stored.
=item $tdb-E<gt>syncZ<>()
E<10>Synchronize updated contents with the file and the device.
E<10>If successful, the return value is true, else, it is false.
E<10>This method is useful when another process connects the same database file.
=item $tdb-E<gt>optimizeZ<>(I<bnum>, I<apow>, I<fpow>, I<opts>)
E<10>Optimize the database file.
E<10>`I<bnum>' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of records.
E<10>`I<apow>' specifies the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.
E<10>`I<fpow>' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.
E<10>`I<opts>' specifies options by bitwise-or: `$tdb-E<gt>TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `$tdb-E<gt>TDEFLATE' specifies that each record is compressed with Deflate encoding, `$tdb-E<gt>TBZIP' specifies that each record is compressed with BZIP2 encoding, `$tdb-E<gt>TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.
E<10>If successful, the return value is true, else, it is false.
E<10>This method is useful to reduce the size of the database file with data fragmentation by successive updating.
=item $tdb-E<gt>vanishZ<>()
E<10>Remove all records.
E<10>If successful, the return value is true, else, it is false.
=item $tdb-E<gt>copyZ<>(I<path>)
E<10>Copy the database file.
E<10>`I<path>' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.
E<10>If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.
E<10>The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.
=item $tdb-E<gt>tranbeginZ<>()
E<10>Begin the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.
=item $tdb-E<gt>trancommitZ<>()
E<10>Commit the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>Update in the transaction is fixed when it is committed successfully.
=item $tdb-E<gt>tranabortZ<>()
E<10>Abort the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.
=item $tdb-E<gt>pathZ<>()
E<10>Get the path of the database file.
E<10>The return value is the path of the database file or `undef' if the object does not connect to any database file.
=item $tdb-E<gt>rnumZ<>()
E<10>Get the number of records.
E<10>The return value is the number of records or 0 if the object does not connect to any database file.
=item $tdb-E<gt>fsizZ<>()
E<10>Get the size of the database file.
E<10>The return value is the size of the database file or 0 if the object does not connect to any database file.
=item $tdb-E<gt>setindexZ<>(I<name>, I<type>)
E<10>Set a column index.
E<10>`I<name>' specifies the name of a column. If the name of an existing index is specified, the index is rebuilt. An empty string means the primary key.
E<10>`I<type>' specifies the index type: `$tdb-E<gt>ITLEXICAL' for lexical string, `$tdb-E<gt>ITDECIMAL' for decimal string, `$tdb-E<gt>ITTOKEN' for token inverted index, `$tdb-E<gt>ITQGRAM' for q-gram inverted index. If it is `$tdb-E<gt>ITOPT', the index is optimized. If it is `$tdb-E<gt>ITVOID', the index is removed. If `$tdb-E<gt>ITKEEP' is added by bitwise-or and the index exists, this method merely returns failure.
E<10>If successful, the return value is true, else, it is false.
=item $tdb-E<gt>genuidZ<>()
E<10>Generate a unique ID number.
E<10>The return value is the new unique ID number or -1 on failure.
=back
=head2 Class TokyoCabinet::TDBQRY
=over
=item $qry = TokyoCabinet::TDBQRY-E<gt>newZ<>(I<tdb>)
E<10>Create a query object.
E<10>`I<tdb>' specifies the table database object.
E<10>The return value is the new query object.
=item $qry-E<gt>addcondZ<>(I<name>, I<op>, I<expr>)
E<10>Add a narrowing condition.
E<10>`I<name>' specifies the name of a column. An empty string means the primary key.
E<10>`I<op>' specifies an operation type: `$qry-E<gt>QCSTREQ' for string which is equal to the expression, `$qry-E<gt>QCSTRINC' for string which is included in the expression, `$qry-E<gt>QCSTRBW' for string which begins with the expression, `$qry-E<gt>QCSTREW' for string which ends with the expression, `$qry-E<gt>QCSTRAND' for string which includes all tokens in the expression, `$qry-E<gt>QCSTROR' for string which includes at least one token in the expression, `$qry-E<gt>QCSTROREQ' for string which is equal to at least one token in the expression, `$qry-E<gt>QCSTRRX' for string which matches regular expressions of the expression, `$qry-E<gt>QCNUMEQ' for number which is equal to the expression, `$qry-E<gt>QCNUMGT' for number which is greater than the expression, `$qry-E<gt>QCNUMGE' for number which is greater than or equal to the expression, `$qry-E<gt>QCNUMLT' for number which is less than the expression, `$qry-E<gt>QCNUMLE' for number which is less than or equal to the expression, `$qry-E<gt>QCNUMBT' for number which is between two tokens of the expression, `$qry-E<gt>QCNUMOREQ' for number which is equal to at least one token in the expression, `$qry-E<gt>QCFTSPH' for full-text search with the phrase of the expression, `$qry-E<gt>QCFTSAND' for full-text search with all tokens in the expression, `$qry-E<gt>QCFTSOR' for full-text search with at least one token in the expression, `$qry-E<gt>QCFTSEX' for full-text search with the compound expression. All operations can be flagged by bitwise-or: `$qry-E<gt>QCNEGATE' for negation, `$qry-E<gt>QCNOIDX' for using no index.
E<10>`I<expr>' specifies an operand exression.
E<10>The return value is always `undef'.
=item $qry-E<gt>setorderZ<>(I<name>, I<type>)
E<10>Set the order of the result.
E<10>`I<name>' specifies the name of a column. An empty string means the primary key.
E<10>`I<type>' specifies the order type: `$qry-E<gt>QOSTRASC' for string ascending, `$qry-E<gt>QOSTRDESC' for string descending, `$qry-E<gt>QONUMASC' for number ascending, `$qry-E<gt>QONUMDESC' for number descending. If it is not defined, `$qry-E<gt>QOSTRASC' is specified.
E<10>The return value is always `undef'.
=item $qry-E<gt>setlimitZ<>(I<max>, I<skip>)
E<10>Set the maximum number of records of the result.
E<10>`I<max>' specifies the maximum number of records of the result. If it is not defined or negative, no limit is specified.
E<10>`I<skip>' specifies the number of skipped records of the result. If it is not defined or not more than 0, no record is skipped.
E<10>The return value is always `undef'.
=item $qry-E<gt>searchZ<>()
E<10>Execute the search.
E<10>The return value is the reference to an array of the primary keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.
=item $qry-E<gt>searchoutZ<>()
E<10>Remove each corresponding record.
E<10>If successful, the return value is true, else, it is false.
=item $qry-E<gt>procZ<>(I<proc>)
E<10>Process each corresponding record.
E<10>`I<proc>' specifies the iterator function called for each record. It can be either the reference of a block or the name of a function. The function receives two parameters. The first parameter is the primary key. The second parameter is the reference to a hash containing columns. It returns flags of the post treatment by bitwise-or: `$qry-E<gt>QPPUT' to modify the record, `$qry-E<gt>QPOUT' to remove the record, `$qry-E<gt>QPSTOP' to stop the iteration.
E<10>If successful, the return value is true, else, it is false.
=item $qry-E<gt>hintZ<>()
E<10>Get the hint string.
E<10>The return value is the hint string.
=item $qry-E<gt>metasearchZ<>(I<others>, I<type>)
E<10>Retrieve records with multiple query objects and get the set of the result.
E<10>`I<others>' specifies the reference to an array of the query objects except for the self object.
E<10>`I<type>' specifies a set operation type: `$qry-E<gt>MSUNION' for the union set, `$qry-E<gt>MSISECT' for the intersection set, `$qry-E<gt>MSDIFF' for the difference set. If it is not defined, `$qry-E<gt>MSUNION' is specified.
E<10>The return value is the reference to an array of the primary keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.
E<10>If the first query object has the order setting, the result array is sorted by the order.
=item $qry-E<gt>kwicZ<>(I<cols>, I<name>, I<width>, I<opts>)
E<10>Generate keyword-in-context strings.
E<10>`I<cols>' specifies the reference to a hash containing columns.
E<10>`I<name>' specifies the name of a column. If it is not defined, the first column of the query is specified.
E<10>`I<width>' specifies the width of strings picked up around each keyword. If it is not defined or negative, the whole text is picked up.
E<10>`I<opts>' specifies options by bitwise-or: `$qry-E<gt>KWMUTAB' specifies that each keyword is marked up between two tab characters, `$qry-E<gt>KWMUCTRL' specifies that each keyword is marked up by the STX (0x02) code and the ETX (0x03) code, `$qry-E<gt>KWMUBRCT' specifies that each keyword is marked up by the two square brackets, `$qry-E<gt>KWNOOVER' specifies that each context does not overlap, `$qry-E<gt>KWPULEAD' specifies that the lead string is picked up forcibly. If it is not defined, no option is specified.
E<10>The return value is the reference to an array of strings around keywords.
=back
=head2 Tying functions of TokyoCabinet::TDB
=over
=item tieZ<>(%hash, E<quot>TokyoCabinet::TDBE<quot>, I<path>, I<omode>, I<bnum>, I<apow>, I<fpow>, I<opts>, I<rcnum>, I<lcnum>, I<ncnum>)
E<10>Tie a hash variable to a table database file.
E<10>`I<path>' specifies the path of the database file.
E<10>`I<omode>' specifies the connection mode: `TokyoCabinet::TDB::OWRITER' as a writer, `TokyoCabinet::TDB::OREADER' as a reader. If the mode is `TokyoCabinet::TDB::OWRITER', the following may be added by bitwise-or: `TokyoCabinet::TDB::OCREAT', which means it creates a new database if not exist, `TokyoCabinet::TDB::OTRUNC', which means it creates a new database regardless if one exists, `TokyoCabinet::TDB::OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `TokyoCabinet::TDB::OREADER' and `TokyoCabinet::TDB::OWRITER' can be added to by bitwise-or: `TokyoCabinet::TDB::ONOLCK', which means it opens the database file without file locking, or `TokyoCabinet::TDB::OLCKNB', which means locking is performed without blocking. If it is not defined, `TokyoCabinet::TDB::OREADER' is specified.
E<10>`I<bnum>' specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 131071. Suggested size of the bucket array is about from 0.5 to 4 times of the number of all records to be stored.
E<10>`I<apow>' specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^4=16.
E<10>`I<fpow>' specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.
E<10>`I<opts>' specifies options by bitwise-or: `TokyoCabinet::TDB::TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::TDB::TDEFLATE' specifies that each record is compressed with Deflate encoding, `TokyoCabinet::TDB::TBZIP' specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::TDB::TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.
E<10>`I<rcnum>' specifies the maximum number of records to be cached. If it is not defined or not more than 0, the record cache is disabled. It is disabled by default.
E<10>`I<lcnum>' specifies the maximum number of leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 2048.
E<10>`I<ncnum>' specifies the maximum number of non-leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 512.
E<10>If successful, the return value is true, else, it is false.
=item untieZ<>(%hash)
E<10>Untie a hash variable from the database file.
E<10>The return value is always true.
=item $hash{I<pkey>} = I<cols>
E<10>Store a record.
E<10>`I<pkey>' specifies primary key.
E<10>`I<cols>' specifies the reference to a hash containing columns.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, it is overwritten.
=item delete($hash{I<pkey>})
E<10>Remove a record.
E<10>`I<pkey>' specifies primary key.
E<10>If successful, the return value is true, else, it is false.
=item $hash{I<pkey>}
E<10>Retrieve a record.
E<10>`I<pkey>' specifies primary key.
E<10>If successful, the return value is the reference to a hash of the columns of the corresponding record. `undef' is returned if no record corresponds.
=item exists($hash{I<pkey>})
E<10>Check whether a record corrsponding a key exists.
E<10>`I<pkey>' specifies primary key.
E<10>The return value is true if the record exists, else it is false.
=item $hash = Z<>()
E<10>Remove all records.
E<10>The return value is always `undef'.
=item Z<>(the iterator)
E<10>The inner methods `FIRSTKEY' and `NEXTKEY' are also implemented so that you can use the tying functions `each', `keys', and so on.
=back
=head2 Class TokyoCabinet::ADB
Abstract database is a set of interfaces to use on-memory hash database, on-memory tree database, hash database, B+ tree database, fixed-length database, and table database with the same API. Before operations to store or retrieve records, it is necessary to connect the abstract database object to the concrete one. The method `open' is used to open a concrete database and the method `close' is used to close the database. To avoid data missing or corruption, it is important to close every database instance when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.
=over
=item $adb = TokyoCabinet::ADB-E<gt>newZ<>()
E<10>Create an abstract database object.
E<10>The return value is the new abstract database object.
=item $adb-E<gt>openZ<>(I<name>)
E<10>Open a database.
E<10>`I<name>' specifies the name of the database. If it is "*", the database will be an on-memory hash database. If it is "+", the database will be an on-memory tree database. If its suffix is ".tch", the database will be a hash database. If its suffix is ".tcb", the database will be a B+ tree database. If its suffix is ".tcf", the database will be a fixed-length database. If its suffix is ".tct", the database will be a table database. Otherwise, this method fails. Tuning parameters can trail the name, separated by "#". Each parameter is composed of the name and the value, separated by "=". On-memory hash database supports "bnum", "capnum", and "capsiz". On-memory tree database supports "capnum" and "capsiz". Hash database supports "mode", "bnum", "apow", "fpow", "opts", "rcnum", and "xmsiz". B+ tree database supports "mode", "lmemb", "nmemb", "bnum", "apow", "fpow", "opts", "lcnum", "ncnum", and "xmsiz". Fixed-length database supports "mode", "width", and "limsiz". Table database supports "mode", "bnum", "apow", "fpow", "opts", "rcnum", "lcnum", "ncnum", "xmsiz", and "idx".
E<10>If successful, the return value is true, else, it is false.
E<10>The tuning parameter "capnum" specifies the capacity number of records. "capsiz" specifies the capacity size of using memory. Records spilled the capacity are removed by the storing order. "mode" can contain "w" of writer, "r" of reader, "c" of creating, "t" of truncating, "e" of no locking, and "f" of non-blocking lock. The default mode is relevant to "wc". "opts" can contains "l" of large option, "d" of Deflate option, "b" of BZIP2 option, and "t" of TCBS option. "idx" specifies the column name of an index and its type separated by ":". For example, "casket.tch#bnum=1000000#opts=ld" means that the name of the database file is "casket.tch", and the bucket number is 1000000, and the options are large and Deflate.
=item $adb-E<gt>closeZ<>()
E<10>Close the database.
E<10>If successful, the return value is true, else, it is false.
E<10>Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken.
=item $adb-E<gt>putZ<>(I<key>, I<value>)
E<10>Store a record.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, it is overwritten.
=item $adb-E<gt>putkeepZ<>(I<key>, I<value>)
E<10>Store a new record.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, this method has no effect.
=item $adb-E<gt>putcatZ<>(I<key>, I<value>)
E<10>Concatenate a value at the end of the existing record.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If there is no corresponding record, a new record is created.
=item $adb-E<gt>outZ<>(I<key>)
E<10>Remove a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is true, else, it is false.
=item $adb-E<gt>getZ<>(I<key>)
E<10>Retrieve a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is the value of the corresponding record. `undef' is returned if no record corresponds.
=item $adb-E<gt>vsizZ<>(I<key>)
E<10>Get the size of the value of a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is the size of the value of the corresponding record, else, it is -1.
=item $adb-E<gt>iterinitZ<>()
E<10>Initialize the iterator.
E<10>If successful, the return value is true, else, it is false.
E<10>The iterator is used in order to access the key of every record stored in a database.
=item $adb-E<gt>iternextZ<>()
E<10>Get the next key of the iterator.
E<10>If successful, the return value is the next key, else, it is `undef'. `undef' is returned when no record is to be get out of the iterator.
E<10>It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.
=item $adb-E<gt>fwmkeysZ<>(I<prefix>, I<max>)
E<10>Get forward matching keys.
E<10>`I<prefix>' specifies the prefix of the corresponding keys.
E<10>`I<max>' specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
E<10>The return value is the reference to an array of the keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.
E<10>Note that this method may be very slow because every key in the database is scanned.
=item $adb-E<gt>addintZ<>(I<key>, I<num>)
E<10>Add an integer to a record.
E<10>`I<key>' specifies the key.
E<10>`I<num>' specifies the additional value.
E<10>If successful, the return value is the summation value, else, it is `undef'.
E<10>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. Because records are stored in binary format, they should be processed with the `unpack' function with the `i' operator after retrieval.
=item $adb-E<gt>adddoubleZ<>(I<key>, I<num>)
E<10>Add a real number to a record.
E<10>`I<key>' specifies the key.
E<10>`I<num>' specifies the additional value.
E<10>If successful, the return value is the summation value, else, it is `undef'.
E<10>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. Because records are stored in binary format, they should be processed with the `unpack' function with the `d' operator after retrieval.
=item $adb-E<gt>syncZ<>()
E<10>Synchronize updated contents with the file and the device.
E<10>If successful, the return value is true, else, it is false.
=item $adb-E<gt>optimizeZ<>(I<params>)
E<10>Optimize the storage.
E<10>`I<params>' specifies the string of the tuning parameters, which works as with the tuning of parameters the method `open'. If it is not defined, it is not used.
E<10>If successful, the return value is true, else, it is false.
=item $adb-E<gt>vanishZ<>()
E<10>Remove all records.
E<10>If successful, the return value is true, else, it is false.
=item $adb-E<gt>copyZ<>(I<path>)
E<10>Copy the database file.
E<10>`I<path>' specifies the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.
E<10>If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.
E<10>The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.
=item $adb-E<gt>tranbeginZ<>()
E<10>Begin the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.
=item $adb-E<gt>trancommitZ<>()
E<10>Commit the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>Update in the transaction is fixed when it is committed successfully.
=item $adb-E<gt>tranabortZ<>()
E<10>Abort the transaction.
E<10>If successful, the return value is true, else, it is false.
E<10>Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.
=item $adb-E<gt>pathZ<>()
E<10>Get the path of the database file.
E<10>The return value is the path of the database file or `undef' if the object does not connect to any database instance. "*" stands for on-memory hash database. "+" stands for on-memory tree database.
=item $adb-E<gt>rnumZ<>()
E<10>Get the number of records.
E<10>The return value is the number of records or 0 if the object does not connect to any database instance.
=item $adb-E<gt>sizeZ<>()
E<10>Get the size of the database.
E<10>The return value is the size of the database file or 0 if the object does not connect to any database instance.
=item $adb-E<gt>miscZ<>(I<name>, I<args>)
E<10>Call a versatile function for miscellaneous operations.
E<10>`I<name>' specifies the name of the function.
E<10>`I<args>' specifies the reference to an array of arguments. If it is not defined, no argument is specified.
E<10>If successful, the return value is the reference to an array of the result. `undef' is returned on failure.
=back
=head2 Tying functions of TokyoCabinet::ADB
=over
=item tieZ<>(%hash, E<quot>TokyoCabinet::ADBE<quot>, I<name>)
E<10>Tie a hash variable to an abstract database instance.
E<10>`I<name>' specifies the name of the database. If it is "*", the database will be an on-memory hash database. If it is "+", the database will be an on-memory tree database. If its suffix is ".tch", the database will be a hash database. If its suffix is ".tcb", the database will be a B+ tree database. If its suffix is ".tcf", the database will be a fixed-length database. If its suffix is ".tct", the database will be a table database. Otherwise, this method fails. Tuning parameters can trail the name, separated by "#". Each parameter is composed of the name and the value, separated by "=". On-memory hash database supports "bnum", "capnum", and "capsiz". On-memory tree database supports "capnum" and "capsiz". Hash database supports "mode", "bnum", "apow", "fpow", "opts", "rcnum", and "xmsiz". B+ tree database supports "mode", "lmemb", "nmemb", "bnum", "apow", "fpow", "opts", "lcnum", "ncnum", and "xmsiz". Fixed-length database supports "mode", "width", and "limsiz". Table database supports "mode", "bnum", "apow", "fpow", "opts", "rcnum", "lcnum", "ncnum", "xmsiz", and "idx".
E<10>If successful, the return value is true, else, it is false.
=item untieZ<>(%hash)
E<10>Untie a hash variable from the database.
E<10>The return value is always true.
=item $hash{I<key>} = I<value>
E<10>Store a record.
E<10>`I<key>' specifies the key.
E<10>`I<value>' specifies the value.
E<10>If successful, the return value is true, else, it is false.
E<10>If a record with the same key exists in the database, it is overwritten.
=item delete($hash{I<key>})
E<10>Remove a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is true, else, it is false.
=item $hash{I<key>}
E<10>Retrieve a record.
E<10>`I<key>' specifies the key.
E<10>If successful, the return value is the value of the corresponding record. `undef' is returned if no record corresponds.
=item exists($hash{I<key>})
E<10>Check whether a record corrsponding a key exists.
E<10>`I<key>' specifies the key.
E<10>The return value is true if the record exists, else it is false.
=item $hash = Z<>()
E<10>Remove all records.
E<10>The return value is always `undef'.
=item Z<>(the iterator)
E<10>The inner methods `FIRSTKEY' and `NEXTKEY' are also implemented so that you can use the tying functions `each', `keys', and so on.
=back
=head1 LICENSE
Copyright (C) 2006-2010 FAL Labs
All rights reserved.
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.
|