473,807 Members | 2,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dictionary design, comments?

I am trying to design a dictionary in such a way that I can
keep the interface and implementation separate. Here is my
initial design. Anyone has any comments on it or suggestions
on how I could make it better.

Does anyone have a good code/pointer that discusses
dictionary design.
Thanks,
--j
template <typename K,
typename I,
class _Compare = std::less<K>,
class dic_impl = my_dict<K,I,_Co mpare> >
class dictionary : public dic_impl {

public:

typedef typename dic_impl::dic_i tem dic_item;
typedef typename dic_impl::const _dic_item const_dic_item;

typedef K key_type;
typedef I inf_type;
dictionary(){ };

virtual ~dictionary(){d ic_impl::clear( );}

const K& key(const_dic_i tem it) const { return dic_impl::key(i t);}
const I& inf(const_dic_i tem it) const { return dic_impl::inf(i t);}
int defined(const K& k) const
{ return (lookup(k) == dic_impl::end() ) ? false : true; }

inline dic_item insert(const K& k, const I& i)
{ return dic_impl::inser t(k,i); }

inline const_dic_item lookup(const K& k) const
{ return dic_impl::looku p(k); }

inline dic_item lookup(const K& k)
{ return dic_impl::looku p(k); }

inline void del(const K& k) { dic_impl::del(k ); }

inline void del_item(dic_it em it) { dic_impl::del_i tem(it); }

void change_inf(dic_ item it, const I& i)
{ dic_impl::chang e_inf(it,i); }

inline void clear() { dic_impl::clear (); }

inline int size() const { return dic_impl::size( ); }

inline bool empty() const { return (size()==0) ? true : false; }

inline const_dic_item begin() const { return dic_impl::begin (); }
inline const_dic_item end() const { return dic_impl::end() ; }

inline dic_item begin() { return dic_impl::begin (); }
inline dic_item end() { return dic_impl::end() ; }

inline const_dic_item succ_item(const _dic_item it) const
{ return dic_impl::succ_ item(it);}
inline const_dic_item pred_item(const _dic_item it) const
{ return dic_impl::pred_ item(it);}

inline dic_item succ_item(dic_i tem it)
{ return dic_impl::succ_ item(it);}
inline dic_item pred_item(dic_i tem it)
{ return dic_impl::pred_ item(it);}
typedef dictionary<K,I, _Compare,dic_im pl> this_type;
}; // end of dictionary
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]
Jul 23 '05 #1
2 1675
Use the bridge pattern.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jul 23 '05 #2
I would use a bridge. You're defining the interface class to be a
subclass of the implementation. Make dic_impl and abstract class and
have your dictionary class aggregate it instead of deriving from it.
You can then derive concrete implementations from the abstract
dic_impl, and the interface can access the implementation
polymorphically .
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]
Jul 23 '05 #3

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

Similar topics

1
1676
by: gyro | last post by:
Hi, I have a collection of objects that I am currently trying to manage. Each object is initialized with a dictionary. The dictionaries have the same keys but may have different values. The initialization process is time consuming, so I don't want to create an object if I have already instantiated one using a dictionary with the 'same' items. I would like to collect the objects in a dictionary with the objects as values and some...
8
2492
by: Benjamin Scott | last post by:
Hello. I attempted to build a compound dictionary: len(Lst)=1000 len(nuerLst)=250 len(nuestLst)=500 Dict={}
36
6414
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but something I'll need in this case is some experience-based set of rules about how to use python in this context. For example... is defining readonly attributes in classes worth the hassle ? Does duck-typing scale well in complex
90
10838
by: Christoph Zwerschke | last post by:
Ok, the answer is easy: For historical reasons - built-in sets exist only since Python 2.4. Anyway, I was thinking about whether it would be possible and desirable to change the old behavior in future Python versions and let dict.keys() and dict.values() both return sets instead of lists. If d is a dict, code like: for x in d.keys():
5
47292
by: Andrew Robinson | last post by:
I need to serialize a dictionary so I can encode the contents. I have the following working but the size seems large. I am guessing that I am serializing the entire object not just the data. Is there a better way? MemoryStream stream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); Dictionary<string, string> dictionary = new Dictionary<string, string>(); dictionary.Add("name", "andrew"); dictionary.Add("home",...
12
1546
by: sandravandale | last post by:
It's important that I can read the contents of the dict without flagging it as modified, but I want it to set the flag the moment I add a new element or alter an existing one (the values in the dict are mutable), this is what makes it difficult. Because the values are mutable I don't think you can tell the difference between a read and a write without making some sort of wrapper around them. Still, I'd love to hear how you guys would do...
1
1891
by: Peter | last post by:
Hi, I have a Dictionary<key, valuewhich is accessed by three threads. One thread puts my value objects in the dictionary (occasionally), and also updates the contents of existing value objects - by finding the appropriate object via a key and updating the value (this updating happens several times a second). Another thread removes "dead" value objects from the dictionary (very occasionally)
8
8002
by: Bob Altman | last post by:
Hi all, I'm trying to do something that should be really easy, but I can't think of an obvious way to do it. I have a dictionary whose value is a "value type" (as opposed to a reference type -- in this case, a Boolean): Dim dic As New Dictionary(Of Int32, Boolean) dic(123) = True I want to set all of the existing entries in the dictionary to False. The
4
1014
by: giddy | last post by:
hi, yet another design question, this one is more simple and maybe a little silly. When it comes to classes like class Person{ string Name; string Address;
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
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
10373
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
10374
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,...
1
7651
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
6880
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();...
1
4331
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
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.