D
Digital Puer
Hi, I was wondering whether to use a map or a set for
my purposes.
I am reading rows from a database and am populating a
struct (or class) for each row. It has a key and ancillary
data, e.g.:
struct Foo {
int key;
float data1;
int data2;
string data3;
};
Now I want to keep all the rows in either a map or a set.
If I use a set, I can keep the struct the way it is; the only
thing I need is to provide a comparison function for the set
so that the ordering is based on the key.
On the other hand, if I use a map, I am inclined to break
the key out and use the key as the first part in the map,
e.g.:
struct Foo {
float data1;
int data2;
string data3;
};
map<int, Foo> mydata;
Which approach is preferable for the following cases:
1. My only operations on the data structure are to iterate
over it and to use find().
2. I will iterate over as well as update the data.
my purposes.
I am reading rows from a database and am populating a
struct (or class) for each row. It has a key and ancillary
data, e.g.:
struct Foo {
int key;
float data1;
int data2;
string data3;
};
Now I want to keep all the rows in either a map or a set.
If I use a set, I can keep the struct the way it is; the only
thing I need is to provide a comparison function for the set
so that the ordering is based on the key.
On the other hand, if I use a map, I am inclined to break
the key out and use the key as the first part in the map,
e.g.:
struct Foo {
float data1;
int data2;
string data3;
};
map<int, Foo> mydata;
Which approach is preferable for the following cases:
1. My only operations on the data structure are to iterate
over it and to use find().
2. I will iterate over as well as update the data.