Home

On Aug 9, 4:42 am, Digital Puer <digital_p...@hotmail.com> wrote:
> [ should I have a set of...]
> struct Foo {
> int key;
> float data1;
> int data2;
> string data3;
> };
> [...or a map of int keys to...]
> struct Foo {
> float data1;
> int data2;
> string data3;};

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

In general, you should use a map when part of the struct data forms
the key, and set when the entire data is the key. Whatever operations
your program starts off doing, programs evolve and choosing a natural
match for your data is a better approach than choosing something
that's perhaps slightly better for the usage start off with, then
having to rewrite everything.

The fact that you want to use find suggests an associative container
is a simply more natural fit than say a sorted vector and binary
search algorithm, and unless profiling shows you need fast population
or iteration, then there's no reason to consider it.

Tony

previous
next

Re: An Editor that Skips to the End of a Def
Re: templated func : what's wrong
Re: handling modules in packages
Re: Is it possible to overload a member variable?
Extending doctest
osuszanie domow
kołdry inter widex
buty do tańca
rtv
producent profili meblowych