page233.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 44 行
HTML
44 行
<HTML><HEAD><TITLE>__init__, __len__ and purge Methods</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="tex2html3888" HREF="page234.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3886" HREF="page231.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3880" HREF="page232.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html3890" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION008512000000000000000"><tt>__init__</tt>, <tt>__len__</tt> and <tt>purge</tt> Methods</A></H3><P>Program <A HREF="page233.html#progchainedScatterTableb"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the<tt>__init__</tt>, <tt>__len__</tt> and <tt>purge</tt> methods ofthe <tt>ChainedScatterTable</tt> class.In addition to <tt>self</tt>.the <tt>__init__</tt> method takes a single argumentwhich specifies the size of scatter table desired.It creates an array of the desired lengthand initializes each element of the array by assigning to itan new <tt>Entry</tt> instance.Consequently, the running time for the <tt>ChainedScatterTable</tt><tt>__init__</tt> method is <I>O</I>(<I>M</I>) where <I>M</I> is the size of the scatter table.<P><P><A NAME="11957"> </A><A NAME="progchainedScatterTableb"> </A> <IMG WIDTH=575 HEIGHT=332 ALIGN=BOTTOM ALT="program11850" SRC="img956.gif" ><BR><STRONG>Program:</STRONG> <tt>ChainedScatterTable</tt> class <tt>__init__</tt>, <tt>__len__</tt> and <tt>purge</tt> methods.<BR><P><P>The <tt>__len__</tt> method returns the lengthof the <tt>_array</tt> instance attribute.Clearly, its running time is <I>O</I>(1).<P>The <tt>purge</tt> method empties the scatter tableby assigning null values to each entry in the table.the time required to purge the scatter table is <I>O</I>(<I>M</I>),where <I>M</I> is the length of the table.<P><HR><A NAME="tex2html3888" HREF="page234.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3886" HREF="page231.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3880" HREF="page232.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html3890" 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 + -
显示快捷键?