-
February 21st, 2009, 06:16 PM
#1
data structre for phone book
i'll be honest i don't really know much about data structures and think i might be over complicating this
(note that i can't use tr1::shared_ptr)
i need to be able to lookup every number associated with a name
i also need to be able to lookup every name associated with a number
so i figured that the best thing for this was something like this
Code:
struct name{
std::string value_;
};
struct number{
std::string value_;
};
std::multimap<name*,number*> name_map_;
std::multimap<numner*,name*> number_map_;
the first template argument can be thought of a ownership handle, whilst the second one can be thought of as a simple ptr
Code:
std::multimap<std::tr1::shared_ptr<name>,number*>
anyway this is for a unix command like phone number program i'm writing
Last edited by g3RC4n; February 21st, 2009 at 06:22 PM.
-
February 21st, 2009, 10:09 PM
#2
Re: data structre for phone book
I don't see any particular reason for those wrapper structs unless you plan to have other data in there which you aren't telling us about. Also, there's no particular reason you need to get pointers involved at all here.
-
February 22nd, 2009, 03:56 AM
#3
Re: data structre for phone book
You could use a boost::bimap<std::string, std::string>.
-
February 24th, 2009, 08:21 PM
#4
Re: data structre for phone book
Originally Posted by Lindley
I don't see any particular reason for those wrapper structs unless you plan to have other data in there which you aren't telling us about. Also, there's no particular reason you need to get pointers involved at all here.
it makes it explicit what they are
void add(const name& name_, const number& number_);
not ambiguous
-
February 24th, 2009, 08:27 PM
#5
Re: data structre for phone book
Usually the variable name is quite enough to make it clear what they are. The type is supposed to give other information, such as, well, the actual type of data.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|