?? page241.html
字號:
<HTML>
<HEAD>
<TITLE>Implementation</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="tex2html4895" HREF="page242.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page242.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="tex2html4893" HREF="page237.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page237.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="tex2html4887" HREF="page240.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page240.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="tex2html4897" 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="tex2html4898" 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>
<H2><A NAME="SECTION009640000000000000000">Implementation</A></H2>
<P>
This section describes an implementation of a scatter table
using open addressing with linear probing.
Program <A HREF="page241.html#proghashtbl4h" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page241.html#proghashtbl4h"><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> declares the <tt>OpenScatterTable</tt> class.
The scatter table is implemented as an array
of elements of the nested type <tt>Entry</tt>.
Each <tt>Entry</tt> instance has two member variables--<tt>object</tt> and <tt>state</tt>.
The former is a pointer to an <tt>Object</tt> class instance.
The latter is an element of the enumeration <tt>State</tt>.
<P>
<P><A NAME="14289"> </A><A NAME="proghashtbl4h"> </A> <IMG WIDTH=575 HEIGHT=429 ALIGN=BOTTOM ALT="program13915" SRC="img1049.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1049.gif" ><BR>
<STRONG>Program:</STRONG> <tt>OpenScatterTable</tt> Class Definition<BR>
<P>
<P>
Each entry can be in one of three states--<tt>empty</tt>, <tt>occupied</tt>, or <tt>deleted</tt>.
Initially, all entries are empty.
When an object pointer is recorded in an entry,
the state of that entry is changed to <tt>occupied</tt>.
The purpose of the third state, <tt>deleted</tt>,
will be discussed in conjunction with the <tt>Withdraw</tt> function below.
<P>
In addition to the lone member variable <tt>array</tt>,
the <tt>OpenScatterTable</tt> class definition contains
a number of private member function declarations--<tt>C</tt>, <tt>FindUnoccupied</tt>, <tt>FindMatch</tt>, and <tt>FindInstance</tt>.
The member function <tt>C</tt> embodies
the <em>collision resolution strategy</em>
which is this case is linear probing.
The other three member functions encapsulate functionality
which is useful in implementation of the various scatter table operations.
<P>
<BR> <HR>
<UL>
<LI> <A NAME="tex2html4899" HREF="page242.html#SECTION009641000000000000000" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page242.html#SECTION009641000000000000000">Constructors and Destructor</A>
<LI> <A NAME="tex2html4900" HREF="page243.html#SECTION009642000000000000000" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page243.html#SECTION009642000000000000000">Inserting Items</A>
<LI> <A NAME="tex2html4901" HREF="page244.html#SECTION009643000000000000000" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page244.html#SECTION009643000000000000000">Finding Items</A>
<LI> <A NAME="tex2html4902" HREF="page245.html#SECTION009644000000000000000" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page245.html#SECTION009644000000000000000">Removing Items</A>
</UL>
<HR><A NAME="tex2html4895" HREF="page242.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page242.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="tex2html4893" HREF="page237.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page237.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="tex2html4887" HREF="page240.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page240.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="tex2html4897" 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="tex2html4898" 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 + -