473,386 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

operation signatures for a dictionary type

Hi all,

Suppose I want to implement a dictionary data structure of some kind,
say using a simple BST. I'm wondering how to express the basic
operations in the nicest manner. Especially the operations FIND, INSERT
and DELETE. I'm aware of the way STL does it, but I don't want to use
iterators.

The dictionary has a key/value structure:

template <class KEY_T, class DATA_T>
class bstree
....
....

My operations are declared as follows:

// Try to find the key in the tree. If found, a pointer
// to the data is returned, else 0 is returned
//
const DATA_T* bstree::find(const KEY_T& key)

// Insert a new key/data pair into the tree.
// True is returned if such a key already existed (and
// was replaced), false otherwise
//
bool bstree::insert(const KEY_T& key, const DATA_T& data)

// Remove a key from the tree. True is returned if such
// a key was found (and removed), false otherwise
//
bool bstree::remove(const KEY_T& key)

My biggest concern is with "find", naturally, because it
returns a pointer to the data. I couldn't use a reference
because I want to be able to test via the return value also
whether the element was found at all (now just testing the
pointer with 0).

I know there are several ways to implement it, but I wonder
at what's the best. I could, for instance, make it:

bool bstree::find(const KEY_T& key, DATA_T& data)

And return true (and fill the data) if found, false otherwise.
But this seems more cluttered to me - first because the caller
has to pass another argument, and second because it's unclear
what to place in "data" if nothing is found.

As I mentioned, STL solves these problems by using iterators.
But I want an implementation without iterators, so a constant
pointer seems like the safest way (my dictionary "owns" the
memory for the key/data, just like STL's containers do).

Any ideas ?

Thanks in advance
Eli
Jul 22 '05 #1
0 1346

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

Similar topics

5
by: Paul Moore | last post by:
I can't find anything which spells this out in the manuals. I guess that, at some level, the answer is "a single bytecode operation", but I'm not sure that explains it for me. This thought was...
1
by: I am dog | last post by:
Hi , I use VS 2005 beta1 to do some thing as follows. declare a Dictionary<ulong,DelegateTyep> dictionary = new ... and use dictionary object such as dictionary += aDelegateTyepObject;
2
by: ESPNSTI | last post by:
Hi, I'm trying to use a generics dictionary with a key class that implements and needs IComparable<>. However when I attempt to use the dictionary, it doesn't appear to use the IComparable<> to...
7
by: Robert McCall | last post by:
Greetings All, Does anyone have any idea why a method signature does not include the return type? Example: int someFct( int a, int b ); is the same signature as
1
by: Martin Widmer | last post by:
Hi Folks. When I iterate through my custom designed collection, I always get the error: "Unable to cast object of type 'System.Collections.DictionaryEntry' to type...
4
by: Bill Woodruff | last post by:
< note : this message was sparked in part by comments by David Browne on a previous thread : "inserting an anonymous method as a value in a generic dictionary ?" : David had shown the use of...
3
by: wildThought | last post by:
If I have an object that contains a generic dictionary inside of it, how do I get access to its properties such as count?
0
digicrowd
by: digicrowd | last post by:
http://bytes.com/images/howtos/applemail_sig_icon.jpg At first glance, it may not appear that Apple Mail (otherwise known as Mail.app) supports the use of HTML signature emails. However, with a...
1
by: sachin2 | last post by:
I am using 3 types of dictionaries. 1) Dictionary<string, string > d = new Dictionary<string, string>(); 2) Dictionary<string, List<string>> d = new Dictionary<string, List<string>>(); 3)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.