1
0
Fork 0
cl-sites/novaspec.org/cl/f_make-hash-table.html
2025-02-05 18:52:26 +01:00

402 lines
No EOL
9.1 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>make-hash-table | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_make-hash-table.html"
><LINK REL="next" HREF="f_hash-table-p.html" TYPE="text/html" TITLE="hash-table-p"
><LINK REL="prev" HREF="t_hash-table.html" TYPE="text/html" TITLE="hash-table"
><LINK REL="up" HREF="18_2_Hash_Tables_Dictionary.html" TYPE="text/html" TITLE="18.2 Hash Tables Dictionary"
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
><SCRIPT SRC="dpans.js%3F3909942064"
></SCRIPT
><SCRIPT SRC="apropos.js%3F3909942064"
></SCRIPT
></HEAD
><BODY
><DIV
><DIV CLASS="topnav"
><DIV CLASS="breadcrumb"
><SPAN CLASS="breadcrumb-item"
><A HREF="index.html"
>Common Lisp Nova Spec</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="18_Hash_Tables.html"
>18. Hash Tables</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="18_2_Hash_Tables_Dictionary.html"
>18.2 Hash Tables Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_make-hash-table.html"
>make-hash-table</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="t_hash-table.html" CLASS="prev"
>&#8592;</A
><SPAN ID="apropos-label"
>Apropos </SPAN
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
><A HREF="f_hash-table-p.html" CLASS="next"
>&#8594;</A
></DIV
><DIV ID="apropos-res"
></DIV
></DIV
></DIV
><DIV CLASS="matter"
><DIV CLASS="com"
><DIV CLASS="begincom"
><HR
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
><TR
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="make-hash-table"
></SPAN
><B
>make-hash-table</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Function</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><P CLASS="j"
><B
>make-hash-table</B
> <SPAN CLASS="cmtt"
>&amp;key</SPAN
> <SPAN CLASS="cmssi"
>test</SPAN
> <SPAN CLASS="cmssi"
>size</SPAN
> <SPAN CLASS="cmssi"
>rehash-size</SPAN
> <SPAN CLASS="cmssi"
>rehash-threshold</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> <SPAN CLASS="cmssi"
>hash-table</SPAN
></P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>test</VAR
> &#8212; a <A HREF="26_1_Glossary.html#designator"
><EM CLASS="term"
>designator</EM
></A
> for one of the <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>functions</EM
></A
> <A HREF="f_eq.html" CLASS="funref"
><B
>eq</B
></A
>, <A HREF="f_eql.html" CLASS="funref"
><B
>eql</B
></A
>, <A HREF="f_equal.html" CLASS="funref"
><B
>equal</B
></A
>, or <A HREF="f_equalp.html" CLASS="funref"
><B
>equalp</B
></A
>. The default is <A HREF="f_eql.html" CLASS="funref"
><B
>eql</B
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>size</VAR
> &#8212; a non-negative <A HREF="26_1_Glossary.html#integer"
><EM CLASS="term"
>integer</EM
></A
>. The default is <A HREF="26_1_Glossary.html#implementation-dependent"
><EM CLASS="term"
>implementation-dependent</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>rehash-size</VAR
> &#8212; a <EM CLASS="term"
>real</EM
> of <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>type</EM
></A
> <CODE CLASS="f"
>(or (integer 1 *) (float (1.0) *))</CODE
>. The default is <A HREF="26_1_Glossary.html#implementation-dependent"
><EM CLASS="term"
>implementation-dependent</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>rehash-threshold</VAR
> &#8212; a <EM CLASS="term"
>real</EM
> of <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>type</EM
></A
> <CODE CLASS="f"
>(real 0 1)</CODE
>. The default is <A HREF="26_1_Glossary.html#implementation-dependent"
><EM CLASS="term"
>implementation-dependent</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>hash-table</VAR
> &#8212; a <A HREF="26_1_Glossary.html#hash_table"
><EM CLASS="term"
>hash table</EM
></A
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
>Creates and returns a new <A HREF="26_1_Glossary.html#hash_table"
><EM CLASS="term"
>hash table</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>test</VAR
> determines how <A HREF="26_1_Glossary.html#key"
><EM CLASS="term"
>keys</EM
></A
> are compared. An <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> is said to be present in the <VAR CLASS="param"
>hash-table</VAR
> if that <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> is the <A HREF="26_1_Glossary.html#same"
><EM CLASS="term"
>same</EM
></A
> under the <EM CLASS="term"
>test</EM
> as the <A HREF="26_1_Glossary.html#key"
><EM CLASS="term"
>key</EM
></A
> for some entry in the <VAR CLASS="param"
>hash-table</VAR
>. </P
><P CLASS="j"
><VAR CLASS="param"
>size</VAR
> is a hint to the <A HREF="26_1_Glossary.html#implementation"
><EM CLASS="term"
>implementation</EM
></A
> about how much initial space to allocate in the <VAR CLASS="param"
>hash-table</VAR
>. This information, taken together with the <VAR CLASS="param"
>rehash-threshold</VAR
>, controls the approximate number of entries which it should be possible to insert before the table has to grow. The actual size might be rounded up from <VAR CLASS="param"
>size</VAR
> to the next &#8216;good&#8217; size; for example, some <A HREF="26_1_Glossary.html#implementation"
><EM CLASS="term"
>implementations</EM
></A
> might round to the next prime number. </P
><P CLASS="j"
><VAR CLASS="param"
>rehash-size</VAR
> specifies a minimum amount to increase the size of the <VAR CLASS="param"
>hash-table</VAR
> when it becomes full enough to require rehashing; see <VAR CLASS="param"
>rehash-theshold</VAR
> below. If <VAR CLASS="param"
>rehash-size</VAR
> is an <A HREF="26_1_Glossary.html#integer"
><EM CLASS="term"
>integer</EM
></A
>, the expected growth rate for the table is additive and the <A HREF="26_1_Glossary.html#integer"
><EM CLASS="term"
>integer</EM
></A
> is the number of entries to add; if it is a <A HREF="26_1_Glossary.html#float"
><EM CLASS="term"
>float</EM
></A
>, the expected growth rate for the table is multiplicative and the <A HREF="26_1_Glossary.html#float"
><EM CLASS="term"
>float</EM
></A
> is the ratio of the new size to the old size. As with <VAR CLASS="param"
>size</VAR
>, the actual size of the increase might be rounded up. </P
><P CLASS="j"
><VAR CLASS="param"
>rehash-threshold</VAR
> specifies how full the <VAR CLASS="param"
>hash-table</VAR
> can get before it must grow. It specifies the maximum desired hash-table occupancy level. </P
><P CLASS="j"
>The <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
> of <VAR CLASS="param"
>rehash-size</VAR
> and <VAR CLASS="param"
>rehash-threshold</VAR
> do not constrain the <A HREF="26_1_Glossary.html#implementation"
><EM CLASS="term"
>implementation</EM
></A
> to use any particular method for computing when and by how much the size of <VAR CLASS="param"
>hash-table</VAR
> should be enlarged. Such decisions are <A HREF="26_1_Glossary.html#implementation-dependent"
><EM CLASS="term"
>implementation-dependent</EM
></A
>, and these <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
> only hints from the <A HREF="26_1_Glossary.html#programmer"
><EM CLASS="term"
>programmer</EM
></A
> to the <A HREF="26_1_Glossary.html#implementation"
><EM CLASS="term"
>implementation</EM
></A
>, and the <A HREF="26_1_Glossary.html#implementation"
><EM CLASS="term"
>implementation</EM
></A
> is permitted to ignore them.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
> (setq table (make-hash-table)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;HASH-TABLE EQL 0/120 46142754&gt;
(setf (gethash "one" table) 1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1
(gethash "one" table) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL, <A HREF="26_1_Glossary.html#false"
><EM CLASS="term"
>false</EM
></A
>
(setq table (make-hash-table :test 'equal)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;HASH-TABLE EQUAL 0/139 46145547&gt;
(setf (gethash "one" table) 1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1
(gethash "one" table) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1, T
(make-hash-table :rehash-size 1.5 :rehash-threshold 0.7)
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;HASH-TABLE EQL 0/120 46156620&gt;</PRE
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_gethash.html" CLASS="funref"
><B
>gethash</B
></A
>, <A HREF="t_hash-table.html" CLASS="typeref"
><B
>hash-table</B
></A
></P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="t_hash-table.html" CLASS="prev"
>&#8592;</A
><A HREF="f_hash-table-p.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>