CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2007
    Location
    london
    Posts
    247

    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.

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: data structre for phone book

    You could use a boost::bimap<std::string, std::string>.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  4. #4
    Join Date
    Jul 2007
    Location
    london
    Posts
    247

    Arrow Re: data structre for phone book

    Quote Originally Posted by Lindley View Post
    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

  5. #5
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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
  •  





Click Here to Expand Forum to Full Width

Featured