page245.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 55 行
HTML
55 行
<HTML><HEAD><TITLE>Finding Items</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="tex2html4025" HREF="page246.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4023" HREF="page242.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4017" HREF="page244.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html4027" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION008643000000000000000">Finding Items</A></H3><P>The <tt>find</tt> and <tt>findMatch</tt> methodsof the <tt>OpenScatterTable</tt> class are definedin Program <A HREF="page245.html#progopenScatterTabled"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.In addition to <tt>self</tt>,the <tt>findMatch</tt> method takes an objectand searches the scatter table for an object which matches the given one.<P><P><A NAME="13662"> </A><A NAME="progopenScatterTabled"> </A> <IMG WIDTH=575 HEIGHT=409 ALIGN=BOTTOM ALT="program13385" SRC="img1006.gif" ><BR><STRONG>Program:</STRONG> <tt>OpenScatterTable</tt> class <tt>findMatch</tt> and <tt>find</tt> methods.<BR><P><P><tt>findMatch</tt> follows the same probing sequenceused by the <tt>insert</tt> method.Therefore, if there is a matching object in the scatter table,<tt>findMatch</tt> will make exactly the same number of probesto locate the object as were made to put the object into the tablein the first place.The <tt>findMatch</tt> method makes at most <I>M</I> probes,where <I>M</I> is the size of the scatter table.However, note that the loop immediately terminatesshould it encounter an <tt>EMPTY</tt> location.This is because if the target has not been found by the timean empty cell is encountered,then the target is not in the table.Notice also that the comparison is only attempted for entries whichare marked <tt>OCCUPIED</tt>.Any locations marked <tt>DELETED</tt> are not examined during the searchbut they do not terminate the search either.<P>The running time of the <tt>find</tt> method is determinedby that of <tt>findMatch</tt>.In the worst case <tt>findMatch</tt> makes <I>n</I> comparisons,where <I>n</I> is the number of items in the table.Therefore, the running time of <tt>find</tt> is <IMG WIDTH=193 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline62571" SRC="img1007.gif" >.<P><HR><A NAME="tex2html4025" HREF="page246.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4023" HREF="page242.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4017" HREF="page244.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html4027" 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 + -
显示快捷键?