1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Issues/iss191_w.htm
2024-04-01 10:24:07 +02:00

164 lines
9.9 KiB
HTML

<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Issue HASH-TABLE-TESTS Writeup</TITLE>
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
<LINK REL=TOP HREF="../Front/index.htm">
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
<LINK REL=PREV HREF="../Issues/iss190_w.htm">
<LINK REL=UP HREF="../Issues/iss191.htm">
<LINK REL=NEXT HREF="../Issues/iss192_w.htm">
</HEAD>
<BODY>
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="../Issues/iss190_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss191.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss192_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue HASH-TABLE-TESTS Writeup</H2>
<PRE><B>Status:</B> Passed, Jan 89 X3J13<P>
<B>Issue:</B> <A HREF="iss191.htm">HASH-TABLE-TESTS</A><P>
<P>
<B>References:</B> CLtL, p382 (third paragraph), and p383<P>
Issue <A HREF="iss143.htm">EQUAL-STRUCTURE</A><P>
Requires Issue: <A HREF="iss086.htm">CONTAGION-ON-NUMERICAL-COMPARISONS</A><P>
<P>
<B>Category:</B> Addition<P>
<P>
<B>Edit history:</B> 26-Sep-88 Version 1 by JonL<P>
8-Dec-88 Version 2 by Masinter<P>
<P>
<B>Problem Description:<P>
</B><P>
A great many users try to coalesce two equivalent <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> instances,<P>
or two equivalent pointer arrays, using hash tables; but they are rudely<P>
awakened when they find out that <A REL=DEFINITION HREF="../Body/f_equal.htm#equal"><B>EQUAL</B></A> is not an appropriate test for<P>
this case, and that there is no :test argument to <A REL=DEFINITION HREF="../Body/f_mk_has.htm#make-hash-table"><B>MAKE-HASH-TABLE</B></A> which <P>
will &quot;hash on non-tree structures&quot;.<P>
<P>
Proposal: <A HREF="iss191.htm">HASH-TABLE-TESTS:ADD-EQUALP</A><P>
<P>
With the advent of the issue <A HREF="iss086.htm">CONTAGION-ON-NUMERICAL-COMPARISONS</A>, we<P>
can expect <A REL=DEFINITION HREF="../Body/f_equalp.htm#equalp"><B>EQUALP</B></A> to be a true equivalence function, and thus a suitable<P>
candidate for the :test function to <A REL=DEFINITION HREF="../Body/f_mk_has.htm#make-hash-table"><B>MAKE-HASH-TABLE</B></A>. Hash-tables will <P>
come in four kinds, the difference being whether the keys are compared <P>
with <A REL=DEFINITION HREF="../Body/f_eq.htm#eq"><B>EQ</B></A>, <A REL=DEFINITION HREF="../Body/a_eql.htm#eql"><B>EQL</B></A>, <A REL=DEFINITION HREF="../Body/f_equal.htm#equal"><B>EQUAL</B></A>, or <A REL=DEFINITION HREF="../Body/f_equalp.htm#equalp"><B>EQUALP</B></A>.<P>
<P>
<P>
<B>Examples:<P>
</B><P>
&gt; (<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> foo a b c)<P>
FOO<P>
&gt; (<A REL=DEFINITION HREF="../Body/s_setq.htm#setq"><B>setq</B></A> x (make-foo :a 1 :b 'b :c '(1 . 2))<P>
x-copy (make-foo :a 1 :b 'b :c '(1 . 2)))<P>
#S(FOO A 1 B B C (1 . 2))<P>
&gt; (<A REL=DEFINITION HREF="../Body/s_setq.htm#setq"><B>setq</B></A> y #(1 B (1 . 2))<P>
y-copy (<A REL=DEFINITION HREF="../Body/f_cp_seq.htm#copy-seq"><B>copy-seq</B></A> y))<P>
#(1 B (1 . 2))<P>
&gt; (<A REL=DEFINITION HREF="../Body/s_setq.htm#setq"><B>setq</B></A> ht-equal (<A REL=DEFINITION HREF="../Body/f_mk_has.htm#make-hash-table"><B>make-hash-table</B></A> :test 'equal) <P>
ht-equalp (<A REL=DEFINITION HREF="../Body/f_mk_has.htm#make-hash-table"><B>make-hash-table</B></A> :test '<A REL=DEFINITION HREF="../Body/f_equalp.htm#equalp"><B>equalp</B></A>))<P>
<P>
#&lt;Hash-Table BB1F7B&gt;<P>
&gt; (<A REL=DEFINITION HREF="../Body/s_progn.htm#progn"><B>progn</B></A> (<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A> (<A REL=DEFINITION HREF="../Body/f_gethas.htm#gethash"><B>gethash</B></A> x ht-equal) t) (<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A> (<A REL=DEFINITION HREF="../Body/f_gethas.htm#gethash"><B>gethash</B></A> x ht-equalp) t) <P>
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A> (<A REL=DEFINITION HREF="../Body/f_gethas.htm#gethash"><B>gethash</B></A> y ht-equal) t) (<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A> (<A REL=DEFINITION HREF="../Body/f_gethas.htm#gethash"><B>gethash</B></A> y ht-equalp) t))<P>
T<P>
&gt; (<A REL=DEFINITION HREF="../Body/f_gethas.htm#gethash"><B>gethash</B></A> x-copy ht-equal)<P>
<A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A><P>
<A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A><P>
&gt; (<A REL=DEFINITION HREF="../Body/f_gethas.htm#gethash"><B>gethash</B></A> x-copy ht-equalp)<P>
T<P>
T<P>
&gt; (<A REL=DEFINITION HREF="../Body/f_gethas.htm#gethash"><B>gethash</B></A> y-copy ht-equal)<P>
<A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A><P>
<A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A><P>
&gt; (<A REL=DEFINITION HREF="../Body/f_gethas.htm#gethash"><B>gethash</B></A> (<A REL=DEFINITION HREF="../Body/f_cp_seq.htm#copy-seq"><B>copy-seq</B></A> y) ht-equalp)<P>
T<P>
T<P>
&gt; <P>
<P>
<P>
<B>Rationale: <P>
</B><P>
Implementing hash-tables efficiently is not an easy task; it makes more<P>
sense for this to be standardly available than for individual programmers <P>
to keep trying to re-invent this obscure part of technology.<P>
<P>
<P>
<B>Current Practice:<P>
</B><P>
Lucid's release 3.0 implements this proposal [some 2.1-level release<P>
supported it &quot;provisionally&quot;]. Symbolics implementation is reputed<P>
to be robust enough to implement this proposal trivially.<P>
<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
Moderate. Implementors have already dealt with EQUAL; the only tricky <P>
part will be ensuring the implication:<P>
&quot;If 'a' is <A REL=DEFINITION HREF="../Body/f_equalp.htm#equalp"><B>EQUALP</B></A> to 'b', then 'a' and 'b' must lie in the<P>
same collision chain in any given <A REL=DEFINITION HREF="../Body/f_equalp.htm#equalp"><B>EQUALP</B></A> hash table&quot;<P>
It has been suggested that merely linear searching a table is an acceptable<P>
implementation technique for CL's hash-tables [although no serious <P>
implementation limits itself thus] and that such tables have no &quot;collision <P>
chains&quot;; but in fact, this is the degenerate case wherein all entries are <P>
in the same collision chain, so the implication is trivially satisfied.<P>
<P>
Some persons prefer to say that the &quot;reprobe sequence will be the same for<P>
the two items&quot;, rather than using the term &quot;collision chain&quot;; the meaning <P>
is the same. <P>
<P>
<P>
<P>
<B>Cost to Users:<P>
</B><P>
None. This is an entirely upwards-compatible addition.<P>
<P>
<P>
<B>Cost of non-adoption:<P>
</B><P>
Continuing bug reports from users about why &quot;hashing <P>
doesn't work&quot; when said user tries entering pointer-containing objects<P>
other than cons cells into hash tables. Continuing delay in same<P>
user's work until they figure out a new strategy for identifying<P>
equivalent structures. More difficulty in debugging their alternatives.<P>
<P>
<P>
<B>Benefits:<P>
</B><P>
Addresses one aspect of the difficult equivalence problem. Makes<P>
hash tables more useful. Permits case-insensitive hashing<P>
on strings [tables of type <A REL=DEFINITION HREF="../Body/f_equal.htm#equal"><B>EQUAL</B></A> are case-sensitive on strings]; <P>
another use is to allow = comparison for numbers<P>
[tables of type <A REL=DEFINITION HREF="../Body/f_equal.htm#equal"><B>EQUAL</B></A> use <A REL=DEFINITION HREF="../Body/a_eql.htm#eql"><B>EQL</B></A> on numbers].<P>
<P>
<P>
<B>Aesthetics:<P>
</B><P>
Reduces the discontinuity between basic equivalence functions and those<P>
usable as equivalence relations in hash-tables.<P>
<P>
<P>
<B>Discussion:<P>
</B><P>
With the rejection of all the issues related to <A HREF="iss143.htm">EQUAL-STRUCTURE</A>, there is <P>
little or no hope that <A REL=DEFINITION HREF="../Body/f_equal.htm#equal"><B>EQUAL</B></A> will be &quot;beefed up&quot; to meet the expectations<P>
of so many of the user community on compound structures. If one wants<P>
a <A REL=DEFINITION HREF="../Body/t_hash_t.htm#hash-table"><B>hash-table</B></A> with a :test function that has fewer equivalence classes <P>
(i.e., does more &quot;coalescing&quot;), then there is no alternative now except <P>
to use the function <A REL=DEFINITION HREF="../Body/f_equalp.htm#equalp"><B>EQUALP</B></A>.<P>
<P>
It would also be possible to extend hash tables to allow = or<P>
<A REL=DEFINITION HREF="../Body/f_stgeq_.htm#stringEQ"><B>STRING=</B></A>, but those are not being proposed at this time.<P>
</PRE>
<HR>
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
</BODY>
</HTML>