fast insertion and search - STL

Discussion in 'C++' started by Vince, Jan 31, 2005.

  1. Vince

    Vince Guest

    Hi,

    I would like to know how can I build a structure or an object to quickly
    reference the following information :

    I need to associate a unique identifier with a list of records
    ex :

    ----------
    id: 0x17 |
    rec:1,2,3 |
    ----------

    ----------
    id: 0x18 |
    rec:2 |
    ----------

    or maybe it is faster to have a list and to do that

    ----------
    id: 0x17 |
    rec:1 |
    ----------

    ----------
    id: 0x17 |
    rec:2 |
    ----------

    ----------
    id: 0x17 |
    rec:3 |
    ----------

    ----------
    id: 0x18 |
    rec:2 |
    ----------


    What kind of container would you use ?
    And I would like to be able to write: obj.AddItem(id, rec);//This method
    add a new id,rec if it doesn't already exist.

    I was thinking of this : map<int, list<int> updateList;


    Sorry for this newbie question.
     
    Vince, Jan 31, 2005
    #1
    1. Advertising

  2. Vince wrote:
    > I would like to know how can I build a structure or an object to quickly
    > reference the following information :
    >
    > I need to associate a unique identifier with a list of records
    > ex :
    >
    > ----------
    > id: 0x17 |
    > rec:1,2,3 |
    > ----------
    >
    > ----------
    > id: 0x18 |
    > rec:2 |
    > ----------
    >
    > or maybe it is faster to have a list and to do that
    >
    > ----------
    > id: 0x17 |
    > rec:1 |
    > ----------
    >
    > ----------
    > id: 0x17 |
    > rec:2 |
    > ----------
    >
    > ----------
    > id: 0x17 |
    > rec:3 |
    > ----------
    >
    > ----------
    > id: 0x18 |
    > rec:2 |
    > ----------
    >
    >
    > What kind of container would you use ?
    > And I would like to be able to write: obj.AddItem(id, rec);//This method
    > add a new id,rec if it doesn't already exist.
    >
    > I was thinking of this : map<int, list<int> updateList;


    map<int, set<int> > might be a bit more robust if the record numbers
    have to be unique, but the list should work well too. If you want to
    keep pairs, you should look at multimap<int,int>.

    V
     
    Victor Bazarov, Jan 31, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kushal
    Replies:
    2
    Views:
    6,277
    tom_usenet
    Jan 30, 2004
  2. OMouse
    Replies:
    6
    Views:
    382
    Andre Kostur
    Aug 18, 2005
  3. Raider
    Replies:
    4
    Views:
    488
    Raider
    Feb 24, 2006
  4. Juha Nieminen
    Replies:
    22
    Views:
    1,078
    Kai-Uwe Bux
    Oct 12, 2007
  5. Ole Nielsby
    Replies:
    1
    Views:
    1,209
    Ole Nielsby
    Dec 29, 2008
Loading...

Share This Page