X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libstdc%2B%2B-v3%2Fdoc%2Fhtml%2Fmanual%2Fsequences.html;fp=libstdc%2B%2B-v3%2Fdoc%2Fhtml%2Fmanual%2Fsequences.html;h=00d5255d5dca7141e17b2e4d88620c2f0c2e8278;hb=6fed43773c9b0ce596dca5686f37ac3fc0fa11c0;hp=0000000000000000000000000000000000000000;hpb=27b11d56b743098deb193d510b337ba22dc52e5c;p=msp430-gcc.git diff --git a/libstdc++-v3/doc/html/manual/sequences.html b/libstdc++-v3/doc/html/manual/sequences.html new file mode 100644 index 00000000..00d5255d --- /dev/null +++ b/libstdc++-v3/doc/html/manual/sequences.html @@ -0,0 +1,43 @@ + + +Chapter 16. Sequences

Chapter 16. Sequences

Table of Contents

list
list::size() is O(n)
vector
Space Overhead Management

list

list::size() is O(n)

+ Yes it is, and that's okay. This is a decision that we preserved + when we imported SGI's STL implementation. The following is + quoted from their FAQ: +

+ The size() member function, for list and slist, takes time + proportional to the number of elements in the list. This was a + deliberate tradeoff. The only way to get a constant-time + size() for linked lists would be to maintain an extra member + variable containing the list's size. This would require taking + extra time to update that variable (it would make splice() a + linear time operation, for example), and it would also make the + list larger. Many list algorithms don't require that extra + word (algorithms that do require it might do better with + vectors than with lists), and, when it is necessary to maintain + an explicit size count, it's something that users can do + themselves. +

+ This choice is permitted by the C++ standard. The standard says + that size() “should” be constant time, and + “should” does not mean the same thing as + “shall”. This is the officially recommended ISO + wording for saying that an implementation is supposed to do + something unless there is a good reason not to. +

+ One implication of linear time size(): you should never write +

+         if (L.size() == 0)
+             ...
+	 

+ Instead, you should write +

+         if (L.empty())
+             ...
+