unroff-website/www/doc/m-12.html

78 lines
2.4 KiB
HTML

<html>
<head>
<!-- This file has been generated by unroff 1.0, 03/21/96 19:29:47. -->
<!-- Do not edit! -->
<link rev="made" href="mailto:net@informatik.uni-bremen.de">
<title>unroff Programmer's Manual, section 12.</title>
</head><body>
<h2><a name="section12">12.</a>&#160;<tt> </tt>Tables
</h2>
<p>
&#160;<tt> </tt>&#160;<tt> </tt>&#160;<tt> </tt><i>unroff
</i>provides simple hash tables as a new first class data type
<i>table</i>.<tt> </tt>
Each table entry associates an arbitrary Scheme object with
a key (a Scheme string or symbol).<tt> </tt>
Tables are useful for various purposes; for example, the Scheme code
delivered with
<i>unroff
</i>maintains hash tables to store information about number registers,
options, fonts, and for other bookkeeping tasks.<tt> </tt>
<h2>
(table? <i>obj</i>)
</h2>
<p>
&#160;<tt> </tt>&#160;<tt> </tt>&#160;<tt> </tt>The type predicate for the new type; it returns #t if
<i>obj
</i>is a member of the type
<i>table</i>,
otherwise #f.<tt> </tt>
<h2>
(make-table <i>size</i>)
</h2>
<p>
&#160;<tt> </tt>&#160;<tt> </tt>&#160;<tt> </tt>Returns a new table of the specified size.<tt> </tt>
<i>size
</i>is a positive integer.<tt> </tt>
The smaller the size, the more collisions occur as entries
are added to the table.<tt> </tt>
However, the hash function employed by the table primitives
ensures that no collisions occur in tables of size
256^<i>n
</i>if all keys have a length less than or equal to
<i>n</i>.<tt> </tt>
<h2>
(table-store! <i>table</i> <i>key</i> <i>obj</i>)
</h2>
<p>
&#160;<tt> </tt>&#160;<tt> </tt>&#160;<tt> </tt>This primitive stores the Scheme object
<i>obj
</i>under the given
<i>key
</i>in the given
<i>table</i>.<tt> </tt>
The key argument must be a string or a symbol.<tt> </tt>
<h2>
(table-lookup <i>table</i> <i>key</i>)
</h2>
<p>
&#160;<tt> </tt>&#160;<tt> </tt>&#160;<tt> </tt>This primitive checks whether an object is stored in the given
<i>table
</i>under the specified
<i>key</i>,
and if so, returns the object.<tt> </tt>
If no object is stored under
<i>key</i>,
<i>table-lookup
</i>returns #f.<tt> </tt>
<h2>
(table-remove! <i>table</i> <i>key</i>)
</h2>
<p>
&#160;<tt> </tt>&#160;<tt> </tt>&#160;<tt> </tt>Removes the entry selected by
<i>key
</i>from the specified table.<tt> </tt>
<p><hr>
Markup created by <em>unroff</em> 1.0,&#160;<tt> </tt>&#160;<tt> </tt>March 21, 1996,&#160;<tt> </tt>&#160;<tt> </tt>net@informatik.uni-bremen.de</body>
</html>