File: ets.html

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

<H3>MODULE</H3>
<DIV CLASS=REFBODY>
ets
</DIV>

<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
Built-In Term Storage
</DIV>

<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>

<P>This module is an interface to the Erlang built-in term storage
BIFs. These provide the ability to store very large quantities of
data in an Erlang runtime system, and to have constant access
time to the data. (In the case of <CODE>ordered_set</CODE>, see below,
access time is proportional to the logarithm of the number of
objects stored).
<P>Data is organized as a set of dynamic tables, which can store
tuples. Each table is created by a process. When the process
terminates, the table is automatically destroyed. Every table has
access rights set at creation.
<P>Tables are divided into four different types, <CODE>set</CODE>,
<CODE>ordered_set</CODE>, <CODE>bag</CODE> and <CODE>duplicate_bag</CODE>.
A <CODE>set</CODE> or <CODE>ordered_set</CODE> table can only have one object
associated with each key. A <CODE>bag</CODE> or <CODE>duplicate_bag</CODE> can
have many objects associated with each key.
<P>The number of tables stored at one Erlang node is limited.
The current default limit is approximately 1400 tables. The upper
limit can be increased by setting the environment variable
<CODE>ERL_MAX_ETS_TABLES</CODE> before starting the Erlang runtime
system (i.e. with the <CODE>-env</CODE> option to
<CODE>erl</CODE>/<CODE>werl</CODE>). The actual limit may be slightly higher
than the one specified, but never lower.
<P>Note that there is no automatic garbage collection for tables.
Even if there are no references to a table from any process, it
will not automatically be destroyed unless the owner process
terminates. It can be destroyed explicitly by using
<CODE>delete/1</CODE>.
<P>Some implementation details:
<P>
<UL>

<LI>
In the current implementation, every object insert and
        look-up operation results in one copy of the object.
</LI>


<LI>
This module provides very limited support for concurrent
        updates. No locking is available, but the <CODE>safe_fixtable/2</CODE>
        function can be used to guarantee that a sequence of
        <CODE>first/1</CODE> and <CODE>next/2</CODE> calls will traverse the table
        without errors even if another process (or the same process)
        simultaneously deletes or inserts objects in the table.
</LI>


<LI>
<CODE>'$end_of_table'</CODE> should not be used as a key since
        this atom is used to mark the end of the table when using
        <CODE>first</CODE>/<CODE>next</CODE>.
</LI>


</UL>

<P>In general, the functions below will exit with reason
<CODE>badarg</CODE> if any argument is of the wrong format, or if the
table identifier is invalid.
</DIV>
<A NAME="match_spec"><!-- Empty --></A>
<H3>Match Specifications</H3>
<DIV CLASS=REFBODY>

<P>Some of the functions uses a <STRONG>match specification</STRONG>,
match_spec. A brief explanation is given in
<A HREF="#select/2">select/2</A>. For a detailed
description, see the chapter &#34;Match specifications in Erlang&#34; in
<STRONG>ERTS User's Guide</STRONG>.
</DIV>

<H3>DATA TYPES</H3>
<DIV CLASS=REFBODY>

<PRE>
match_spec()
  a match specification, see above

tid()
  a table identifier, as returned by new/2
    
</PRE>

</DIV>

<H3>EXPORTS</H3>

<P><A NAME="all/0"><STRONG><CODE>all() -&#62; [Tab]</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns a list of all tables at the node. Named tables are
         given by their names, unnamed tables are given by their
         table identifiers.
</DIV>

<P><A NAME="delete/1"><STRONG><CODE>delete(Tab) -&#62; true</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Deletes the entire table <CODE>Tab</CODE>.
</DIV>

<P><A NAME="delete/2"><STRONG><CODE>delete(Tab, Key) -&#62; true</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Deletes all objects with the key <CODE>Key</CODE> from the table
         <CODE>Tab</CODE>.
</DIV>

<P><A NAME="delete_all_objects/1"><STRONG><CODE>delete_all_objects(Tab) -&#62; true</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Delete all objects in the ETS table <CODE>Tab</CODE>. The deletion
         is atomic.
</DIV>

<P><A NAME="delete_object/2"><STRONG><CODE>delete_object(Tab,Object) -&#62; true</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Object = tuple()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Delete the exact object <CODE>Object</CODE> from the ETS table,
         leaving objects with the same key but other differences
         (useful for type <CODE>bag</CODE>).
</DIV>

<P><A NAME="file2tab/1"><STRONG><CODE>file2tab(Filename) -&#62; {ok,Tab} | {error,Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Filename = string() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Reason = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Reads a file produced by <CODE>tab2file/2</CODE> and creates the
         corresponding table <CODE>Tab</CODE>.
</DIV>

<P><A NAME="first/1"><STRONG><CODE>first(Tab) -&#62; Key | '$end_of_table'</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns the first key <CODE>Key</CODE> in the table <CODE>Tab</CODE>.
         If the table is of the <CODE>ordered_set</CODE> type, the first key
         in Erlang term order will be returned. If the table is of any
         other type, the first key according to the table's internal
         order will be returned. If the table is empty,
         <CODE>'$end_of_table'</CODE> will be returned.
<P>Use <CODE>next/2</CODE> to find subsequent keys in the table.
</DIV>

<P><A NAME="fixtable/2"><STRONG><CODE>fixtable(Tab, true|false) -&#62; true | false</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>
<TABLE CELLPADDING=4>
  <TR>
    <TD VALIGN=TOP><IMG ALT="Warning!" SRC="warning.gif"></TD>
    <TD>

<P>The function is retained for backwards compatibility only.
         Use <CODE>safe_fixtable/2</CODE> instead.    </TD>
  </TR>
</TABLE>

<P>Fixes a table for safe traversal. The function is primarily
         used by the Mnesia DBMS to implement functions which allow
         write operations in a table, although the table is in the
         process of being copied to disk or to another node. It does
         not keep track of when and how tables are fixed.
</DIV>

<P><A NAME="foldl/3"><STRONG><CODE>foldl(Function, Acc0, Tab) -&#62; Acc1</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Function = fun(A, AccIn) -&#62; AccOut</CODE></STRONG><BR>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Acc0 = Acc1 = AccIn = AccOut = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P><CODE>Acc0</CODE> is returned if the table is empty.
         This function is similar to <CODE>lists:foldl/3</CODE>. The order in
         which the elements of the table are traversed is unspecified,
         except for tables of type <CODE>ordered_set</CODE>, for which they
         are traversed first to last.

</DIV>

<P><A NAME="foldr/3"><STRONG><CODE>foldr(Function, Acc0, Tab) -&#62; Acc1</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Function = fun(A, AccIn) -&#62; AccOut</CODE></STRONG><BR>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Acc0 = Acc1 = AccIn = AccOut = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P><CODE>Acc0</CODE> is returned if the table is empty.
         This function is similar to <CODE>lists:foldr/3</CODE>. The order in
         which the elements of the table are traversed is unspecified,
         except for tables of type <CODE>ordered_set</CODE>, for which they
         are traversed last to first.

</DIV>

<P><A NAME="from_dets/2"><STRONG><CODE>from_dets(Tab, DetsTab) -&#62; Tab</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>DetsTab = atom()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Fills an already created ETS table with the objects in the
         already opened Dets table named <CODE>DetsTab</CODE>. The existing
         objects of the ETS table are kept unless overwritten.
</DIV>

<P><A NAME="fun2ms/1"><STRONG><CODE>fun2ms(LiteralFun) -&#62; MatchSpec</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>LiteralFun -- see below</CODE></STRONG><BR>
<STRONG><CODE>MatchSpec = match_spec()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Pseudo function that by means of a <CODE>parse_transform</CODE>
         translates <CODE>LiteralFun</CODE> typed as parameter in the
         function call to a
         <A HREF="#match_spec">match_spec</A>. With
         &#34;literal&#34; is meant that the fun needs to textually be written
         as the parameter of the function, it cannot be held in a
         variable which in turn is passed to the function).
<P>The parse transform is implemented in the module
         <CODE>ms_transform</CODE> and the source <STRONG>must</STRONG> include the
         file <CODE>ms_transform.hrl</CODE> in <CODE>stdlib</CODE> for this
         pseudo function to work. Failing to include the hrl file in
         the source will result in a runtime error, not a compile
         time ditto. The include file is easiest included by adding
         the line
         <CODE>-include_lib(&#34;stdlib/include/ms_transform.hrl&#34;).</CODE> to
         the source file.
<P>The fun is very restricted, it can take only a single
         parameter (the object to match): a sole variable or a
         tuple. It needs to use the <CODE>is_</CODE>XXX guard tests.
         Language constructs that have no representation
         in a match_spec (like <CODE>if</CODE>, <CODE>case</CODE>, <CODE>receive</CODE>
         etc) are not allowed.
<P>The return value is the resulting match_spec.
<P>Example:
<PRE>
1&#62; <STRONG>ets:fun2ms(fun({M,N}) when N &#62; 3 -&#62; M end).</STRONG>
[{{'$1','$2'},[{'&#62;','$2',3}],['$1']}]
        
</PRE>

<P>Variables from the environment can be imported, so that this
         works:
<PRE>
2&#62; <STRONG>X=3.</STRONG>
3
3&#62; <STRONG>ets:fun2ms(fun({M,N}) when N &#62; X -&#62; M end).</STRONG>
[{{'$1','$2'},[{'&#62;','$2',{const,3}}],['$1']}]
        
</PRE>

<P>The imported variables will be replaced by match_spec
         <CODE>const</CODE> expressions, which is consistent with the
         static scoping for Erlang funs. Local or global function
         calls can not be in the guard or body of the fun however.
         Calls to builtin match_spec functions of course is allowed:
        
<PRE>
4&#62; <STRONG>ets:fun2ms(fun({M,N}) when N &#62; X, is_atomm(M) -&#62; M end).</STRONG>
Error: fun containing local Erlang function calls
('is_atomm' called in guard) cannot be translated into match_spec
{error,transform_error}
5&#62; <STRONG>ets:fun2ms(fun({M,N}) when N &#62; X, is_atom(M) -&#62; M end).</STRONG>
[{{'$1','$2'},[{'&#62;','$2',{const,3}},{is_atom,'$1'}],['$1']}]
        
</PRE>

<P>As can be seen by the example, the function can be called
         from the shell too. The fun needs to be literally in the call
         when used from the shell as well. Other means than the
         parse_transform are used in the shell case, but more or less
the same restrictions apply (the exception being records,
as they are not handled by the shell).
<P>
<TABLE CELLPADDING=4>
  <TR>
    <TD VALIGN=TOP><IMG ALT="Warning!" SRC="warning.gif"></TD>
    <TD>

<P>If the parse_transform is not applied to a module which
         calls this pseudo function, the call will fail in runtime
         (with a <CODE>badarg</CODE>). The module <CODE>ets</CODE> actually
         exports a function with this name, but it should never
         really be called except for when using the function in the
         shell. If the <CODE>parse_transform</CODE> is properly applied by
         including the <CODE>ms_transform.hrl</CODE> header file, compiled
         code will never call the function, but the function call is
         replaced by a literal match_spec.    </TD>
  </TR>
</TABLE>

<P>For more information, see
         <A HREF="ms_transform.html#top">ms_transform(3)</A>.
        
</DIV>

<P><A NAME="i/0"><STRONG><CODE>i() -&#62; void()</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY>

<P>Displays information about all ETS tables on tty.
</DIV>

<P><A NAME="i/1"><STRONG><CODE>i(Tab) -&#62; void()</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Browses the table <CODE>Tab</CODE> on tty.
</DIV>

<P><A NAME="info/1"><STRONG><CODE>info(Tab) -&#62; [{Item, Value}] | undefined</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Item = atom(), see below</CODE></STRONG><BR>
<STRONG><CODE>Value = term(), see below</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns information about the table <CODE>Tab</CODE> as a list of
         <CODE>{Item, Value}</CODE> tuples.
<P>
<TABLE CELLPADDING=4>
  <TR>
    <TD VALIGN=TOP><IMG ALT="Warning!" SRC="warning.gif"></TD>
    <TD>

<P>In Erlang/OTP R10B and earlier releases, this function
         erroneously returned a tuple. This has now been corrected.
             </TD>
  </TR>
</TABLE>

<P>
<UL>

<LI>
         <CODE>Item=memory, Value=int()</CODE><BR>

         The number of words allocated to the table.
         
</LI>


<LI>
         <CODE>Item=owner, Value=pid()</CODE><BR>

         The pid of the owner of the table.
         
</LI>


<LI>
         <CODE>Item=name, Value=atom()</CODE><BR>

         The name of the table.
         
</LI>


<LI>
         <CODE>Item=size, Value=int()</CODE><BR>

         The number of objects inserted in the table.
         
</LI>


<LI>
         <CODE>Item=node, Value=atom()</CODE><BR>

         The node where the table is stored. This field is no longer
         meaningful as tables cannot be accessed from other nodes.
         
</LI>


<LI>
         <CODE>Item=named_table, Value=true|false</CODE><BR>

         Indicates if the table is named or not.
         
</LI>


<LI>
         <CODE>Item=type, Value=set|ordered_set|bag|duplicate_bag</CODE>
         <BR>

         The table type.
         
</LI>


<LI>
         <CODE>Item=keypos, Value=int()</CODE><BR>

         The key position.
         
</LI>


<LI>
         <CODE>Item=protection, Value=public|protected|private</CODE><BR>

         The table access rights.
         
</LI>


</UL>

</DIV>

<P><A NAME="info/2"><STRONG><CODE>info(Tab, Item) -&#62; Value | undefined</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Item, Value - see below</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns the information associated with <CODE>Item</CODE> for
         the table <CODE>Tab</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>Item=fixed, Value=true|false</CODE><BR>

         Indicates if the table is fixed by any process or not.
         
</LI>


<LI>
         <CODE>Item=safe_fixed, Value={FirstFixed,Info}|false
         </CODE><BR>

         If the table has been fixed using <CODE>safe_fixtable/2</CODE>,
         the call returns a tuple where <CODE>FirstFixed</CODE> is the
         time when the table was first fixed by a process, which
         may or may not be one of the processes it is fixed by
         right now.<BR>


         <CODE>Info</CODE> is a possibly empty lists of tuples
         <CODE>{Pid,RefCount}</CODE>, one tuple for every process the
         table is fixed by right now. <CODE>RefCount</CODE> is the value
         of the reference counter, keeping track of how many times
         the table has been fixed by the process.<BR>


         If the table never has been fixed, the call returns
         <CODE>false</CODE>.<BR>

         
</LI>


</UL>

</DIV>

<P><A NAME="init_table/2"><STRONG><CODE>init_table(Name, InitFun) -&#62; true</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) -&#62; Res</CODE></STRONG><BR>
<STRONG><CODE>Arg = read | close</CODE></STRONG><BR>
<STRONG><CODE>Res = end_of_input | {[object()], InitFun} | term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Replaces the existing objects of the table <CODE>Tab</CODE> with
         objects created by calling the input function <CODE>InitFun</CODE>,
         see below. This function is provided for compatibility with
         the <CODE>dets</CODE> module, it is not more efficient than filling
         a table by using <CODE>ets:insert/2</CODE>.

        
<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. This holds also for duplicated
         objects stored in tables of type <CODE>duplicate_bag</CODE>.
</DIV>

<P><A NAME="insert/2"><STRONG><CODE>insert(Tab, ObjectOrObjects) -&#62; true</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>ObjectOrObjects = tuple() | [tuple()]</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Inserts the object or all of the objects in the list
         <CODE>ObjectOrObjects</CODE> into the table <CODE>Tab</CODE>. If there
         already exists an object with the same key as one of the
         objects, and the table is a <CODE>set</CODE> or <CODE>ordered_set</CODE>
         table, the old object will be replaced. If the list contains
         more than one object with the same key and the table is a
         <CODE>set/ordered_set</CODE>, one will be inserted, which one is
         not defined.
</DIV>

<P><A NAME="insert_new/2"><STRONG><CODE>insert_new(Tab, ObjectOrObjects) -&#62; bool()</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>ObjectOrObjects = tuple() | [tuple()]</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>This function works exactly like <CODE>insert/2</CODE>, with the
         exception that instead of overwriting objects with the same
         key (in the case of <CODE>set</CODE> or <CODE>ordered_set</CODE>) or
         adding more objects with keys already existing in the table
         (in the case of <CODE>bag</CODE> and <CODE>duplicate_bag</CODE>), it
         simply returns <CODE>false</CODE>. If <CODE>ObjectOrObjects</CODE> is a
         list, the function checks <STRONG>every</STRONG> key prior to
         inserting anything. Nothing will be inserted if not
         <STRONG>all</STRONG> keys present in the list are absent from the
         table.
</DIV>

<P><A NAME="is_compiled_ms/1"><STRONG><CODE>is_compiled_ms(Term) -&#62; bool()</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Term = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>This function is used to check if a term is a valid
         compiled <A HREF="#match_spec">match_spec</A>.
         The compiled match_spec is an opaque datatype which can
         <STRONG>not</STRONG> be sent between Erlang nodes nor be stored on
         disk. Any attempt to create an external representation of a
         compiled match_spec will result in an empty binary
         (<CODE>&#60;&#60;&#62;&#62;</CODE>). As an example, the following
         expression:
<PRE>
ets:is_compiled_ms(ets:match_spec_compile([{'_',[],[true]}])).
        
</PRE>

<P>will yield <CODE>true</CODE>, while the following expressions:
<PRE>
MS = ets:match_spec_compile([{'_',[],[true]}]),
Broken = binary_to_term(term_to_binary(MS)),
ets:is_compiled_ms(Broken).
        
</PRE>

<P>will yield false, as the variable <CODE>Broken</CODE> will contain
         a compiled match_spec that has passed through external
         representation.
<P>
<TABLE CELLPADDING=4>
  <TR>
    <TD VALIGN=TOP><IMG ALT="Note!" SRC="note.gif"></TD>
    <TD>

<P>The fact that compiled match_specs has no external
         representation is for performance reasons. It may be subject
         to change in future releases, while this interface will
         still remain for backward compatibility reasons.    </TD>
  </TR>
</TABLE>

</DIV>

<P><A NAME="last/1"><STRONG><CODE>last(Tab) -&#62; Key | '$end_of_table'</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns the last key <CODE>Key</CODE> according to Erlang term
         order in the table <CODE>Tab</CODE> of the <CODE>ordered_set</CODE> type.
         If the table is of any other type, the function is synonymous
         to <CODE>first/2</CODE>. If the table is empty,
         <CODE>'$end_of_table'</CODE> is returned.
<P>Use <CODE>prev/2</CODE> to find preceding keys in the table.
</DIV>

<P><A NAME="lookup/2"><STRONG><CODE>lookup(Tab, Key) -&#62; [Object]</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>Object = tuple()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns a list of all objects with the key <CODE>Key</CODE> in
         the table <CODE>Tab</CODE>.
<P>If the table is of type <CODE>set</CODE> or <CODE>ordered_set</CODE>,
         the function returns either the empty list or a list with one
         element, as there cannot be more than one object with the same
         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 time order of object insertions is preserved;
         The first object inserted with the given key will be first
         in the resulting list, and so on.
<P>Insert and look-up times in tables of type <CODE>set</CODE>,
         <CODE>bag</CODE> and <CODE>duplicate_bag</CODE> are constant, regardless
         of the size of the table. For the <CODE>ordered_set</CODE>
         data-type, time is proportional to the (binary) logarithm of
         the number of objects.
</DIV>

<P><A NAME="lookup_element/3"><STRONG><CODE>lookup_element(Tab, Key, Pos) -&#62; Elem</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>Pos = int()</CODE></STRONG><BR>
<STRONG><CODE>Elem = term() | [term()]</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>If the table <CODE>Tab</CODE> is of type <CODE>set</CODE> or
         <CODE>ordered_set</CODE>, the function returns the <CODE>Pos</CODE>:th
         element of the object with the key <CODE>Key</CODE>.
<P>If the table is of type <CODE>bag</CODE> or <CODE>duplicate_bag</CODE>,
         the functions returns a list with the <CODE>Pos</CODE>:th element of
         every object with the key <CODE>Key</CODE>.
<P>If no object with the key <CODE>Key</CODE> exists, the function
         will exit with reason <CODE>badarg</CODE>.
</DIV>

<P><A NAME="match/2"><STRONG><CODE>match(Tab, Pattern) -&#62; [Match]</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Pattern = tuple()</CODE></STRONG><BR>
<STRONG><CODE>Match = [term()]</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Matches the objects in the table <CODE>Tab</CODE> against the
         pattern <CODE>Pattern</CODE>.
<P>A pattern is a term that may contain:
<P>
<UL>

<LI>
bound parts (Erlang terms),
</LI>


<LI>
<CODE>'_'</CODE> which matches any Erlang term, and
</LI>


<LI>
pattern variables: <CODE>'$N'</CODE> where
         <CODE>N</CODE>=0,1,...
</LI>


</UL>

<P>The function returns a list with one element for each
         matching object, where each element is an ordered list of
         pattern variable bindings. An example:
<PRE>
6&#62; <STRONG>ets:match(T, '$1').</STRONG> % Matches every object in the table
[[{rufsen,dog,7}],[{brunte,horse,5}],[{ludde,dog,5}]]
7&#62; <STRONG>ets:match(T, {'_',dog,'$1'}).</STRONG>
[[7],[5]]
8&#62; <STRONG>ets:match(T, {'_',cow,'$1'}).</STRONG>
[]
        
</PRE>

<P>If the key is specified in the pattern, the match is very
         efficient. If the key is not specified, i.e. if it is a
         variable or an underscore, the entire table must be searched.
         The search time can be substantial if the table is very large.
        
<P>On tables of the <CODE>ordered_set</CODE> type, the result is in
         the same order as in a <CODE>first/next</CODE> traversal.
</DIV>

<P><A NAME="match/3"><STRONG><CODE>match(Tab, Pattern, Limit) -&#62; {[Match],Continuation} |
        '$end_of_table'</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Pattern = tuple()</CODE></STRONG><BR>
<STRONG><CODE>Match = [term()]</CODE></STRONG><BR>
<STRONG><CODE>Continuation = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Works like <CODE>ets:match/2</CODE> but only returns a limited
         (<CODE>Limit</CODE>) number of matching objects. The
         <CODE>Continuation</CODE> term can then be used in subsequent calls
         to <CODE>ets:match/1</CODE> to get the next chunk of matching
         objects. This is a space efficient way to work on objects in a
         table which is still faster than traversing the table object
         by object using <CODE>ets:first/1</CODE> and <CODE>ets:next/1</CODE>.
<P><CODE>'$end_of_table'</CODE> is returned if the table is empty.
</DIV>

<P><A NAME="match/1"><STRONG><CODE>match(Continuation) -&#62; {[Match],Continuation} |
        '$end_of_table'</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Match = [term()]</CODE></STRONG><BR>
<STRONG><CODE>Continuation = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Continues a match started with <CODE>ets:match/3</CODE>. The next
         chunk of the size given in the initial <CODE>ets:match/3</CODE>
         call is returned together with a new <CODE>Continuation</CODE>
         that can be used in subsequent calls to this function.
<P><CODE>'$end_of_table'</CODE> is returned when there are no more
         objects in the table.
</DIV>

<P><A NAME="match_delete/2"><STRONG><CODE>match_delete(Tab, Pattern) -&#62; true</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Pattern = tuple()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Deletes all objects which match the pattern <CODE>Pattern</CODE>
         from the table <CODE>Tab</CODE>. See <CODE>match/2</CODE> for a
         description of patterns.
</DIV>

<P><A NAME="match_object/2"><STRONG><CODE>match_object(Tab, Pattern) -&#62; [Object]</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Pattern = Object = tuple()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Matches the objects in the table <CODE>Tab</CODE> against the
         pattern <CODE>Pattern</CODE>. See <CODE>match/2</CODE> for a description
         of patterns. The function returns a list of all objects which
         match the pattern.
<P>If the key is specified in the pattern, the match is very
         efficient. If the key is not specified, i.e. if it is a
         variable or an underscore, the entire table must be searched.
         The search time can be substantial if the table is very large.
        
<P>On tables of the <CODE>ordered_set</CODE> type, the result is in
         the same order as in a <CODE>first/next</CODE> traversal.
</DIV>

<P><A NAME="match_object/3"><STRONG><CODE>match_object(Tab, Pattern, Limit) -&#62; {[Match],Continuation}
        | '$end_of_table'</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Pattern = tuple()</CODE></STRONG><BR>
<STRONG><CODE>Match = [term()]</CODE></STRONG><BR>
<STRONG><CODE>Continuation = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Works like <CODE>ets:match_object/2</CODE> but only returns a
         limited (<CODE>Limit</CODE>) number of matching objects. The
         <CODE>Continuation</CODE> term can then be used in subsequent calls
         to <CODE>ets:match_object/1</CODE> to get the next chunk of matching
         objects. This is a space efficient way to work on objects in a
         table which is still faster than traversing the table object
         by object using <CODE>ets:first/1</CODE> and <CODE>ets:next/1</CODE>.
<P><CODE>'$end_of_table'</CODE> is returned if the table is empty.
</DIV>

<P><A NAME="match_object/1"><STRONG><CODE>match_object(Continuation) -&#62; {[Match],Continuation} |
        '$end_of_table'</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Match = [term()]</CODE></STRONG><BR>
<STRONG><CODE>Continuation = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Continues a match started with <CODE>ets:match_object/3</CODE>.
         The next chunk of the size given in the initial
         <CODE>ets:match_object/3</CODE> call is returned together with a
         new <CODE>Continuation</CODE> that can be used in subsequent calls
         to this function.
<P><CODE>'$end_of_table'</CODE> is returned when there are no more
         objects in the table.
</DIV>

<P><A NAME="match_spec_compile/1"><STRONG><CODE>match_spec_compile(MatchSpec) -&#62; CompiledMatchSpec</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>MatchSpec = match_spec()</CODE></STRONG><BR>
<STRONG><CODE>CompiledMatchSpec = comp_match_spec()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>This function transforms a
         <A HREF="#match_spec">match_spec</A> into an
         internal representation that can be used in subsequent calls
         to <CODE>ets:match_spec_run/2</CODE>. The internal representation is
         opaque and can not be converted to external term format and
         then back again without losing its properties (meaning it can
         not be sent to a process on another node and still remain a
         valid compiled match_spec, nor can it be stored on disk).
         The validity of a compiled match_spec can be checked using
         <CODE>ets:is_compiled_ms/1</CODE>.
<P>If the term <CODE>MatchSpec</CODE> can not be compiled (does not
         represent a valid match_spec), a <CODE>badarg</CODE> fault is
         thrown.
<P>
<TABLE CELLPADDING=4>
  <TR>
    <TD VALIGN=TOP><IMG ALT="Note!" SRC="note.gif"></TD>
    <TD>

<P>This function has limited use in normal code, it is used by
         Dets to perform the <CODE>dets:select</CODE> operations.    </TD>
  </TR>
</TABLE>

</DIV>

<P><A NAME="match_spec_run/2"><STRONG><CODE>match_spec_run(List,CompiledMatchSpec) -&#62; list()</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>List = [ tuple() ]</CODE></STRONG><BR>
<STRONG><CODE>CompiledMatchSpec = comp_match_spec()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>This function executes the matching specified in a
         compiled <A HREF="#match_spec">match_spec</A> on
         a list of tuples. The <CODE>CompiledMatchSpec</CODE> term should be
         the result of a call to <CODE>ets:match_spec_compile/1</CODE> and
         is hence the internal representation of the match_spec one
         wants to use.
<P>The matching will be executed on each element in <CODE>List</CODE>
         and the function returns a list containing all results. If an
         element in <CODE>List</CODE> does not match, nothing is returned
         for that element. The length of the result list is therefore
         equal or less than the the length of the parameter
         <CODE>List</CODE>. The two calls in the following example will give
         the same result (but certainly not the same execution
         time...):
<PRE>
Table = ets:new...
MatchSpec = ....
% The following call...
ets:match_spec_run(ets:tab2list(Table),
ets:match_spec_compile(MatchSpec)),
% ...will give the same result as the more common (and more efficient)
ets:select(Table,MatchSpec),
        
</PRE>

<P>
<TABLE CELLPADDING=4>
  <TR>
    <TD VALIGN=TOP><IMG ALT="Note!" SRC="note.gif"></TD>
    <TD>

<P>This function has limited use in normal code, it is used by
         Dets to perform the <CODE>dets:select</CODE> operations and by
         Mnesia during transactions.    </TD>
  </TR>
</TABLE>

</DIV>

<P><A NAME="member/2"><STRONG><CODE>member(Tab, Key) -&#62; true | false</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Key = term()</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 in
         the table has the key <CODE>Key</CODE>, <CODE>false</CODE> otherwise.
</DIV>

<P><A NAME="new/2"><STRONG><CODE>new(Name, Options) -&#62; tid()</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = atom()</CODE></STRONG><BR>
<STRONG><CODE>Options = [Option]</CODE></STRONG><BR>
<STRONG><CODE>Option = Type | Access | named_table | {keypos,Pos}</CODE></STRONG><BR>
<STRONG><CODE>Type = set | ordered_set | bag | duplicate_bag
        </CODE></STRONG><BR>
<STRONG><CODE>Access = public | protected | private</CODE></STRONG><BR>
<STRONG><CODE>Pos = int()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Creates a new table and returns a table identifier which can
         be used in subsequent operations. The table identifier can be
         sent to other processes so that a table can be shared between
         different processes within a node.
<P>The parameter <CODE>Options</CODE> is a list of atoms which
         specifies table type, access rights, key position and if the
         table is named or not. If one or more options are left out,
         the default values are used. This means that not specifying
         any options (<CODE>[]</CODE>) is the same as specifying
         <CODE>[set,protected,{keypos,1}]</CODE>.
<P>
<UL>

<LI>
<CODE>set</CODE>
         The table is a <CODE>set</CODE> table - one key, one object,
         no order among objects. This is the default table type.
         <BR>

         
</LI>


<LI>
<CODE>ordered_set</CODE>
         The table is a <CODE>ordered_set</CODE> table - one key, one
         object, ordered in Erlang term order, which is the order
         implied by the &#60; and &#62; operators. Tables of this type
         have a somewhat different behavior in some situations
         than tables of the other types.<BR>

         
</LI>


<LI>
<CODE>bag</CODE>
         The table is a <CODE>bag</CODE> table which can have many
         objects, but only one instance of each object, per key.
         <BR>

         
</LI>


<LI>
<CODE>duplicate_bag</CODE>
         The table is a <CODE>duplicate_bag</CODE> table which can have
         many objects, including multiple copies of the same
         object, per key.<BR>

         
</LI>


<LI>
<CODE>public</CODE>
         Any process may read or write to the table.<BR>

         
</LI>


<LI>
<CODE>protected</CODE>
         The owner process can read and write to the table. Other
         processes can only read the table. This is the default
         setting for the access rights.<BR>

         
</LI>


<LI>
<CODE>private</CODE>
         Only the owner process can read or write to the table.<BR>

         
</LI>


<LI>
<CODE>named_table</CODE>
         If this option is present, the name <CODE>Name</CODE> is
         associated with the table identifier. The name can then
         be used instead of the table identifier in subsequent
         operations.<BR>

         
</LI>


<LI>
<CODE>{keypos,Pos}</CODE>
         Specfies which element in the stored tuples should be
         used as key. By default, it is the first element, i.e.
         <CODE>Pos=1</CODE>. However, this is not always appropriate. In
         particular, we do not want the first element to be the
         key if we want to store Erlang records in a table.<BR>

         Note that any tuple stored in the table must have at
         least <CODE>Pos</CODE> number of elements.<BR>

         
</LI>


</UL>

</DIV>

<P><A NAME="next/2"><STRONG><CODE>next(Tab, Key1) -&#62; Key2 | '$end_of_table'</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Key1 = Key2 = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns the next key <CODE>Key2</CODE>, following the key
         <CODE>Key1</CODE> in the table <CODE>Tab</CODE>. If the table is of the
         <CODE>ordered_set</CODE> type, the next key in Erlang term order is
         returned. If the table is of any other type, the next key
         according to the table's internal order is returned. If there
         is no next key, <CODE>'$end_of_table'</CODE> is returned.
<P>Use <CODE>first/1</CODE> to find the first key in the table.
<P>Unless a table of type <CODE>set</CODE>, <CODE>bag</CODE> or
         <CODE>duplicate_bag</CODE> is protected using
         <CODE>safe_fixtable/2</CODE>, see below, a traversal may fail if
         concurrent updates are made to the table. If the table is of
         type <CODE>ordered_set</CODE>, the function returns the next key in
         order, even if the object does no longer exist.
</DIV>

<P><A NAME="prev/2"><STRONG><CODE>prev(Tab, Key1) -&#62; Key2 | '$end_of_table'</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Key1 = Key2 = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns the previous key <CODE>Key2</CODE>, preceding the key
         <CODE>Key1</CODE> according the Erlang term order in the table
         <CODE>Tab</CODE> of the <CODE>ordered_set</CODE> type. If the table is of
         any other type, the function is synonymous to <CODE>next/2</CODE>.
         If there is no previous key, <CODE>'$end_of_table'</CODE> is
         returned.
<P>Use <CODE>last/1</CODE> to find the last key in the table.
</DIV>

<P><A NAME="rename/2"><STRONG><CODE>rename(Tab, Name) -&#62; Name</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = Name = atom()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Renames the named table <CODE>Tab</CODE> to the new name
         <CODE>Name</CODE>. Afterwards, the old name can not be used to
         access the table. Renaming an unnamed table has no effect.
</DIV>

<P><A NAME="repair_continuation/2"><STRONG><CODE>repair_continuation(Continuation, MatchSpec) -&#62; Continuation
</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Continuation = term()</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>ets:select/3</CODE> or <CODE>ets: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_specs and therefore will be
         invalidated if converted to external term format. Given that
         the original match_spec is kept intact, the continuation can
         be restored, meaning it can once again be used in subsequent
         <CODE>ets:select/1</CODE> calls even though it has been stored on
         disk or on another node.
<P>As an example, the following seqence of calls will fail:
<PRE>
T=ets:new(x,[]),
...
{_,C} = ets:select(T,ets:fun2ms(fun({N,_}=A)
when (N rem 10) =:= 0 -&#62;
A
end),10),
Broken = binary_to_term(term_to_binary(C)),
ets:select(Broken).
        
</PRE>

<P>...while the following sequence will work:
<PRE>
T=ets:new(x,[]),
...
MS = ets:fun2ms(fun({N,_}=A)
when (N rem 10) =:= 0 -&#62;
A
end),
{_,C} = ets:select(T,MS,10),
Broken = binary_to_term(term_to_binary(C)),
ets:select(ets:repair_continuation(Broken,MS)).
        
</PRE>

<P>...as the call to <CODE>ets:repair_continuation/2</CODE> will
         reestablish the (deliberately) invalidated continuation
         <CODE>Broken</CODE>.
<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 a
         compiled match_spec 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(Tab, true|false) -&#62; true</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Fixes a table of the <CODE>set</CODE>, <CODE>bag</CODE> or
         <CODE>duplicate_bag</CODE> table type for safe traversal.
<P>A process fixes a table by calling
         <CODE>safe_fixtable(Tab,true)</CODE>. The table remains fixed until
         the process releases it by calling
         <CODE>safe_fixtable(Tab,false)</CODE>, or until the 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 requires N releases to actually release
         the table.
<P>When a table is fixed, a sequence of <CODE>first/1</CODE> and
         <CODE>next/2</CODE> calls are guaranteed to succeed even if objects
         are removed during the traversal. An example:
<PRE>
clean_all_with_value(Tab,X) -&#62;
    safe_fixtable(Tab,true),
    clean_all_with_value(Tab,X,ets:first(Tab)),
    safe_fixtable(Tab,false).

clean_all_with_value(Tab,X,'$end_of_table') -&#62;
    true;
clean_all_with_value(Tab,X,Key) -&#62;
    case ets:lookup(Tab,Key) of
        [{Key,X}] -&#62;
            ets:delete(Tab,Key);
        _ -&#62;
            true
    end,
    clean_all_with_value(Tab,X,ets:next(Tab,Key)).
        
</PRE>

<P>Note that no deleted objects are actually removed from a
         fixed table until it has been released. If a process fixes a
         table but never releases it, the memory used by the deleted
         objects will never be freed. The performance of operations on
         the table will also degrade significantly.
<P>Use <CODE>info/2</CODE> to retrieve information about which
         processes have fixed which tables. A system with a lot of
         processes fixing tables may need a monitor which sends alarms
         when tables have been fixed for too long.
<P>Note that for tables of the <CODE>ordered_set</CODE> type,
         <CODE>safe_fixtable/2</CODE> is not necessary as calls to
         <CODE>first/1</CODE> and <CODE>next/2</CODE> will always succeed.
</DIV>

<P><A NAME="select/2"><STRONG><CODE>select(Tab, MatchSpec) -&#62; [Match]</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Match = term()</CODE></STRONG><BR>
<STRONG><CODE>MatchSpec = match_spec()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Matches the objects in the table <CODE>Tab</CODE> using a
         <A HREF="#match_spec">match_spec</A>. This is a
         more general call than the <CODE>ets:match/2</CODE> and
         <CODE>ets:match_object/2</CODE> calls. In its simplest forms the
         match_specs look like this:
<P>
<UL>

<LI>
MatchSpec = [MatchFunction]
         
</LI>


<LI>
MatchFunction = {MatchHead, [Guard], [Result]}
         
</LI>


<LI>
MatchHead = &#34;Pattern as in ets:match&#34;
         
</LI>


<LI>
Guard = {&#34;Guardtest name&#34;, ...}
         
</LI>


<LI>
Result = &#34;Term construct&#34;
        
</LI>


</UL>

<P>This means that the match_spec is always a list of one or
         more tuples (of arity 3). The tuples first element should be
         a pattern as described in the documentation of
         <CODE>ets:match/2</CODE>. The second element of the tuple should
         be a list of 0 or more guard tests (described below). The
         third element of the tuple should be a list containing a
         description of the value to actually return. In almost all
         normal cases the list contains exactly one term which fully
         describes the value to return for each object.
<P>The return value is constructed using the &#34;match variables&#34;
         bound in the MatchHead or using the special match variables
         <CODE>'$_'</CODE> (the whole matching object) and <CODE>'$$'</CODE> (all
         match variables in a list), so that the following
         <CODE>ets:match/2</CODE> expression:
<PRE>
ets:match(Tab,{'$1','$2','$3'})
        
</PRE>

<P>is exactly equivalent to:
<PRE>
ets:select(Tab,[{{'$1','$2','$3'},[],['$$']}])
        
</PRE>

<P>- and the following <CODE>ets:match_object/2</CODE> call:
<PRE>
ets:match_object(Tab,{'$1','$2','$1'})
        
</PRE>

<P>is exactly equivalent to
<PRE>
ets:select(Tab,[{{'$1','$2','$1'},[],['$_']}])
        
</PRE>

<P>Composite terms can be constructed in the <CODE>Result</CODE> part
         either by simply writing a list, so that this code:
<PRE>
ets:select(Tab,[{{'$1','$2','$3'},[],['$$']}])
        
</PRE>

<P>gives the same output as:
<PRE>
ets:select(Tab,[{{'$1','$2','$3'},[],[['$1','$2','$3']]}])
        
</PRE>

<P>i.e. all the bound variables in the match head as a list. If
         tuples are to be constructed, one has to write a tuple of
         arity 1 with the single element in the tuple being the tuple
         one wants to construct (as an ordinary tuple could be mistaken
         for a <CODE>Guard</CODE>). Therefore the following call:
<PRE>
ets:select(Tab,[{{'$1','$2','$1'},[],['$_']}])
        
</PRE>

<P>gives the same output as:
<PRE>
ets:select(Tab,[{{'$1','$2','$1'},[],[{{'$1','$2','$3'}}]}])
        
</PRE>

<P>- this syntax is equivalent to the syntax used in the trace
         patterns (see
         <A HREF="javascript:erlhref('../../../../', 'runtime_tools', 'dbg.html');">dbg(3)</A>).
<P>The <CODE>Guard</CODE>s are constructed as tuples where the first
         element is the name of the test and the rest of the elements
         are the parameters of the test. To check for a specific type
         (say a list) of the element bound to the match variable
         <CODE>'$1'</CODE>, one would write the test as
         <CODE>{is_list, '$1'}</CODE>. If the test fails, the object in the
         table will not match and the next <CODE>MatchFunction</CODE> (if
         any) will be tried. Most guard tests present in Erlang can be
         used, but only the new versions prefixed <CODE>is_</CODE> are
         allowed (like <CODE>is_float</CODE>, <CODE>is_atom</CODE> etc).
<P>The <CODE>Guard</CODE> section can also contain logic and
         arithmetic operations, which are written with the same syntax
         as the guard tests (prefix notation), so that a guard test
         written in Erlang looking like this:
<PRE>
is_integer(X), is_integer(Y), X + Y &#60; 4711
        
</PRE>

<P>is expressed like this (X replaced with '$1' and Y with
         '$2'):
<PRE>
[{is_integer, '$1'}, {is_integer, '$2'}, {'&#60;', {'+', '$1', '$2'}, 4711}]
        
</PRE>

</DIV>

<P><A NAME="select/3"><STRONG><CODE>select(Tab, MatchSpec, Limit) -&#62; {[Match],Continuation} |
        '$end_of_table'</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Match = term()</CODE></STRONG><BR>
<STRONG><CODE>MatchSpec = match_spec()</CODE></STRONG><BR>
<STRONG><CODE>Continuation = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Works like <CODE>ets:select/2</CODE> but only returns a limited
         (<CODE>Limit</CODE>) number of matching objects. The
         <CODE>Continuation</CODE> term can then be used in subsequent calls
         to <CODE>ets:select/1</CODE> to get the next chunk of matching
         objects. This is a space efficient way to work on objects in a
         table which is still faster than traversing the table object
         by object using <CODE>ets:first/1</CODE> and <CODE>ets:next/1</CODE>.
<P><CODE>'$end_of_table'</CODE> is returned if the table is empty.
</DIV>

<P><A NAME="select/1"><STRONG><CODE>select(Continuation) -&#62; {[Match],Continuation} |
        '$end_of_table'</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Match = term()</CODE></STRONG><BR>
<STRONG><CODE>Continuation = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Continues a match started with
         <CODE>ets:select/3</CODE>. The next
         chunk of the size given in the initial <CODE>ets:select/3</CODE>
         call is returned together with a new <CODE>Continuation</CODE>
         that can be used in subsequent calls to this function.
<P><CODE>'$end_of_table'</CODE> is returned when there are no more
         objects in the table.
</DIV>

<P><A NAME="select_delete/2"><STRONG><CODE>select_delete(Tab, MatchSpec) -&#62; NumDeleted</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Object = tuple()</CODE></STRONG><BR>
<STRONG><CODE>MatchSpec = match_spec()</CODE></STRONG><BR>
<STRONG><CODE>NumDeleted = integer()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Matches the objects in the table <CODE>Tab</CODE> using a
         <A HREF="#match_spec">match_spec</A>. If the
         match_spec returns <CODE>true</CODE> for an object, that object is
         removed from the table. For any other result from the
         match_spec the object is retained. This is a more general
         call than the <CODE>ets:match_delete/2</CODE> call.
<P>The function returns the number of objects actually
         deleted from the table.
</DIV>

<P><A NAME="select_count/2"><STRONG><CODE>select_count(Tab, MatchSpec) -&#62; NumMatched</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Object = tuple()</CODE></STRONG><BR>
<STRONG><CODE>MatchSpec = match_spec()</CODE></STRONG><BR>
<STRONG><CODE>NumMatched = integer()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Matches the objects in the table <CODE>Tab</CODE> using a
         <A HREF="#match_spec">match_spec</A>. If the
         match_spec returns <CODE>true</CODE> for an object, that object
         considered a match and is counted. For any other result from
         the match_spec the object is not considered a match and is
         therefore not counted.
<P>The function could be described as a <CODE>match_delete/2</CODE>
         that does not actually delete any elements, but only counts
         them.
<P>The function returns the number of objects matched.
</DIV>

<P><A NAME="slot/2"><STRONG><CODE>slot(Tab, I) -&#62; [Object] | '$end_of_table'</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>I = int()</CODE></STRONG><BR>
<STRONG><CODE>Object = tuple()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>This function is mostly for debugging purposes, Normally
         one should use <CODE>first/next</CODE> or <CODE>last/prev</CODE> instead.
        
<P>Returns all objects in the <CODE>I</CODE>:th slot of the table
         <CODE>Tab</CODE>. A table can be traversed by repeatedly calling
         the function, starting with the first slot <CODE>I=0</CODE> and
         ending when <CODE>'$end_of_table'</CODE> is returned.
         The function will fail with reason <CODE>badarg</CODE> if the
         <CODE>I</CODE> argument is out of range.
<P>Unless a table of type <CODE>set</CODE>, <CODE>bag</CODE> or
         <CODE>duplicate_bag</CODE> is protected using
         <CODE>safe_fixtable/2</CODE>, see above, a traversal may fail if
         concurrent updates are made to the table. If the table is of
         type <CODE>ordered_set</CODE>, the function returns a list
         containing the <CODE>I</CODE>:th object in Erlang term order.
</DIV>

<P><A NAME="tab2file/2"><STRONG><CODE>tab2file(Tab, Filename) -&#62; ok | {error,Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Filename = string() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Reason = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Dumps the table <CODE>Tab</CODE> to the file <CODE>Filename</CODE>.
         The implementation of this function is not efficient.
</DIV>

<P><A NAME="tab2list/1"><STRONG><CODE>tab2list(Tab) -&#62; [Object]</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Object = tuple()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns a list of all objects in the table <CODE>Tab</CODE>.
</DIV>

<P><A NAME="table/2"><STRONG><CODE>table(Tab [, Options]) -&#62; QueryHandle</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</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, NObjects}
         | {traverse, TraverseMethod}</CODE></STRONG><BR>
<STRONG><CODE>NObjects = default | integer() &#62; 0</CODE></STRONG><BR>
<STRONG><CODE>TraverseMethod = first_next
         | last_prev
         | 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>ets:table/1,2</CODE> is the means to make the
         ETS table <CODE>Tab</CODE> usable to QLC.
<P>When there are only simple restrictions on the key position
         QLC uses <CODE>ets: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>ets:first/1</CODE> and
         <CODE>ets:next/2</CODE>.<BR>

         
</LI>


<LI>
         <CODE>last_prev</CODE>. The table is traversed one key at
         a time by calling <CODE>ets:last/1</CODE> and
         <CODE>ets:prev/2</CODE>.<BR>

         
</LI>


<LI>
         <CODE>select</CODE>. The table is traversed by calling
         <CODE>ets:select/3</CODE> and <CODE>ets:select/1</CODE>. The option
         <CODE>n_objects</CODE> determines the number of objects
         returned (the third argument of <CODE>select/3</CODE>); the
         default is to return <CODE>100</CODE> objects at a time. The
         <A HREF="#match_spec">match_spec</A> (the
         second argument of <CODE>select/3</CODE>) is assembled by QLC:
         simple filters are translated into equivalent match_specs
         while more complicated filters have to be applied to all
         objects returned by <CODE>select/3</CODE> given a match_spec
         that matches all objects.<BR>

         
</LI>


<LI>
         <CODE>{select, MatchSpec}</CODE>. As for <CODE>select</CODE>
         the table is traversed by calling <CODE>ets:select/3</CODE> and
         <CODE>ets:select/1</CODE>. The difference is that the
         match_spec is explicitly given. This is how to state
         match_specs that cannot easily be expressed within the
         syntax provided by QLC.<BR>

         
</LI>


</UL>

<P>The following example uses an explicit match_spec to
         traverse the table:
<PRE>
9&#62; <STRONG>ets:insert(Tab = ets:new(t, []), [{1,a},{2,b},{3,c},{4,d}]),</STRONG>
<STRONG>MS = ets:fun2ms(fun({X,Y}) when (X &#62; 1) or (X &#60; 5) -&#62; {Y} end),</STRONG>
<STRONG>QH1 = ets:table(Tab, [{traverse, {select, MS}}]).</STRONG>
        
</PRE>

<P>An example with implicit match_spec:
<PRE>
10&#62; <STRONG>QH2 = qlc:q([{Y} || {X,Y} &#60;- ets:table(Tab), (X &#62; 1) or (X &#60; 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>
11&#62; <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="test_ms/2"><STRONG><CODE>test_ms(Tuple, MatchSpec) -&#62; {ok, Result} | {error, Errors}
</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tuple = tuple()</CODE></STRONG><BR>
<STRONG><CODE>MatchSpec = match_spec()</CODE></STRONG><BR>
<STRONG><CODE>Result = term()</CODE></STRONG><BR>
<STRONG><CODE>Errors = [{warning|error, string()}]
</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>This function is a utility to test a
         <A HREF="#match_spec">match_spec</A> used in
         calls to <CODE>ets:select/2</CODE>. The function both tests
         <CODE>MatchSpec</CODE> for &#34;syntactic&#34; correctness and runs the
         match_spec against the object <CODE>Tuple</CODE>. If the match_spec
         contains errors, the tuple <CODE>{error, Errors}</CODE> is returned
         where <CODE>Errors</CODE> is a list of natural language
         descriptions of what was wrong with the match_spec. If the
         match_spec is syntactically OK, the function returns
         <CODE>{ok,Term}</CODE> where <CODE>Term</CODE> is what would have been
         the result in a real <CODE>ets:select/2</CODE> call or <CODE>false</CODE>
         if the match_spec does not match the object <CODE>Tuple</CODE>.
<P>This is a useful debugging and test tool, especially when
         writing complicated <CODE>ets:select/2</CODE> calls.
</DIV>

<P><A NAME="to_dets/2"><STRONG><CODE>to_dets(Tab, DetsTab) -&#62; Tab</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>DetsTab = atom()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Fills an already created/opened Dets table with the objects
         in the already opened ETS table named <CODE>Tab</CODE>. The Dets
         table is emptied before the objects are inserted.
</DIV>

<P><A NAME="update_counter/6"><STRONG><CODE>update_counter(Tab, Key, {Pos,Incr,Threshold,SetValue}) -&#62;
        Result</CODE></STRONG></A><BR>
<A NAME="update_counter/4"><STRONG><CODE>update_counter(Tab, Key, {Pos,Incr}) -&#62; Result</CODE></STRONG></A><BR>
<A NAME="update_counter/3"><STRONG><CODE>update_counter(Tab, Key, Incr) -&#62; Result</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = tid() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>Pos = Incr = Threshold = SetValue = Result = int()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>This function provides an efficient way to update a counter,
         without the hassle of having to look up an object, update the
         object by incrementing an element and insert the resulting
         object into the table again. (The update is done atomically;
         i.e. no process can access the ets table in the middle of the
         operation.)
<P>It will destructively update the object with key <CODE>Key</CODE>
         in the table <CODE>Tab</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 (<CODE>&#60;keypos&#62;+1</CODE>) is updated.
<P>If a <CODE>Threshold</CODE> is specified, the counter will be
         reset to the value <CODE>SetValue</CODE> if the following
         conditions occur:
<P>
<UL>

<LI>
The <CODE>Incr</CODE> is not negative (<CODE>&#62;= 0</CODE>) and the
         result would be greater than (<CODE>&#62;</CODE>) <CODE>Threshold</CODE>
         
</LI>


<LI>
The <CODE>Incr</CODE> is negative (<CODE>&#60; 0</CODE>) and the
         result would be less than (<CODE>&#60;</CODE>)
         <CODE>Threshold</CODE>
</LI>


</UL>

<P>The function will fail with reason <CODE>badarg</CODE> if:
<P>
<UL>

<LI>
the table is not of type <CODE>set</CODE> or
         <CODE>ordered_set</CODE>,
</LI>


<LI>
no object with the right key exists,
</LI>


<LI>
the object has the wrong arity,
</LI>


<LI>
the element to update is not an integer,
</LI>


<LI>
the element to update is also the key, or,
</LI>


<LI>
any of <CODE>Pos</CODE>, <CODE>Incr</CODE>, <CODE>Threshold</CODE> or
         <CODE>SetValue</CODE> is not an integer
</LI>


</UL>

</DIV>

<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
Claes Wikstrom, Tony Rogvall, Patrik Nyblom - support@erlang.ericsson.se<BR>

</DIV>
<CENTER>
<HR>
<SMALL>stdlib 1.14.2<BR>
Copyright &copy; 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>