Talk:Map (C++)

message: But "Incrementing/decrementing an iterator takes O(log n) time". Therefore, shouldn't the iteration over all elements be O(n log n)? --Kaba3 (talk) 19:56, 18 January 2008 (UTC)
thread_title:  "Iterating through every element of a map takes O(n) time" ? 

message: This is a very bad example for many reasons.
# "map" is the wrong data structure to use for the problem. One only desired to keep track of who is present, and has no need to keep track of who is not present (presumed to be everyone else). Although a value type (bool) is declared, it is never given a value other than "true", which is redundant. Therefore a "set" is the proper data structure.
# The present[s] uses the [] operator, which is bad. When "s" is not already in the map, it inserts a new element with key "s" and undefined value. This adds useless entries into the map about people who are not present.
I propose to replace the example with a real example where a mapping is used. Perhaps some kind of address book which maps names (string) to their address (another string); and then it prints out all the info in order by name.
--Spoon! 01:23, 7 December 2006 (UTC)
replies: text: I agree with your first point.  I updated the "present" example to instead count words.  This is a more realistic usage that requires map instead of set.  Your second point is incorrect.  While the [] operator does insert a new element with key "s", the value is not undefined; it is defined as 0/false.  While using operator[] does add entries into the map about words that are not there, that is perfectly OK for the purposes of the example because it is correct and it clearly demonstrates that the operator[] inserts pairs with zeros as values. Krelborne (talk) 03:29, 2 January 2008 (UTC)
thread_title:  Bad example 

message: Is it true that integers are initialized to zero and booleans to false?  I'm doubtful.  Can you cite a source for this statement?
MrDizzy 16:25, 20 February 2007 (UTC)
replies: text: This sounds wrong to me, as integers and bools are primitive data types and hence have not default constructor, im "being bold" and killing the comment. 129.78.64.102 06:56, 7 March 2007 (UTC)
thread_title:  Initialization 

message: cout.setf(ios::boolalpha)
The cyan setf and boolalpha against the gray is really difficult for me to read.
Also, Hello, Wikipedia World!  This is my first discussion post.
Juancnuno 20:09, 13 October 2007 (UTC)
thread_title:  Bad Colors 

message: Guys I just wanted to let you know that the code posted 
#include <iostream>
#include <string>
#include <map>
 
using namespace std;
 
int main()
{
    map<string, int> wordcounts;
    string s;
    int count = 1;
 
    while (cin >> s && s != "end")
        wordcounts[s] = count++;
 
    while (cin >> s && s != "end")
        cout << s << ' ' << wordcounts[s] << endl;
}
does not work right and for some strings it just gives meaningless outputs.
And in any case count should first be initialized to 0
Wanted to let you know...  —Preceding unsigned comment added by 128.211.171.92 (talk) 23:01, 26 March 2008 (UTC)
thread_title:  Code Not Working Right 

message: Hi, I am currently considering renaming this article to conform to a common convention for C++ Standard Library components. The full discussion can be found here. decltype 09:45, 6 March 2009 (UTC)
thread_title:  Renaming this article to follow a consistent convention 

message: According to the referenced page 3, those following items:
*Iterating through all elements ( O(n) time )
and
*Copying an entire map ( O(n log n ) time )
It seems, reading the wikipedia sentence that the above items take
O( log n ). Is it a mistake from me ???
Heretik_0127 06 July 2009  —Preceding undated comment added 05:15, 6 July 2009 (UTC)
thread_title:  Performance 

message: Are you sure that statement  "iterators  are not invalidated by insert ***and erase*** operations (...)" is true?
According to spec: "Erasing an element from a map also does not invalidate any iterators, except, of course, for iterators that actually point to the element that is being erased". Also users' experience  show that iterators are invalidated by ::erase().  —Preceding unsigned comment added by 212.2.96.101 (talk) 09:28, 20 May 2010 (UTC)
replies: text: Yes, [t]he erase members shall invalidate only iterators and references to the erased elements. I would think it was obvious that a reference to an object that has been erased from a container would be invalid, but perhaps the sentence needs clarification. decltype (talk) 09:54, 20 May 2010 (UTC)
thread_title:  map::erase() and iterators 

message: "Note that this performance cost applies to each task individually."
No point in noting. 4O(logn) = O(logn), right?  —Preceding unsigned comment added by 194.237.142.7 (talk) 12:10, 4 May 2011 (UTC)
thread_title:  Performance note 

message: There's an ongoing  discussion about an reorganization of the articles about the C++ containers. This page is one of the subjects of that discussion. Please express your opinion. 1exec1 (talk) 20:16, 2 December 2011 (UTC)
thread_title:  Reorganization