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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
<TITLE>dets</TITLE>
<SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
<STYLE TYPE="text/css">
<!--
.REFBODY { margin-left: 13mm }
.REFTYPES { margin-left: 8mm }
-->
</STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<!-- refpage -->
<CENTER>
<A HREF="http://www.erlang.se">
<IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif">
</A>
<H1>dets</H1>
</CENTER>
<H3>MODULE</H3>
<DIV CLASS=REFBODY>
dets
</DIV>
<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
A Disk Based Term Storage
</DIV>
<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>
<P>The module <CODE>dets</CODE> provides a term storage on file. The
stored terms, in this module called <STRONG>objects</STRONG>, are tuples
such that one element is defined to be the key. A Dets
<STRONG>table</STRONG> is a collection of objects with the key at the same
position stored on a file.
<P>Dets is used by the Mnesia application, and is provided as is
for users who are interested in an efficient storage of Erlang
terms on disk only. Many applications just need to store some
terms in a file. Mnesia adds transactions, queries, and
distribution. The size of Dets files cannot exceed 2 GB. If larger
tables are needed, Mnesia's table fragmentation can be used.
<P>There are three types of Dets tables: set, bag and
duplicate_bag. A table of type <STRONG>set</STRONG> has at most one object
with a given key. If an object with a key already present in the
table is inserted, the existing object is overwritten by the new
object. A table of type <STRONG>bag</STRONG> has zero or more different
objects with a given key. A table of type <STRONG>duplicate_bag</STRONG>
has zero or more possibly equal objects with a given key.
<P>Dets tables must be opened before they can be updated or read,
and when finished they must be properly closed. If a table has not
been properly closed, Dets will automatically repair the table.
This can take a substantial time if the table is large. A Dets
table is closed when the process which opened the table
terminates. If several Erlang processes (users) open the same Dets
table, they will share the table. The table is properly closed
when all users have either terminated or closed the table. Dets
tables are not properly closed if the Erlang runtime system is
terminated abnormally.
<P>
<TABLE CELLPADDING=4>
<TR>
<TD VALIGN=TOP><IMG ALT="Note!" SRC="note.gif"></TD>
<TD>
<P>A ^C command abnormally terminates an Erlang runtime
system in a Unix environment with a break-handler. </TD>
</TR>
</TABLE>
<P>Since all operations performed by Dets are disk operations, it
is important to realize that a single look-up operation involves a
series of disk seek and read operations. For this reason, the Dets
functions are much slower than the corresponding Ets functions,
although Dets exports a similar interface.
<P>Dets organizes data as a linear hash list and the hash list
grows gracefully as more data is inserted into the table. Space
management on the file is performed by what is called a buddy
system. The current implementation keeps the entire buddy system
in RAM, which implies that if the table gets heavily fragmented,
quite some memory can be used up. The only way to defragment a
table is to close it and then open it again with the <CODE>repair</CODE>
option set to <CODE>force</CODE>.
<P>It is worth noting that the ordered_set type present in Ets is
not yet implemented by Dets, neither is the limited support for
concurrent updates which makes a sequence of <CODE>first</CODE> and
<CODE>next</CODE> calls safe to use on fixed Ets tables. Both these
features will be implemented by Dets in a future release of
Erlang/OTP. Until then, the Mnesia application (or some user
implemented method for locking) has to be used to implement safe
concurrency. Currently, no library of Erlang/OTP has support for
ordered disk based term storage.
<P>Two versions of the format used for storing objects on file are
supported by Dets. The first version, 8, is the format always used
for tables created by OTP R7 and earlier. The second version, 9,
is the default version of tables created by OTP R8 (and later OTP
releases). OTP R8 can create version 8 tables, and convert version
8 tables to version 9, and vice versa, upon request.
<P>All Dets functions return <CODE>{error, Reason}</CODE> if an error
occurs (<CODE>first/1</CODE> and <CODE>next/2</CODE> are exceptions, they exit
the process with the error tuple). If given badly formed
arguments, all functions exit the process with a <CODE>badarg</CODE>
message.
<P><STRONG>Types</STRONG>
<PRE>
access() = read | read_write
auto_save() = infinity | int()
bindings_cont() = tuple()
bool() = true | false
file() = string()
int() = integer() >= 0
keypos() = integer() >= 1
name() = atom() | ref()
no_slots() = integer() >= 0 | default
object() = tuple()
object_cont() = tuple()
select_cont() = tuple()
type() = bag | duplicate_bag | set
version() = 8 | 9 | default
</PRE>
</DIV>
<H3>EXPORTS</H3>
<P><A NAME="all/0"><STRONG><CODE>all() -> [Name]</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns a list of the names of all open tables on this
node.
</DIV>
<P><A NAME="bchunk/2"><STRONG><CODE>bchunk(Name, Continuation) -> {Continuation2, Data}
| '$end_of_table' | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Continuation = start | cont()</CODE></STRONG><BR>
<STRONG><CODE>Continuation2 = cont()</CODE></STRONG><BR>
<STRONG><CODE>Data = binary() | tuple()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns a list of objects stored in a table. The exact
representation of the returned objects is not public. The
lists of data can be used for initializing a table by giving
the value <CODE>bchunk</CODE> to the <CODE>format</CODE> option of the
<CODE>init_table/3</CODE> function. The Mnesia application uses this
function for copying open tables.
<P>Unless the table is protected using <CODE>safe_fixtable/2</CODE>,
calls to <CODE>bchunk/2</CODE> may not work as expected if
concurrent updates are made to the table.
<P>The first time <CODE>bchunk/2</CODE> is called, an initial
continuation, the atom <CODE>start</CODE>, must be provided.
<P>The <CODE>bchunk/2</CODE> function returns a tuple
<CODE>{Continuation2, Data}</CODE>, where <CODE>Data</CODE> is a list of
objects. <CODE>Continuation2</CODE> is another continuation which is
to be passed on to a subsequent call to <CODE>bchunk/2</CODE>. With
a series of calls to <CODE>bchunk/2</CODE> it is possible to extract
all objects of the table.
<P><CODE>bchunk/2</CODE> returns <CODE>'$end_of_table'</CODE> when all
objects have been returned, or <CODE>{error, Reason}</CODE> if an
error occurs.
</DIV>
<P><A NAME="close/1"><STRONG><CODE>close(Name) -> ok | {error, Reason} </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Closes a table. Only processes that have opened a table are
allowed to close it.
<P>All open tables must be closed before the system is
stopped. If an attempt is made to open a table which has not
been properly closed, Dets automatically tries to repair the
table.
</DIV>
<P><A NAME="delete/2"><STRONG><CODE>delete(Name, Key) -> ok | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Deletes all objects with the key <CODE>Key</CODE> from the table
<CODE>Name</CODE>.
</DIV>
<P><A NAME="delete_all_objects/1"><STRONG><CODE>delete_all_objects(Name) -> ok | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Deletes all objects from a table in almost constant time.
However, if the table if fixed, <CODE>delete_all_objects(T)</CODE>
is equivalent to <CODE>match_delete(T, '_')</CODE>.
</DIV>
<P><A NAME="delete_object/2"><STRONG><CODE>delete_object(Name, Object) -> ok | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Object = object()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Deletes all instances of a given object from a table. If a
table is of type <CODE>bag</CODE> or <CODE>duplicate_bag</CODE>, the
<CODE>delete/2</CODE> function cannot be used to delete only some of
the objects with a given key. This function makes this
possible.
</DIV>
<P><A NAME="first/1"><STRONG><CODE>first(Name) -> Key | '$end_of_table'</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns the first key stored in the table <CODE>Name</CODE>
according to the table's internal order, or
<CODE>'$end_of_table'</CODE> if the table is empty.
<P>Unless the table is protected using <CODE>safe_fixtable/2</CODE>,
subsequent calls to <CODE>next/2</CODE> may not work as expected if
concurrent updates are made to the table.
<P>Should an error occur, the process is exited with an error
tuple <CODE>{error, Reason}</CODE>. The reason for not returning the
error tuple is that it cannot be distinguished from a key.
<P>There are two reasons why <CODE>first/1</CODE> and <CODE>next/2</CODE>
should not be used: they are not very efficient, and they
prevent the use of the key <CODE>'$end_of_table'</CODE> since this
atom is used to indicate the end of the table. If possible,
the <CODE>match</CODE>, <CODE>match_object</CODE>, and <CODE>select</CODE>
functions should be used for traversing tables.
</DIV>
<P><A NAME="foldl/3"><STRONG><CODE>foldl(Function, Acc0, Name) -> Acc1 | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Function = fun(Object, AccIn) -> AccOut</CODE></STRONG><BR>
<STRONG><CODE>Acc0 = Acc1 = AccIn = AccOut = term()</CODE></STRONG><BR>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Object = object()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Calls <CODE>Function</CODE> on successive elements of the table
<CODE>Name</CODE> together with an extra argument <CODE>AccIn</CODE>. The
order in which the elements of the table are traversed is
unspecified. <CODE>Function</CODE> must return a new accumulator
which is passed to the next call. <CODE>Acc0</CODE> is returned if
the table is empty.
</DIV>
<P><A NAME="foldr/3"><STRONG><CODE>foldr(Function, Acc0, Name) -> Acc1 | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Function = fun(Object, AccIn) -> AccOut</CODE></STRONG><BR>
<STRONG><CODE>Acc0 = Acc1 = AccIn = AccOut = term()</CODE></STRONG><BR>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Object = object()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Calls <CODE>Function</CODE> on successive elements of the table
<CODE>Name</CODE> together with an extra argument <CODE>AccIn</CODE>. The
order in which the elements of the table are traversed is
unspecified. <CODE>Function</CODE> must return a new accumulator
which is passed to the next call. <CODE>Acc0</CODE> is returned if
the table is empty.
</DIV>
<P><A NAME="from_ets/2"><STRONG><CODE>from_ets(Name, EtsTab) -> ok | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>EtsTab = -see ets(3)-
</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Deletes all objects of the table <CODE>Name</CODE> and then
inserts all the objects of the Ets table <CODE>EtsTab</CODE>. The
order in which the objects are inserted is not specified.
Since <CODE>ets:safe_fixtable/2</CODE> is called the Ets table must
be public or owned by the calling process.
</DIV>
<P><A NAME="info/1"><STRONG><CODE>info(Name) -> InfoList | undefined</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>InfoList = [{Item, Value}]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns information about the table <CODE>Name</CODE> as a list of
<CODE>{Item, Value}</CODE> tuples:
<P>
<UL>
<LI>
<CODE>{file_size, int()}</CODE>, the size of the file in
bytes.<BR>
</LI>
<LI>
<CODE>{filename, file()}</CODE>, the name of the file
where objects are stored.<BR>
</LI>
<LI>
<CODE>{keypos, keypos()}</CODE>, the position of the
key.<BR>
</LI>
<LI>
<CODE>{size, int()}</CODE>, the number of objects stored
in the table.<BR>
</LI>
<LI>
<CODE>{type, type()}</CODE>, the type of the table.<BR>
</LI>
</UL>
</DIV>
<P><A NAME="info/2"><STRONG><CODE>info(Name, Item) -> Value | undefined</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns the information associated with <CODE>Item</CODE> for the
table <CODE>Name</CODE>. In addition to the <CODE>{Item, Value}</CODE>
pairs defined for <CODE>info/1</CODE>, the following items are
allowed:
<P>
<UL>
<LI>
<CODE>{access, access()}</CODE>, the access mode.<BR>
</LI>
<LI>
<CODE>{auto_save, auto_save()}</CODE>, the auto save
interval.<BR>
</LI>
<LI>
<CODE>{bchunk_format, binary()}</CODE>, an opaque binary
describing the format of the objects returned by
<CODE>bchunk/2</CODE>. The binary can be used as argument to
<CODE>is_compatible_chunk_format/2</CODE>. Only available for
version 9 tables.<BR>
</LI>
<LI>
<CODE>{hash,</CODE> Hash<CODE>}</CODE>. Describes which BIF is
used to calculate the hash values of the objects stored in
the Dets table. Possible values of Hash are <CODE>hash</CODE>,
which implies that the <CODE>erlang:hash/2</CODE> BIF is used,
<CODE>phash</CODE>, which implies that the <CODE>erlang:phash/2</CODE>
BIF is used, and <CODE>phash2</CODE>, which implies that the
<CODE>erlang:phash2/1</CODE> BIF is used.<BR>
</LI>
<LI>
<CODE>{memory, int()}</CODE>, the size of the file in
bytes. The same value is associated with the item
<CODE>file_size</CODE>.<BR>
</LI>
<LI>
<CODE>{no_keys, int()}</CODE>, the number of different
keys stored in the table. Only available for version 9
tables.<BR>
</LI>
<LI>
<CODE>{no_objects, int()}</CODE>, the number of objects
stored in the table.<BR>
</LI>
<LI>
<CODE>{no_slots, {Min, Used, Max}}</CODE>, the number of
slots of the table. <CODE>Min</CODE> is the minimum number of
slots, <CODE>Used</CODE> is the number of currently used slots,
and <CODE>Max</CODE> is the maximum number of slots. Only
available for version 9 tables.<BR>
</LI>
<LI>
<CODE>{owner, pid()}</CODE>, the pid of the process that
handles requests to the Dets table.<BR>
</LI>
<LI>
<CODE>{ram_file, bool()}</CODE>, whether the table is
kept in RAM.<BR>
</LI>
<LI>
<CODE>{safe_fixed,</CODE> SafeFixed<CODE>}</CODE>. If the table
is fixed, SafeFixed is a tuple <CODE>{FixedAtTime,
[{Pid,RefCount}]}</CODE>. <CODE>FixedAtTime</CODE> is the time when
the table was first fixed, and <CODE>Pid</CODE> is the pid of
the process that fixes the table <CODE>RefCount</CODE> times.
There may be any number of processes in the list. If the
table is not fixed, SafeFixed is the atom <CODE>false</CODE>.<BR>
</LI>
<LI>
<CODE>{version, int()}</CODE>, the version of the format
of the table.<BR>
</LI>
</UL>
</DIV>
<P><A NAME="init_table/3"><STRONG><CODE>init_table(Name, InitFun [, Options]) -> ok
| {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = atom()</CODE></STRONG><BR>
<STRONG><CODE>InitFun = fun(Arg) -> Res</CODE></STRONG><BR>
<STRONG><CODE>Arg = read | close</CODE></STRONG><BR>
<STRONG><CODE>Res = end_of_input | {[object()], InitFun} | {Data, InitFun}
| term()</CODE></STRONG><BR>
<STRONG><CODE>Data = binary() | tuple()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Replaces the existing objects of the table <CODE>Name</CODE> with
objects created by calling the input function <CODE>InitFun</CODE>,
see below. The reason for using this function rather than
calling <CODE>insert/2</CODE> is that of efficiency. It should be
noted that the input functions are called by the process that
handles requests to the Dets table, not by the calling
process.
<P>When called with the argument <CODE>read</CODE> the function
<CODE>InitFun</CODE> is assumed to return <CODE>end_of_input</CODE> when
there is no more input, or <CODE>{Objects, Fun}</CODE>, where
<CODE>Objects</CODE> is a list of objects and <CODE>Fun</CODE> is a new
input function. Any other value Value is returned as an error
<CODE>{error, {init_fun, Value}}</CODE>. Each input function will be
called exactly once, and should an error occur, the last
function is called with the argument <CODE>close</CODE>, the reply
of which is ignored.
<P>If the type of the table is <CODE>set</CODE> and there is more
than one object with a given key, one of the objects is
chosen. This is not necessarily the last object with the given
key in the sequence of objects returned by the input
functions. Extra objects should be avoided, or the file will
be unnecessarily fragmented. This holds also for duplicated
objects stored in tables of type <CODE>duplicate_bag</CODE>.
<P>It is important that the table has a sufficient number of
slots for the objects. If not, the hash list will start to
grow when <CODE>init_table/2</CODE> returns which will significantly
slow down access to the table for a period of time. The
minimum number of slots is set by the <CODE>open_file/2</CODE>
option <CODE>min_no_slots</CODE> and returned by the <CODE>info/2</CODE>
item <CODE>no_slots</CODE>. See also the <CODE>min_no_slots</CODE> option
below.
<P>The <CODE>Options</CODE> argument is a list of <CODE>{Key, Val}</CODE>
tuples where the following values are allowed:
<P>
<UL>
<LI>
<CODE>{min_no_slots, no_slots()}</CODE>. Specifies the
estimated number of different keys that will be stored
in the table. The <CODE>open_file</CODE> option with the same
name is ignored unless the table is created, and in that
case performance can be enhanced by supplying an
estimate when initializing the table.<BR>
</LI>
<LI>
<CODE>{format, Format}</CODE>. Specifies the format of the
objects returned by the function <CODE>InitFun</CODE>. If
<CODE>Format</CODE> is <CODE>term</CODE> (the default),
<CODE>InitFun</CODE> is assumed to return a list of tuples. If
<CODE>Format</CODE> is <CODE>bchunk</CODE>, <CODE>InitFun</CODE> is
assumed to return <CODE>Data</CODE> as returned by
<CODE>bchunk/2</CODE>. This option overrides the
<CODE>min_no_slots</CODE> option.<BR>
</LI>
</UL>
</DIV>
<P><A NAME="insert/2"><STRONG><CODE>insert(Name, Objects) -> ok | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Objects = object() | [object()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Inserts one or more objects into the table <CODE>Name</CODE>. If
there already exists an object with the same key as some of
the given objects and the table type is <CODE>set</CODE>, the old
object will be replaced.
</DIV>
<P><A NAME="insert_new/2"><STRONG><CODE>insert_new(Name, Objects) -> Bool</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Objects = object() | [object()]</CODE></STRONG><BR>
<STRONG><CODE>Bool = bool()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Inserts one or more objects into the table <CODE>Name</CODE>. If
there already exists an object with the same key as some of
the given objects the table is not updated and <CODE>false</CODE> is
returned, otherwise the objects are inserted and <CODE>true</CODE>
returned.
</DIV>
<P><A NAME="is_compatible_bchunk_format/2"><STRONG><CODE>is_compatible_bchunk_format(Name, BchunkFormat) -> Bool</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>BchunkFormat = binary()</CODE></STRONG><BR>
<STRONG><CODE>Bool = bool()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns <CODE>true</CODE> if it would be possible to initialize
the table <CODE>Name</CODE>, using <CODE>init_table/3</CODE> with the
option <CODE>{format,bchunk}</CODE>, with objects read with
<CODE>bchunk/2</CODE> from some table <CODE>T</CODE> such that calling
<CODE>info(T,bchunk_format)</CODE> returns
<CODE>BchunkFormat</CODE>.
</DIV>
<P><A NAME="is_dets_file/1"><STRONG><CODE>is_dets_file(FileName) -> Bool | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>FileName = file()</CODE></STRONG><BR>
<STRONG><CODE>Bool = bool()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns <CODE>true</CODE> if the file <CODE>FileName</CODE> is a Dets
table, <CODE>false</CODE> otherwise.
</DIV>
<P><A NAME="lookup/2"><STRONG><CODE>lookup(Name, Key) -> [Object] | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Object = object()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns a list of all objects with the key <CODE>Key</CODE>
stored in the table <CODE>Name</CODE>. For example:
<PRE>
2> <STRONG>dets:open_file(abc, [{type, bag}]).</STRONG>
{ok,abc}
3> <STRONG>dets:insert(abc, {1,2,3}).</STRONG>
ok
4> <STRONG>dets:insert(abc, {1,3,4}).</STRONG>
ok
5> <STRONG>dets:lookup(abc, 1).</STRONG>
[{1,2,3},{1,3,4}]
</PRE>
<P>If the table is of type <CODE>set</CODE>, the function returns
either the empty list or a list with one object, as there
cannot be more than one object with a given key. If the table
is of type <CODE>bag</CODE> or <CODE>duplicate_bag</CODE>, the function
returns a list of arbitrary length.
<P>Note that the order of objects returned is unspecified. In
particular, the order in which objects were inserted is not
reflected.
</DIV>
<P><A NAME="match/1"><STRONG><CODE>match(Continuation) -> {[Match], Continuation2} | '$end_of_table'
| {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Continuation = Continuation2 = bindings_cont()</CODE></STRONG><BR>
<STRONG><CODE>Match = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Matches some objects stored in a table and returns a list
of the bindings that match a given pattern in some unspecified
order. The table, the pattern, and the number of objects that
are matched are all defined by <CODE>Continuation</CODE>, which has
been returned by a prior call to <CODE>match/1</CODE> or
<CODE>match/3</CODE>.
<P>When all objects of the table have been matched,
<CODE>'$end_of_table'</CODE> is returned.
</DIV>
<P><A NAME="match/2"><STRONG><CODE>match(Name, Pattern) -> [Match] | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Pattern = tuple()</CODE></STRONG><BR>
<STRONG><CODE>Match = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns for each object of the table <CODE>Name</CODE> that
matches <CODE>Pattern</CODE> a list of bindings in some unspecified
order. See <A HREF="ets.html">ets(3)</A> for a
description of patterns. If the keypos'th element of
<CODE>Pattern</CODE> is unbound, all objects of the table are
matched. If the keypos'th element is bound, only the
objects with the right key are matched.
</DIV>
<P><A NAME="match/3"><STRONG><CODE>match(Name, Pattern, N) -> {[Match], Continuation}
| '$end_of_table' | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Pattern = tuple()</CODE></STRONG><BR>
<STRONG><CODE>N = default | int()</CODE></STRONG><BR>
<STRONG><CODE>Match = [term()]</CODE></STRONG><BR>
<STRONG><CODE>Continuation = bindings_cont()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Matches some or all objects of the table <CODE>Name</CODE> and
returns a list of the bindings that match <CODE>Pattern</CODE> in
some unspecified order. See <A HREF="ets.html">ets(3)</A> for a description of
patterns.
<P>A tuple of the bindings and a continuation is returned,
unless the table is empty, in which case
<CODE>'$end_of_table'</CODE> is returned. The continuation is to be
used when matching further objects by calling
<CODE>match/1</CODE>.
<P>If the keypos'th element of <CODE>Pattern</CODE> is bound,
all objects of the table are matched. If the keypos'th
element is unbound, all objects of the table are matched,
<CODE>N</CODE> objects at a time. The default, indicated by giving
<CODE>N</CODE> the value <CODE>default</CODE>, is to let the number of
objects vary depending on the sizes of the objects. If
<CODE>Name</CODE> is a version 9 table, all objects with the same
key are always matched at the same time which implies that
more than N objects may sometimes be matched.
<P>The table should always be protected using
<CODE>safe_fixtable/2</CODE> before calling <CODE>match/3</CODE>, or
errors may occur when calling <CODE>match/1</CODE>.
</DIV>
<P><A NAME="match_delete/2"><STRONG><CODE>match_delete(Name, Pattern) -> N | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>N = int()</CODE></STRONG><BR>
<STRONG><CODE>Pattern = tuple()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Deletes all objects that match <CODE>Pattern</CODE> from the
table <CODE>Name</CODE>, and returns the number of deleted
objects. See <A HREF="ets.html">ets(3)</A> for a
description of patterns.
<P>If the keypos'th element of <CODE>Pattern</CODE> is bound,
only the objects with the right key are matched.
</DIV>
<P><A NAME="match_object/1"><STRONG><CODE>match_object(Continuation) -> {[Object], Continuation2}
| '$end_of_table' | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Continuation = Continuation2 = object_cont()</CODE></STRONG><BR>
<STRONG><CODE>Object = object()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns a list of some objects stored in a table that match
a given pattern in some unspecified order. The table, the
pattern, and the number of objects that are matched are all
defined by <CODE>Continuation</CODE>, which has been returned by a
prior call to <CODE>match_object/1</CODE> or
<CODE>match_object/3</CODE>.
<P>When all objects of the table have been matched,
<CODE>'$end_of_table'</CODE> is returned.
</DIV>
<P><A NAME="match_object/2"><STRONG><CODE>match_object(Name, Pattern) -> [Object] | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Pattern = tuple()</CODE></STRONG><BR>
<STRONG><CODE>Object = object()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns a list of all objects of the table <CODE>Name</CODE> that
match <CODE>Pattern</CODE> in some unspecified order. See <A HREF="ets.html">ets(3)</A> for a description of patterns.
<P>If the keypos'th element of <CODE>Pattern</CODE> is
unbound, all objects of the table are matched. If the
keypos'th element of <CODE>Pattern</CODE> is bound, only the
objects with the right key are matched.
<P>Using the <CODE>match_object</CODE> functions for traversing all
objects of a table is more efficient than calling
<CODE>first/1</CODE> and <CODE>next/2</CODE> or <CODE>slot/2</CODE>.
</DIV>
<P><A NAME="match_object/3"><STRONG><CODE>match_object(Name, Pattern, N) -> {[Object], Continuation}
| '$end_of_table' | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Pattern = tuple()</CODE></STRONG><BR>
<STRONG><CODE>N = default | int()</CODE></STRONG><BR>
<STRONG><CODE>Object = object()</CODE></STRONG><BR>
<STRONG><CODE>Continuation = object_cont()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Matches some or all objects stored in the table <CODE>Name</CODE>
and returns a list of the objects that match <CODE>Pattern</CODE> in
some unspecified order. See <A HREF="ets.html">ets(3)</A> for a description of
patterns.
<P>A list of objects and a continuation is returned, unless
the table is empty, in which case <CODE>'$end_of_table'</CODE>
is returned. The continuation is to be used when matching
further objects by calling <CODE>match_object/1</CODE>.
<P>If the keypos'th element of <CODE>Pattern</CODE> is bound,
all objects of the table are matched. If the keypos'th
element is unbound, all objects of the table are matched,
<CODE>N</CODE> objects at a time. The default, indicated by giving
<CODE>N</CODE> the value <CODE>default</CODE>, is to let the number of
objects vary depending on the sizes of the objects. If
<CODE>Name</CODE> is a version 9 table, all matching objects with
the same key are always returned in the same reply which
implies that more than N objects may sometimes be returned.
<P>The table should always be protected using
<CODE>safe_fixtable/2</CODE> before calling <CODE>match_object/3</CODE>,
or errors may occur when calling <CODE>match_object/1</CODE>.
</DIV>
<P><A NAME="member/2"><STRONG><CODE>member(Name, Key) -> Bool | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>Bool = bool()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Works like <CODE>lookup/2</CODE>, but does not return the
objects. The function returns <CODE>true</CODE> if one or more
elements of the table has the key <CODE>Key</CODE>, <CODE>false</CODE>
otherwise.
</DIV>
<P><A NAME="next/2"><STRONG><CODE>next(Name, Key1) -> Key2 | '$end_of_table'</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Key1 = Key2 = term()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns the key following <CODE>Key1</CODE> in the table
<CODE>Name</CODE> according to the table's internal order, or
<CODE>'$end_of_table'</CODE> if there is no next key.
<P>Should an error occur, the process is exited with an error
tuple <CODE>{error, Reason}</CODE>.
<P>Use <CODE>first/1</CODE> to find the first key in the table.
</DIV>
<P><A NAME="open_file/1"><STRONG><CODE>open_file(Filename) -> {ok, Reference} | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>FileName = file()</CODE></STRONG><BR>
<STRONG><CODE>Reference = ref()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Opens an existing table. If the table has not been properly
closed, the error <CODE>{error, need_repair}</CODE> is returned. The
returned reference is to be used as the name of the table.
This function is most useful for debugging purposes.
</DIV>
<P><A NAME="open_file/2"><STRONG><CODE>open_file(Name, Args) -> {ok, Name} | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = atom()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Opens a table. An empty Dets table is created if no file
exists.
<P>The atom <CODE>Name</CODE> is the name of the table. The table
name must be provided in all subsequent operations on the
table. The name can be used by other processes as well, and
several process can share one table.
<P>If two processes open the same table by giving the same
name and arguments, then the table will have two users. If one
user closes the table, it still remains open until the second
user closes the table.
<P>The <CODE>Args</CODE> argument is a list of <CODE>{Key, Val}</CODE>
tuples where the following values are allowed:
<P>
<UL>
<LI>
<CODE>{access, access()}</CODE>. It is possible to open
existing tables in read-only mode. A table which is opened
in read-only mode is not subjected to the automatic file
reparation algorithm if it is later opened after a crash.
The default value is <CODE>read_write</CODE>.<BR>
</LI>
<LI>
<CODE>{auto_save, auto_save()}</CODE>, the auto save
interval. If the interval is an integer <CODE>Time</CODE>, the
table is flushed to disk whenever it is not accessed for
<CODE>Time</CODE> milliseconds. A table that has been flushed
will require no reparation when reopened after an
uncontrolled emulator halt. If the interval is the atom
<CODE>infinity</CODE>, auto save is disabled. The default value
is 180000 (3 minutes).<BR>
</LI>
<LI>
<CODE>{estimated_no_objects, int()}</CODE>. Equivalent to the
<CODE>min_no_slots</CODE> option.
<BR>
</LI>
<LI>
<CODE>{file, file()}</CODE>, the name of the file to be
opened. The default value is the name of the table.<BR>
</LI>
<LI>
<CODE>{max_no_slots, no_slots()}</CODE>, the maximum number
of slots that will be used. The default value is 2 M, and
the maximal value is 32 M. Note that a higher value may
increase the fragmentation of the table, and conversely,
that a smaller value may decrease the fragmentation, at
the expense of execution time. Only available for version
9 tables.<BR>
</LI>
<LI>
<CODE>{min_no_slots, no_slots()}</CODE>. Application
performance can be enhanced with this flag by specifying,
when the table is created, the estimated number of
different keys that will be stored in the table. The
default value as well as the minimum value is 256.<BR>
</LI>
<LI>
<CODE>{keypos, keypos()}</CODE>, the position of the
element of each object to be used as key. The default
value is 1. The ability to explicitly state the key
position is most convenient when we want to store Erlang
records in which the first position of the record is the
name of the record type.<BR>
</LI>
<LI>
<CODE>{ram_file, bool()}</CODE>, whether the table is to
be kept in RAM. Keeping the table in RAM may sound like an
anomaly, but can enhance the performance of applications
which open a table, insert a set of objects, and then
close the table. When the table is closed, its contents
are written to the disk file. The default value is
<CODE>false</CODE>.<BR>
</LI>
<LI>
<CODE>{repair, Value}</CODE>. <CODE>Value</CODE> can be either
a <CODE>bool()</CODE> or the atom <CODE>force</CODE>. The flag
specifies whether the Dets server should invoke the
automatic file reparation algorithm. The default is
<CODE>true</CODE>. If <CODE>false</CODE> is specified, there is no
attempt to repair the file and <CODE>{error, need_repair}</CODE>
is returned if the table needs to be repaired.<BR>
The value <CODE>force</CODE> means that a reparation will
take place even if the table has been properly closed.
This is how to convert tables created by older versions of
STDLIB. An example is tables hashed with the deprecated
<CODE>erlang:hash/2</CODE> BIF. Tables created with Dets from a
STDLIB version of 1.8.2 and later use the
<CODE>erlang:phash/2</CODE> function or the
<CODE>erlang:phash2/1</CODE> function, which is preferred.<BR>
The <CODE>repair</CODE> option is ignored if the table is
already open.
<BR>
</LI>
<LI>
<CODE>{type, type()}</CODE>, the type of the table. The
default value is <CODE>set</CODE>.<BR>
</LI>
<LI>
<CODE>{version, version()}</CODE>, the version of the format
used for the table. The default value is <CODE>9</CODE>. Tables
on the format used before OTP R8 can be created by giving
the value <CODE>8</CODE>. A version 8 table can be converted to
a version 9 table by giving the options <CODE>{version,9}</CODE>
and <CODE>{repair,force}</CODE>.<BR>
</LI>
</UL>
</DIV>
<P><A NAME="pid2name/1"><STRONG><CODE>pid2name(Pid) -> {ok, Name} | undefined</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns the name of the table given the pid of a process
that handles requests to a table, or <CODE>undefined</CODE> if
there is no such table.
<P>This function is meant to be used for debugging only.
</DIV>
<P><A NAME="repair_continuation/2"><STRONG><CODE>repair_continuation(Continuation, MatchSpec) -> Continuation2</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Continuation = Continuation2 = select_cont()</CODE></STRONG><BR>
<STRONG><CODE>MatchSpec = match_spec()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>This function can be used to restore an opaque continuation
returned by <CODE>select/3</CODE> or <CODE>select/1</CODE> if the
continuation has passed through external term format (been
sent between nodes or stored on disk).
<P>The reason for this function is that continuation terms
contain compiled match specifications and therefore will be
invalidated if converted to external term format. Given that
the original match specification is kept intact, the
continuation can be restored, meaning it can once again be
used in subsequent <CODE>select/1</CODE> calls even though it has
been stored on disk or on another node.
<P>See also <CODE>ets(3)</CODE> for further explanations and
examples.
<P>
<TABLE CELLPADDING=4>
<TR>
<TD VALIGN=TOP><IMG ALT="Note!" SRC="note.gif"></TD>
<TD>
<P>This function is very rarely needed in application code. It
is used by Mnesia to implement distributed <CODE>select/3</CODE>
and <CODE>select/1</CODE> sequences. A normal application would
either use Mnesia or keep the continuation from being
converted to external format.
<P>The reason for not having an external representation of
compiled match specifications is performance. It may be
subject to change in future releases, while this interface
will remain for backward compatibility. </TD>
</TR>
</TABLE>
</DIV>
<P><A NAME="safe_fixtable/2"><STRONG><CODE>safe_fixtable(Name, Fix)</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Fix = bool()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>If <CODE>Fix</CODE> is <CODE>true</CODE>, the table <CODE>Name</CODE> is
fixed (once more) by the calling process, otherwise the table
is released. The table is also released when a fixing process
terminates.
<P>If several processes fix a table, the table will remain
fixed until all processes have released it or terminated. A
reference counter is kept on a per process basis, and N
consecutive fixes require N releases to release the table.
<P>It is not guaranteed that calls to <CODE>first/1</CODE>,
<CODE>next/2</CODE>, select and match functions work as expected
even if the table has been fixed; the limited support for
concurrency implemented in Ets has not yet been implementeded
in Dets. Fixing a table currently only disables resizing of
the hash list of the table.
<P>If objects have been added while the table was fixed, the
hash list will start to grow when the table is released which
will significantly slow down access to the table for a period
of time.
</DIV>
<P><A NAME="select/1"><STRONG><CODE>select(Continuation) -> {Selection, Continuation2}
| '$end_of_table' | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Continuation = Continuation2 = select_cont()</CODE></STRONG><BR>
<STRONG><CODE>Selection = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns the results of applying a match specification to
some objects stored in a table. The table, the match
specification, and the number of objects that are matched
are all defined by <CODE>Continuation</CODE>, which has been
returned by a prior call to <CODE>select/1</CODE> or
<CODE>select/3</CODE>.
<P>When all objects of the table have been matched,
<CODE>'$end_of_table'</CODE> is returned.
</DIV>
<P><A NAME="select/2"><STRONG><CODE>select(Name, MatchSpec) -> Selection | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>MatchSpec = match_spec()</CODE></STRONG><BR>
<STRONG><CODE>Selection = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns the results of applying the match specification
<CODE>MatchSpec</CODE> to all or some objects stored in the table
<CODE>Name</CODE>. The order of the objects is not specified. See
the ERTS User's Guide for a description of match
specifications.
<P>If the keypos'th element of <CODE>MatchSpec</CODE> is
unbound, the match specification is applied to all objects of
the table. If the keypos'th element is bound, the match
specification is applied to the objects with the right key(s)
only.
<P>Using the <CODE>select</CODE> functions for traversing all
objects of a table is more efficient than calling
<CODE>first/1</CODE> and <CODE>next/2</CODE> or <CODE>slot/2</CODE>.
</DIV>
<P><A NAME="select/3"><STRONG><CODE>select(Name, MatchSpec, N) -> {Selection, Continuation}
| '$end_of_table' | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>MatchSpec = match_spec()</CODE></STRONG><BR>
<STRONG><CODE>N = default | int()</CODE></STRONG><BR>
<STRONG><CODE>Selection = [term()]</CODE></STRONG><BR>
<STRONG><CODE>Continuation = select_cont()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns the results of applying the match specification
<CODE>MatchSpec</CODE> to some or all objects stored in the table
<CODE>Name</CODE>. The order of the objects is not specified. See
the ERTS User's Guide for a description of match
specifications.
<P>A tuple of the results of applying the match specification
and a continuation is returned, unless the table is empty,
in which case <CODE>'$end_of_table'</CODE> is returned. The
continuation is to be used when matching further objects by
calling <CODE>select/1</CODE>.
<P>If the keypos'th element of <CODE>MatchSpec</CODE> is
bound, the match specification is applied to all objects of
the table with the right key(s). If the keypos'th
element of <CODE>MatchSpec</CODE> is unbound, the match
specification is applied to all objects of the table, <CODE>N</CODE>
objects at a time. The default, indicated by giving <CODE>N</CODE>
the value <CODE>default</CODE>, is to let the number of objects vary
depending on the sizes of the objects. If <CODE>Name</CODE> is a
version 9 table, all objects with the same key are always
handled at the same time which implies that the match
specification may be applied to more than N objects.
<P>The table should always be protected using
<CODE>safe_fixtable/2</CODE> before calling <CODE>select/3</CODE>, or
errors may occur when calling <CODE>select/1</CODE>.
</DIV>
<P><A NAME="select_delete/2"><STRONG><CODE>select_delete(Name, MatchSpec) -> N | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>MatchSpec = match_spec()</CODE></STRONG><BR>
<STRONG><CODE>N = int()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Deletes each object from the table <CODE>Name</CODE> such that
applying the match specification <CODE>MatchSpec</CODE> to the
object returns the value <CODE>true</CODE>. See the ERTS
User's Guide for a description of match
specifications. Returns the number of deleted objects.
<P>If the keypos'th element of <CODE>MatchSpec</CODE> is
bound, the match specification is applied to the objects
with the right key(s) only.
</DIV>
<P><A NAME="slot/2"><STRONG><CODE>slot(Name, I) -> '$end_of_table' | [Object] | {error, Reason}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>I = int()</CODE></STRONG><BR>
<STRONG><CODE>Object = object()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>The objects of a table are distributed among slots,
starting with slot <CODE>0</CODE> and ending with slot n. This
function returns the list of objects associated with slot
<CODE>I</CODE>. If <CODE>I</CODE> is greater than n <CODE>'$end_of_table'</CODE>
is returned.
</DIV>
<P><A NAME="sync/1"><STRONG><CODE>sync(Name) -> ok | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Ensures that all updates made to the table <CODE>Name</CODE> are
written to disk. This also applies to tables which have been
opened with the <CODE>ram_file</CODE> flag set to <CODE>true</CODE>. In
this case, the contents of the RAM file are flushed to
disk.
<P>Note that the space management data structures kept in RAM,
the buddy system, is also written to the disk. This may take
some time if the table is fragmented.
</DIV>
<P><A NAME="table/2"><STRONG><CODE>table(Name [, Options]) -> QueryHandle</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>QueryHandle = -a query handle, see qlc(3)-</CODE></STRONG><BR>
<STRONG><CODE>Options = [Option] | Option</CODE></STRONG><BR>
<STRONG><CODE>Option = {n_objects, Limit}
| {traverse, TraverseMethod}</CODE></STRONG><BR>
<STRONG><CODE>Limit = default | integer() >= 1</CODE></STRONG><BR>
<STRONG><CODE>TraverseMethod = first_next
| select
| {select, MatchSpec}</CODE></STRONG><BR>
<STRONG><CODE>MatchSpec = match_spec()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P><A NAME="qlc_table"><!-- Empty --></A>Returns a QLC (Query List
Comprehension) query handle. The module <CODE>qlc</CODE>
implements a query language aimed mainly at Mnesia but Ets
tables, Dets tables, and lists are also recognized by QLC
as sources of data. Calling <CODE>dets:table/1,2</CODE> is the
means to make the Dets table <CODE>Name</CODE> usable to QLC.
<P>When there are only simple restrictions on the key position
QLC uses <CODE>dets:lookup/2</CODE> to look up the keys, but when
that is not possible the whole table is traversed. The
option <CODE>traverse</CODE> determines how this is done:
<P>
<UL>
<LI>
<CODE>first_next</CODE>. The table is traversed one key at
a time by calling <CODE>dets:first/1</CODE> and
<CODE>dets:next/2</CODE>.<BR>
</LI>
<LI>
<CODE>select</CODE>. The table is traversed by calling
<CODE>dets:select/3</CODE> and <CODE>dets:select/1</CODE>. The option
<CODE>n_objects</CODE> determines the number of objects
returned (the third argument of <CODE>select/3</CODE>). The
match specification (the second argument of
<CODE>select/3</CODE>) is assembled by QLC: simple filters are
translated into equivalent match specifications while
more complicated filters have to be applied to all
objects returned by <CODE>select/3</CODE> given a match
specification that matches all objects.<BR>
</LI>
<LI>
<CODE>{select, MatchSpec}</CODE>. As for <CODE>select</CODE>
the table is traversed by calling <CODE>dets:select/3</CODE>
and <CODE>dets:select/1</CODE>. The difference is that the
match specification is explicitly given. This is how to
state match specifications that cannot easily be
expressed within the syntax provided by QLC.<BR>
</LI>
</UL>
<P>The following example uses an explicit match specification
to traverse the table:
<PRE>
1> <STRONG>dets:open_file(t, []),</STRONG>
<STRONG>dets:insert(t, [{1,a},{2,b},{3,c},{4,d}]),</STRONG>
<STRONG>MS = ets:fun2ms(fun({X,Y}) when (X > 1) or (X < 5) -> {Y} end),</STRONG>
<STRONG>QH1 = dets:table(t, [{traverse, {select, MS}}]).</STRONG>
</PRE>
<P>An example with implicit match specification:
<PRE>
2> <STRONG>QH2 = qlc:q([{Y} || {X,Y} <- dets:table(t), (X > 1) or (X < 5)]).</STRONG>
</PRE>
<P>The latter example is in fact equivalent to the former which
can be verified using the function <CODE>qlc:info/1</CODE>:
<PRE>
3> <STRONG>qlc:info(QH1) =:= qlc:info(QH2).</STRONG>
true
</PRE>
<P><CODE>qlc:info/1</CODE> returns information about a query handle,
and in this case identical information is returned for the
two query handles.
</DIV>
<P><A NAME="to_ets/2"><STRONG><CODE>to_ets(Name, EtsTab) -> EtsTab | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>EtsTab = -see ets(3)-
</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Inserts the objects of the Dets table <CODE>Name</CODE> into the
Ets table <CODE>EtsTab</CODE>. The order in which the objects are
inserted is not specified. The existing objects of the Ets
table are kept unless overwritten.
</DIV>
<P><A NAME="traverse/2"><STRONG><CODE>traverse(Name, Fun) -> Return | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Fun = fun(Object) -> FunReturn</CODE></STRONG><BR>
<STRONG><CODE>FunReturn = continue | {continue, Val} | {done, Value}</CODE></STRONG><BR>
<STRONG><CODE>Val = Value = term()</CODE></STRONG><BR>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Object = object()</CODE></STRONG><BR>
<STRONG><CODE>Return = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Applies <CODE>Fun</CODE> to each object stored in the table
<CODE>Name</CODE> in some unspecified order. Different actions are
taken depending on the return value of <CODE>Fun</CODE>. The
following <CODE>Fun</CODE> return values are allowed:
<P>
<DL>
<DT>
<CODE>continue</CODE>
</DT>
<DD>
Continue to perform the traversal. For example, the
following function can be used to print out the contents
of a table:<BR>
<PRE>
fun(X) -> io:format("~p~n", [X]), continue end.
</PRE>
</DD>
<DT>
<CODE>{continue, Val}</CODE>
</DT>
<DD>
Continue the traversal and accumulate <CODE>Val</CODE>. The
following function is supplied in order to collect all
objects of a table in a list: <BR>
<PRE>
fun(X) -> {continue, X} end.
</PRE>
</DD>
<DT>
<CODE>{done, Value}</CODE>
</DT>
<DD>
Terminate the traversal and return <CODE>[Value | Acc]</CODE>.<BR>
</DD>
</DL>
<P>Any other value returned by <CODE>Fun</CODE> terminates the
traversal and is immediately returned.
</DIV>
<P><A NAME="update_counter/3"><STRONG><CODE>update_counter(Name, Key, Increment) -> Result</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = name()</CODE></STRONG><BR>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>Increment = {Pos, Incr} | Incr</CODE></STRONG><BR>
<STRONG><CODE>Pos = Incr = Result = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Updates the object with key <CODE>Key</CODE> stored in the table
<CODE>Name</CODE> of type <CODE>set</CODE> by adding <CODE>Incr</CODE> to the
element at the <CODE>Pos</CODE>:th position. The new counter value
is returned. If no position is specified, the element directly
following the key is updated.
<P>This functions provides a way of updating a counter,
without having to look up an object, update the object by
incrementing an element and insert the resulting object into
the table again.
</DIV>
<H3>See Also</H3>
<DIV CLASS=REFBODY>
<P><A HREF="ets.html">ets(3)</A>,
mnesia(3),
<A HREF="qlc.html">qlc(3)</A>
</DIV>
<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
Claes Wikstrm - support@erlang.ericsson.se<BR>
Hans Bolinder - support@erlang.ericsson.se<BR>
</DIV>
<CENTER>
<HR>
<SMALL>stdlib 1.14.2<BR>
Copyright © 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|