474,015 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BTree implementation - take 2

I took the advice from the group and got rid of the node accessor functions
and arrived at this definition. I have not added the copy
constructor/assignment operators to this class yet.

template <class TYPE, class ARG_TYPE = const TYPE&>
class CBTree : public CObject
{
// Constructors
public:
CBTree();
// Attributes
public:
int GetCount() const;
// Operations
public:
BOOL Insert(ARG_TYPE newElement);
BOOL Remove(ARG_TYPE element);
void RemoveAll();
BOOL Find(ARG_TYPE element);
// Implementation
public:
virtual ~CBTree();
};

I think this looks a little bit better then last time, but a question about
the "Find" function and the iterator stuff. I know the STL and OO devotees
will probably recommend I have the iterator as a seperate object, but as
this is an MFC class, I am being pushed into wrapping everything into one
simple to use class. Looking at other examples of template/MFC classes, they
use a POSITION object which is essentially a, yes, you guessed it, arbitrary
position pointer variable.

So I might change the Find method to:

POSITION Find(ARG_TYPE element) const;

where POSITION would be NULL if the element is not found. Otherwise it would
be an internal representation of the position, such as the pointer to the
node, similarly I could have a function:

POSITION GetRoot() const;

Now several of you suggested hiding the implementation from the user, so
does it make sense to have functions like:

POSITION GetNext(POSITIO N& pos, left/right);

or maybe something that returns the element at the same time? such as:

POSITION GetNext(POSITIO N& pos, left/right, ARG_TYPE element);

or maybe a

ARG_TYPE GetElement(POSI TION& pos);

type function instead?

ie, how can I phrase the navigation functions while hiding the node details
from the user? Have GetLeft and GetRight and GetParent functions seem to be
exposing details of the implementation.
Jul 22 '05 #1
2 3303
Nobody wrote:
I took the advice from the group and got rid of the node accessor functions
and arrived at this definition. I have not added the copy
constructor/assignment operators to this class yet.

template <class TYPE, class ARG_TYPE = const TYPE&>
class CBTree : public CObject
{
// Constructors
public:
CBTree();
// Attributes
public:
int GetCount() const;
// Operations
public:
BOOL Insert(ARG_TYPE newElement);
BOOL Remove(ARG_TYPE element);
void RemoveAll();
BOOL Find(ARG_TYPE element);
// Implementation
public:
virtual ~CBTree();
};

I think this looks a little bit better then last time, but a question about
the "Find" function and the iterator stuff. I know the STL and OO devotees
will probably recommend I have the iterator as a seperate object, but as
this is an MFC class, I am being pushed into wrapping everything into one
simple to use class. Looking at other examples of template/MFC classes, they
use a POSITION object which is essentially a, yes, you guessed it, arbitrary
position pointer variable.

So I might change the Find method to:

POSITION Find(ARG_TYPE element) const;

where POSITION would be NULL if the element is not found. Otherwise it would
be an internal representation of the position, such as the pointer to the
node, similarly I could have a function:

POSITION GetRoot() const;

Now several of you suggested hiding the implementation from the user, so
does it make sense to have functions like:

POSITION GetNext(POSITIO N& pos, left/right);

or maybe something that returns the element at the same time? such as:

POSITION GetNext(POSITIO N& pos, left/right, ARG_TYPE element);

or maybe a

ARG_TYPE GetElement(POSI TION& pos);

type function instead?

ie, how can I phrase the navigation functions while hiding the node details
from the user? Have GetLeft and GetRight and GetParent functions seem to be
exposing details of the implementation.


How about iterators?
A "for_each" method.
Check out the SGI STL website and read the definitions
of containers.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Jul 22 '05 #2
[snip]
Now several of you suggested hiding the implementation from the user, so
does it make sense to have functions like:

POSITION GetNext(POSITIO N& pos, left/right);

or maybe something that returns the element at the same time? such as:

POSITION GetNext(POSITIO N& pos, left/right, ARG_TYPE element);

or maybe a

ARG_TYPE GetElement(POSI TION& pos);

type function instead?

ie, how can I phrase the navigation functions while hiding the node details from the user? Have GetLeft and GetRight and GetParent functions seem to be exposing details of the implementation.


Separate methods for separate concepts. I would have

POSITION GetNext(const POSITION& pos);

POSITION GetPrevious(con st POSITION& pos);

ARG_TYPE GetElement(cons t POSITION& pos);

john
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1274
by: Jane Austine | last post by:
Hello. How do I change the BTree sorting order with bsddb, instead of the default lexicographical order? After studying sleepycat's document, I found there is a function call for setting the compare callback, set_bt_compare. It even seems like got into pybsddb patch list (http://sourceforge.net/tracker/index.php?func=detail&aid=532308&group_id=13900&atid=313900). However, the current Python source tree (cvs) doesn't include the patch.
5
2075
by: Nobody | last post by:
I am trying to write a BTree class, just wondering if I missed any useful methods. This is my class definition so far (excuse the MFC portions, its a project requirement): template <class TYPE, class ARG_TYPE = const TYPE&> class CBTree : public CObject {
4
5258
by: Eloff | last post by:
I've got 100MB of urls organized by domain and then by document. I thought that a hastable of hastables or a btree of btrees would be a good way to lookup a specific url quickly by first finding the domain and then finding the matching document. What do you think would be better? And do you have any implementation you recommend? Thanks, and merry Christmas folks. -Dan
4
2198
by: Spam Me Please | last post by:
I have a tree like this struct BTree{ int left; char c; int right; }; #define END -1 int main(int argc, char *argv)
2
2580
by: Mark Harrison | last post by:
I create a table like so: create table types ( typeid integer unique not null, typename varchar(255) unique not null ); and I get the expected messages: NOTICE: CREATE TABLE / UNIQUE will create implicit index 'types_typeid_key' for table 'types'
4
3126
by: os2 | last post by:
hi i would like to catalog my hd and put the data in a btree somebody know how to do it? a hint to begin? thanks
1
3149
by: Brian Maguire | last post by:
Can too many btree indexes cause page level locking? I read this... http://www.postgresql.org/docs/7.4/static/locking-indexes.html
0
2264
by: Rano | last post by:
Hi could u guys look at this assignment sheet and try to help me to display the Btree in this form by using x and y coordinate plzzzzzzz help 10 3 11 2 4
0
1303
by: sudhi nair | last post by:
hi dba's i want an automated script for converting btree index (with less cardinality) to bitmap index bcoz old version is 10g std edition now migration to 10g enterp edition any body know pls post regads
0
10282
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11541
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11838
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
11053
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7766
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6571
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
5315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.