This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [GSoC] Question about std::map


On 7 July 2014 12:08, Tobias Grosser wrote:
>
> The number of elements in these maps is most likely between 3-10.

Then std::map is the wrong solution.

The overhead of dereferencing all the pointers while walking through a
std::map will be higher than the savings you get from logarithmic
lookup.

For ten elements a linear search of a std::vector will probably be
quicker than lookup in a std::map. A binary search of a sorted vector
(which needs no pointer-chasing because it uses random-access
iterators) will definitely be faster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]