📄 page333.html
字号:
<HTML><HEAD><TITLE>__init__ Method and m Property</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="tex2html5034" HREF="page334.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5032" HREF="page331.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5026" HREF="page332.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html5036" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0010612000000000000000"><tt>__init__</tt> Method and <tt>m</tt> Property</A></H3><P>Program <A HREF="page332.html#progmWayTreea"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the <tt>__init__</tt> methodand the <tt>m</tt> property of the <tt>MWayTree</tt> class.In addition to <tt>self</tt>,the <tt>__init__</tt> method takes a single, integer-valued argumentthat specifies the desired value of <I>M</I>.Provided <I>M</I> is greater than or equal to two,the <tt>__init__</tt> method creates two arrays,on of length <I>M</I>-1 and the other of length <I>M</I>.Note, a node in an <I>M</I>-way tree contains at most <I>M</I>-1 keys.In the implementation shown, <tt>key[0]</tt> is never used.Because the <tt>__init__</tt> method allocates arrays of length <I>M</I>-1 and <I>M</I>,its worst-case running time is <I>O</I>(<I>M</I>).<P>The <tt>m</tt> property shown in Program <A HREF="page332.html#progmWayTreea"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>invokes the <tt>getM</tt> method to return the value of <I>M</I>.That is, it returns the maximum number of subtrees that a node isallows to have.This is simply given by the length of the <tt>_subtree</tt> array.The running time of this property is clearly <I>O</I>(1).<P><HR><A NAME="tex2html5034" HREF="page334.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5032" HREF="page331.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5026" HREF="page332.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html5036" 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -