CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    58

    which std container to choose

    hi,

    i have a pile of data, which i need to access frequently and fast.
    One entry consists of two unsigned ints, let`s call them source and destination.

    One source can have several destinations, but this rarely ever happens.
    Several sources can have the same destination - this happens more frequently, but still scarcely.

    Once the data is set up, it rarely ever changes - yet it should be possible to add or remove entries.

    I now need to find all sources for a given destination, or all destinations for a given source.
    The question: which stl container to choose?

    I have tried a multimap, using the source as key. This works good for finding all d for a given s, but is inefficient in the other direction.
    Do you think it would be more efficient to have two multimaps, sorted respectively by source and destination?

  2. #2
    Join Date
    May 2009
    Posts
    2,413

    Re: which std container to choose

    Quote Originally Posted by tuli View Post
    Do you think it would be more efficient to have two multimaps, sorted respectively by source and destination?
    I would have one unordered_map with source as key, each key associated with a vector of destinations. Then I would have another unordered_map with destination as key, each key associated with a vector of sources.

    Using std::unordered_map and std::vector like this would be very fast and flexible.
    Last edited by nuzzle; September 17th, 2012 at 05:07 AM.

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