📄 page242.html
字号:
<HTML>
<HEAD>
<TITLE>Constructors and Destructor</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">
<img src="cover75.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cover75.gif" alt="Logo" align=right>
<b>Data Structures and Algorithms
with Object-Oriented Design Patterns in C++</b><br>
<A NAME="tex2html4911" HREF="page243.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page243.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html4909" HREF="page241.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page241.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html4903" HREF="page241.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page241.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html4913" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html4914" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <BR><HR>
<H3><A NAME="SECTION009641000000000000000">Constructors and Destructor</A></H3>
<P>
Program <A HREF="page242.html#proghashtbl8c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page242.html#proghashtbl8c"><IMG ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A> gives the definition of the
default constructor for the <tt>OpenScatterTable::Entry</tt> class.
It shall always be the case that an unoccupied entry will have
its <tt>object</tt> pointer set to zero
and the default state of all entries is initially <tt>empty</tt>.
The default constructor initializes the two
corresponding member variables accordingly.
<P>
<P><A NAME="14298"> </A><A NAME="proghashtbl8c"> </A> <IMG WIDTH=575 HEIGHT=508 ALIGN=BOTTOM ALT="program13956" SRC="img1050.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1050.gif" ><BR>
<STRONG>Program:</STRONG> <tt>OpenScatterTable</tt> Class Constructor and Destructor and <tt>OpenScatterTable::Entry</tt> Class Constructor Definitions<BR>
<P>
<P>
The <tt>OpenScatterTable</tt> constructor takes
a single argument of type <tt>unsigned int</tt>
which specifies the size of scatter table desired.
The constructor initializes the <tt>HashTable</tt> base class
and the <tt>array</tt> member variable as required.
Initializing the <tt>array</tt> variable requires
setting all of the entries to the <tt>empty</tt> state.
Consequently, the running time for the <tt>OpenScatterTable</tt>
constructor is <I>O</I>(<I>M</I>) where <I>M</I> is the size of the scatter table.
<P>
The <tt>OpenScatterTable</tt> destructor calls the <tt>Purge</tt>
member function.
The <tt>Purge</tt> function must delete any contained objects
if the scatter table is the owner of those objects.
The <tt>Purge</tt> function traverses the array looking for occupied
entries and deletes objects as the are found.
If there are <I>n</I> contained objects
and the length of the array is <I>M</I>,
then the running time of the <tt>Purge</tt> function is <IMG WIDTH=137 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline62930" SRC="img1003.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1003.gif" >.
Since <IMG WIDTH=47 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline62202" SRC="img874.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img874.gif" >, if we assume that <IMG WIDTH=120 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline62830" SRC="img977.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img977.gif" >
the running time becomes <I>O</I>(<I>M</I>)<HR><A NAME="tex2html4911" HREF="page243.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page243.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html4909" HREF="page241.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page241.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html4903" HREF="page241.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page241.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html4913" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html4914" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <P><ADDRESS>
<img src="bruno.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/bruno.gif" alt="Bruno" align=right>
<a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html">Copyright © 1997</a> by <a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -