summaryrefslogtreecommitdiff
path: root/devdocs/elisp/hash-tables.html
blob: ebdabe4d10efbf2bedfc6d89492e6da406afde8b (plain)
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
 <h2 class="chapter">Hash Tables</h2>   <p>A hash table is a very fast kind of lookup table, somewhat like an alist (see <a href="association-lists">Association Lists</a>) in that it maps keys to corresponding values. It differs from an alist in these ways: </p> <ul> <li> Lookup in a hash table is extremely fast for large tables—in fact, the time required is essentially <em>independent</em> of how many elements are stored in the table. For smaller tables (a few tens of elements) alists may still be faster because hash tables have a more-or-less constant overhead. </li>
<li> The correspondences in a hash table are in no particular order. </li>
<li> There is no way to share structure between two hash tables, the way two alists can share a common tail. </li>
</ul> <p>Emacs Lisp provides a general-purpose hash table data type, along with a series of functions for operating on them. Hash tables have a special printed representation, which consists of ‘<samp>#s</samp>’ followed by a list specifying the hash table properties and contents. See <a href="creating-hash">Creating Hash</a>. (Hash notation, the initial ‘<samp>#</samp>’ character used in the printed representations of objects with no read representation, has nothing to do with hash tables. See <a href="printed-representation">Printed Representation</a>.) </p> <p>Obarrays are also a kind of hash table, but they are a different type of object and are used only for recording interned symbols (see <a href="creating-symbols">Creating Symbols</a>). </p> <table class="menu" border="0" cellspacing="0"> <tr>
<td align="left" valign="top">• <a href="creating-hash" accesskey="1">Creating Hash</a>
</td>
<td> </td>
<td align="left" valign="top">Functions to create hash tables. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="hash-access" accesskey="2">Hash Access</a>
</td>
<td> </td>
<td align="left" valign="top">Reading and writing the hash table contents. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="defining-hash" accesskey="3">Defining Hash</a>
</td>
<td> </td>
<td align="left" valign="top">Defining new comparison methods. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="other-hash" accesskey="4">Other Hash</a>
</td>
<td> </td>
<td align="left" valign="top">Miscellaneous. </td>
</tr> </table><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Hash-Tables.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Hash-Tables.html</a>
  </p>
</div>