fast insertion and search - STL

V

Vince

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.
 
V

Victor Bazarov

Vince said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top