By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

fast insertion and search - STL

P: n/a
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.

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.