page231.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 80 行
HTML
80 行
<HTML><HEAD><TITLE>Chained Scatter Table</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html3861" HREF="page232.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3859" HREF="page230.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3853" HREF="page230.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html3863" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION008510000000000000000">Chained Scatter Table</A></H2><P>Figure <A HREF="page231.html#fighash2"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> illustrates a<em>chained scatter table</em><A NAME=11412> </A>.The elements of a chained scatter table are ordered pairs.Each array element contains a key and a ``pointer.''All keys are stored in the table itself.Consequently, there is a fixed limit on the number of itemsthat can be stored in a scatter table.<P><P><A NAME="11783"> </A><A NAME="fighash2"> </A> <IMG WIDTH=575 HEIGHT=380 ALIGN=BOTTOM ALT="figure11413" SRC="img947.gif" ><BR><STRONG>Figure:</STRONG> Chained scatter table.<BR><P><P>Since the pointers point to other elements in the array,they are implemented as integer-valued array subscripts.Since valid array subscripts start from the value zero,the <em>null</em> pointer must be represented not as zero,but by an integer value that is outside the array bounds (say -1).<P>To find an item in a chained scatter table,we begin by hashing that item to determine the locationfrom which to begin the search.For example, to find the string <tt>"elva"</tt>,which hashes to the value <IMG WIDTH=80 HEIGHT=20 ALIGN=MIDDLE ALT="tex2html_wrap_inline62279" SRC="img948.gif" >,we begin the search in array location <IMG WIDTH=181 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline62281" SRC="img949.gif" >.The item at that location is <tt>"fyra"</tt>,which does not match.So we follow the pointer in location <IMG WIDTH=13 HEIGHT=20 ALIGN=MIDDLE ALT="tex2html_wrap_inline62283" SRC="img950.gif" >to location <IMG WIDTH=14 HEIGHT=20 ALIGN=MIDDLE ALT="tex2html_wrap_inline62285" SRC="img951.gif" >.The item there, <tt>"fyra"</tt>, does not match either.We follow the pointer again,this time to location <IMG WIDTH=13 HEIGHT=20 ALIGN=MIDDLE ALT="tex2html_wrap_inline62287" SRC="img952.gif" > where we ultimatelyfind the string we are looking for.<P>Comparing Figures <A HREF="page224.html#fighash1"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> and <A HREF="page231.html#fighash2"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,we see that the chained scatter table has embedded withinit the linked lists which appearto be the same as those in the separately chained hash table.However, the lists are not exactly identical.When using the chained scatter table,it is possible for lists to <em>coalesce</em><A NAME=11799> </A>.<P>For example, when using separate chaining,the keys <tt>"tre"</tt> and <tt>"sju"</tt> appear in a separatelist from the key <tt>"tolv"</tt>.This is because both <tt>"tre"</tt> and <tt>"sju"</tt>hash to position <IMG WIDTH=14 HEIGHT=20 ALIGN=MIDDLE ALT="tex2html_wrap_inline62289" SRC="img953.gif" >,whereas <tt>"tolv"</tt> hashes to position <IMG WIDTH=13 HEIGHT=20 ALIGN=MIDDLE ALT="tex2html_wrap_inline62291" SRC="img954.gif" >.The same keys appear together in a single liststarting at position <IMG WIDTH=14 HEIGHT=20 ALIGN=MIDDLE ALT="tex2html_wrap_inline62289" SRC="img953.gif" >in the chained scatter table.The two lists have <em>coalesced</em>.<P><BR> <HR><UL> <LI> <A NAME="tex2html3864" HREF="page232.html#SECTION008511000000000000000">Implementation</A><LI> <A NAME="tex2html3865" HREF="page233.html#SECTION008512000000000000000"><tt>__init__</tt>, <tt>__len__</tt> and <tt>purge</tt> Methods</A><LI> <A NAME="tex2html3866" HREF="page234.html#SECTION008513000000000000000">Inserting and Finding an Item</A><LI> <A NAME="tex2html3867" HREF="page235.html#SECTION008514000000000000000">Removing Items</A><LI> <A NAME="tex2html3868" HREF="page236.html#SECTION008515000000000000000">Worst-Case Running Time</A></UL><HR><A NAME="tex2html3861" HREF="page232.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3859" HREF="page230.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3853" HREF="page230.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html3863" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright © 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?