232 lines
17 KiB
HTML
232 lines
17 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html>
|
||
|
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<!-- This manual documents Guile version 3.0.10.
|
||
|
|
||
|
Copyright (C) 1996-1997, 2000-2005, 2009-2023 Free Software Foundation,
|
||
|
Inc.
|
||
|
|
||
|
Copyright (C) 2021 Maxime Devos
|
||
|
|
||
|
Copyright (C) 2024 Tomas Volf
|
||
|
|
||
|
|
||
|
Permission is granted to copy, distribute and/or modify this document
|
||
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||
|
any later version published by the Free Software Foundation; with no
|
||
|
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
|
||
|
copy of the license is included in the section entitled "GNU Free
|
||
|
Documentation License." -->
|
||
|
<title>rnrs hashtables (Guile Reference Manual)</title>
|
||
|
|
||
|
<meta name="description" content="rnrs hashtables (Guile Reference Manual)">
|
||
|
<meta name="keywords" content="rnrs hashtables (Guile Reference Manual)">
|
||
|
<meta name="resource-type" content="document">
|
||
|
<meta name="distribution" content="global">
|
||
|
<meta name="Generator" content=".texi2any-real">
|
||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||
|
|
||
|
<link href="index.html" rel="start" title="Top">
|
||
|
<link href="Concept-Index.html" rel="index" title="Concept Index">
|
||
|
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
||
|
<link href="R6RS-Standard-Libraries.html" rel="up" title="R6RS Standard Libraries">
|
||
|
<link href="rnrs-enums.html" rel="next" title="rnrs enums">
|
||
|
<link href="rnrs-syntax_002dcase.html" rel="prev" title="rnrs syntax-case">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
|
||
|
span:hover a.copiable-link {visibility: visible}
|
||
|
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
|
||
|
-->
|
||
|
</style>
|
||
|
<link rel="stylesheet" type="text/css" href="https://www.gnu.org/software/gnulib/manual.css">
|
||
|
|
||
|
|
||
|
</head>
|
||
|
|
||
|
<body lang="en">
|
||
|
<div class="subsubsection-level-extent" id="rnrs-hashtables">
|
||
|
<div class="nav-panel">
|
||
|
<p>
|
||
|
Next: <a href="rnrs-enums.html" accesskey="n" rel="next">rnrs enums</a>, Previous: <a href="rnrs-syntax_002dcase.html" accesskey="p" rel="prev">rnrs syntax-case</a>, Up: <a href="R6RS-Standard-Libraries.html" accesskey="u" rel="up">R6RS Standard Libraries</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
|
||
|
</div>
|
||
|
<hr>
|
||
|
<h4 class="subsubsection" id="rnrs-hashtables-1"><span>7.6.2.25 rnrs hashtables<a class="copiable-link" href="#rnrs-hashtables-1"> ¶</a></span></h4>
|
||
|
|
||
|
<p>The <code class="code">(rnrs hashtables (6))</code> library provides structures and
|
||
|
procedures for creating and accessing hash tables. The hash tables API
|
||
|
defined by R6RS is substantially similar to both Guile’s native hash
|
||
|
tables implementation as well as the one provided by SRFI-69;
|
||
|
See <a class="xref" href="Hash-Tables.html">Hash Tables</a>, and <a class="ref" href="SRFI_002d69.html">SRFI-69 - Basic hash tables</a>, respectively. Note that you can
|
||
|
write portable R6RS library code that manipulates SRFI-69 hash tables
|
||
|
(by importing the <code class="code">(srfi :69)</code> library); however, hash tables
|
||
|
created by one API cannot be used by another.
|
||
|
</p>
|
||
|
<p>Like SRFI-69 hash tables—and unlike Guile’s native ones—R6RS hash
|
||
|
tables associate hash and equality functions with a hash table at the
|
||
|
time of its creation. Additionally, R6RS allows for the creation
|
||
|
(via <code class="code">hashtable-copy</code>; see below) of immutable hash tables.
|
||
|
</p>
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-make_002deq_002dhashtable"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">make-eq-hashtable</strong><a class="copiable-link" href="#index-make_002deq_002dhashtable"> ¶</a></span></dt>
|
||
|
<dt class="deffnx def-cmd-deffn" id="index-make_002deq_002dhashtable-1"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">make-eq-hashtable</strong> <var class="def-var-arguments">k</var><a class="copiable-link" href="#index-make_002deq_002dhashtable-1"> ¶</a></span></dt>
|
||
|
<dd><p>Returns a new hash table that uses <code class="code">eq?</code> to compare keys and
|
||
|
Guile’s <code class="code">hashq</code> procedure as a hash function. If <var class="var">k</var> is given,
|
||
|
it specifies the initial capacity of the hash table.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-make_002deqv_002dhashtable"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">make-eqv-hashtable</strong><a class="copiable-link" href="#index-make_002deqv_002dhashtable"> ¶</a></span></dt>
|
||
|
<dt class="deffnx def-cmd-deffn" id="index-make_002deqv_002dhashtable-1"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">make-eqv-hashtable</strong> <var class="def-var-arguments">k</var><a class="copiable-link" href="#index-make_002deqv_002dhashtable-1"> ¶</a></span></dt>
|
||
|
<dd><p>Returns a new hash table that uses <code class="code">eqv?</code> to compare keys and
|
||
|
Guile’s <code class="code">hashv</code> procedure as a hash function. If <var class="var">k</var> is given,
|
||
|
it specifies the initial capacity of the hash table.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-make_002dhashtable"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">make-hashtable</strong> <var class="def-var-arguments">hash-function equiv</var><a class="copiable-link" href="#index-make_002dhashtable"> ¶</a></span></dt>
|
||
|
<dt class="deffnx def-cmd-deffn" id="index-make_002dhashtable-1"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">make-hashtable</strong> <var class="def-var-arguments">hash-function equiv k</var><a class="copiable-link" href="#index-make_002dhashtable-1"> ¶</a></span></dt>
|
||
|
<dd><p>Returns a new hash table that uses <var class="var">equiv</var> to compare keys and
|
||
|
<var class="var">hash-function</var> as a hash function. <var class="var">equiv</var> must be a procedure
|
||
|
that accepts two arguments and returns a true value if they are
|
||
|
equivalent, <code class="code">#f</code> otherwise; <var class="var">hash-function</var> must be a procedure
|
||
|
that accepts one argument and returns a non-negative integer.
|
||
|
</p>
|
||
|
<p>If <var class="var">k</var> is given, it specifies the initial capacity of the hash
|
||
|
table.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_003f"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable?</strong> <var class="def-var-arguments">obj</var><a class="copiable-link" href="#index-hashtable_003f"> ¶</a></span></dt>
|
||
|
<dd><p>Returns <code class="code">#t</code> if <var class="var">obj</var> is an R6RS hash table, <code class="code">#f</code>
|
||
|
otherwise.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_002dsize"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-size</strong> <var class="def-var-arguments">hashtable</var><a class="copiable-link" href="#index-hashtable_002dsize"> ¶</a></span></dt>
|
||
|
<dd><p>Returns the number of keys currently in the hash table <var class="var">hashtable</var>.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_002dref"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-ref</strong> <var class="def-var-arguments">hashtable key default</var><a class="copiable-link" href="#index-hashtable_002dref"> ¶</a></span></dt>
|
||
|
<dd><p>Returns the value associated with <var class="var">key</var> in the hash table
|
||
|
<var class="var">hashtable</var>, or <var class="var">default</var> if none is found.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_002dset_0021"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-set!</strong> <var class="def-var-arguments">hashtable key obj</var><a class="copiable-link" href="#index-hashtable_002dset_0021"> ¶</a></span></dt>
|
||
|
<dd><p>Associates the key <var class="var">key</var> with the value <var class="var">obj</var> in the hash table
|
||
|
<var class="var">hashtable</var>, and returns an unspecified value. An <code class="code">&assertion</code>
|
||
|
condition is raised if <var class="var">hashtable</var> is immutable.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_002ddelete_0021"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-delete!</strong> <var class="def-var-arguments">hashtable key</var><a class="copiable-link" href="#index-hashtable_002ddelete_0021"> ¶</a></span></dt>
|
||
|
<dd><p>Removes any association found for the key <var class="var">key</var> in the hash table
|
||
|
<var class="var">hashtable</var>, and returns an unspecified value. An <code class="code">&assertion</code>
|
||
|
condition is raised if <var class="var">hashtable</var> is immutable.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_002dcontains_003f"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-contains?</strong> <var class="def-var-arguments">hashtable key</var><a class="copiable-link" href="#index-hashtable_002dcontains_003f"> ¶</a></span></dt>
|
||
|
<dd><p>Returns <code class="code">#t</code> if the hash table <var class="var">hashtable</var> contains an
|
||
|
association for the key <var class="var">key</var>, <code class="code">#f</code> otherwise.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_002dupdate_0021"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-update!</strong> <var class="def-var-arguments">hashtable key proc default</var><a class="copiable-link" href="#index-hashtable_002dupdate_0021"> ¶</a></span></dt>
|
||
|
<dd><p>Associates with <var class="var">key</var> in the hash table <var class="var">hashtable</var> the result
|
||
|
of calling <var class="var">proc</var>, which must be a procedure that takes one
|
||
|
argument, on the value currently associated <var class="var">key</var> in
|
||
|
<var class="var">hashtable</var>—or on <var class="var">default</var> if no such association exists.
|
||
|
An <code class="code">&assertion</code> condition is raised if <var class="var">hashtable</var> is
|
||
|
immutable.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_002dcopy"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-copy</strong> <var class="def-var-arguments">hashtable</var><a class="copiable-link" href="#index-hashtable_002dcopy"> ¶</a></span></dt>
|
||
|
<dt class="deffnx def-cmd-deffn" id="index-hashtable_002dcopy-1"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-copy</strong> <var class="def-var-arguments">hashtable mutable</var><a class="copiable-link" href="#index-hashtable_002dcopy-1"> ¶</a></span></dt>
|
||
|
<dd><p>Returns a copy of the hash table <var class="var">hashtable</var>. If the optional
|
||
|
argument <var class="var">mutable</var> is provided and is a true value, the new hash
|
||
|
table will be mutable.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_002dclear_0021"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-clear!</strong> <var class="def-var-arguments">hashtable</var><a class="copiable-link" href="#index-hashtable_002dclear_0021"> ¶</a></span></dt>
|
||
|
<dt class="deffnx def-cmd-deffn" id="index-hashtable_002dclear_0021-1"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-clear!</strong> <var class="def-var-arguments">hashtable k</var><a class="copiable-link" href="#index-hashtable_002dclear_0021-1"> ¶</a></span></dt>
|
||
|
<dd><p>Removes all of the associations from the hash table <var class="var">hashtable</var>.
|
||
|
The optional argument <var class="var">k</var>, which specifies a new capacity for the
|
||
|
hash table, is accepted by Guile’s <code class="code">(rnrs hashtables)</code>
|
||
|
implementation, but is ignored.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_002dkeys"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-keys</strong> <var class="def-var-arguments">hashtable</var><a class="copiable-link" href="#index-hashtable_002dkeys"> ¶</a></span></dt>
|
||
|
<dd><p>Returns a vector of the keys with associations in the hash table
|
||
|
<var class="var">hashtable</var>, in an unspecified order.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_002dentries"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-entries</strong> <var class="def-var-arguments">hashtable</var><a class="copiable-link" href="#index-hashtable_002dentries"> ¶</a></span></dt>
|
||
|
<dd><p>Return two values—a vector of the keys with associations in the hash
|
||
|
table <var class="var">hashtable</var>, and a vector of the values to which these keys
|
||
|
are mapped, in corresponding but unspecified order.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_002dequivalence_002dfunction"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-equivalence-function</strong> <var class="def-var-arguments">hashtable</var><a class="copiable-link" href="#index-hashtable_002dequivalence_002dfunction"> ¶</a></span></dt>
|
||
|
<dd><p>Returns the equivalence predicated use by <var class="var">hashtable</var>. This
|
||
|
procedure returns <code class="code">eq?</code> and <code class="code">eqv?</code>, respectively, for hash
|
||
|
tables created by <code class="code">make-eq-hashtable</code> and
|
||
|
<code class="code">make-eqv-hashtable</code>.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_002dhash_002dfunction"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-hash-function</strong> <var class="def-var-arguments">hashtable</var><a class="copiable-link" href="#index-hashtable_002dhash_002dfunction"> ¶</a></span></dt>
|
||
|
<dd><p>Returns the hash function used by <var class="var">hashtable</var>. For hash tables
|
||
|
created by <code class="code">make-eq-hashtable</code> or <code class="code">make-eqv-hashtable</code>,
|
||
|
<code class="code">#f</code> is returned.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-hashtable_002dmutable_003f"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">hashtable-mutable?</strong> <var class="def-var-arguments">hashtable</var><a class="copiable-link" href="#index-hashtable_002dmutable_003f"> ¶</a></span></dt>
|
||
|
<dd><p>Returns <code class="code">#t</code> if <var class="var">hashtable</var> is mutable, <code class="code">#f</code> otherwise.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<p>A number of hash functions are provided for convenience:
|
||
|
</p>
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-equal_002dhash"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">equal-hash</strong> <var class="def-var-arguments">obj</var><a class="copiable-link" href="#index-equal_002dhash"> ¶</a></span></dt>
|
||
|
<dd><p>Returns an integer hash value for <var class="var">obj</var>, based on its structure and
|
||
|
current contents. This hash function is suitable for use with
|
||
|
<code class="code">equal?</code> as an equivalence function.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-string_002dhash-2"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">string-hash</strong> <var class="def-var-arguments">string</var><a class="copiable-link" href="#index-string_002dhash-2"> ¶</a></span></dt>
|
||
|
<dt class="deffnx def-cmd-deffn" id="index-symbol_002dhash-1"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">symbol-hash</strong> <var class="def-var-arguments">symbol</var><a class="copiable-link" href="#index-symbol_002dhash-1"> ¶</a></span></dt>
|
||
|
<dd><p>These procedures are identical to the ones provided by Guile’s core
|
||
|
library. See <a class="xref" href="Hash-Table-Reference.html">Hash Table Reference</a>, for documentation.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
<dl class="first-deffn">
|
||
|
<dt class="deffn" id="index-string_002dci_002dhash-1"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">string-ci-hash</strong> <var class="def-var-arguments">string</var><a class="copiable-link" href="#index-string_002dci_002dhash-1"> ¶</a></span></dt>
|
||
|
<dd><p>Returns an integer hash value for <var class="var">string</var> based on its contents,
|
||
|
ignoring case. This hash function is suitable for use with
|
||
|
<code class="code">string-ci=?</code> as an equivalence function.
|
||
|
</p></dd></dl>
|
||
|
|
||
|
</div>
|
||
|
<hr>
|
||
|
<div class="nav-panel">
|
||
|
<p>
|
||
|
Next: <a href="rnrs-enums.html">rnrs enums</a>, Previous: <a href="rnrs-syntax_002dcase.html">rnrs syntax-case</a>, Up: <a href="R6RS-Standard-Libraries.html">R6RS Standard Libraries</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
</body>
|
||
|
</html>
|