Data structure with auto-increment field

M

Michele 'xjp'

Hi,
I need a data structure (better if in STL) what give me:
- an auto generated auto-increment integer field ('id')
- various string fields

This structure data must be searchable: I must be able to search any of
the fields using a string (or a int if I search the 'id').
This is equal to a record in a database, with the searchable property.

To implement this, I was thinking to use STL's map<int, container>
The container is a structure data (defined by me) that contains the
various string fields. The key of the STL's map will be the number of
the times that I call map.insert(). The container itself contains also
the 'id'.

What do you think about this?
I am not sure that the container in the map will be searchable by his
fields.

Is there any way to do this in a better way?

Thanks
 
?

=?ISO-8859-15?Q?Erik_Wikstr=F6m?=

Hi,
I need a data structure (better if in STL) what give me:
- an auto generated auto-increment integer field ('id')
- various string fields

This structure data must be searchable: I must be able to search any of
the fields using a string (or a int if I search the 'id').
This is equal to a record in a database, with the searchable property.

To implement this, I was thinking to use STL's map<int, container>
The container is a structure data (defined by me) that contains the
various string fields. The key of the STL's map will be the number of
the times that I call map.insert(). The container itself contains also
the 'id'.

I'd probably create a struct that contains the data you want and then
push_back them into a std::vector, then the index will be the ID you are
looking for and finding a record by id is O(1), to search by a string
you have to create your own comparator (or loop over all elements), this
will take O(n) unless they are inserted in some sorted order in which
case it'll be O(log n).
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top