stdlist

What makes the gcc std::list sort implementation so fast?

十年热恋 提交于 2019-11-29 18:12:32
问题 I have a linked list implementation and I'm experimenting with both Mergesort and QuickSort algorithms. What I don't understand is why the sort operation in std::list is so fast. Looking at the std::list under linux and it appears to be linked list as well, not an array based list. The merge sort I tried almost identical to Dave Gamble's version here: Merge Sort a Linked List Also, I thought I'd try a simple quicksort based on this code: http://www.flipcode.com/archives/Quick_Sort_On_Linked

Keeping std::list iterators valid through insertion

半城伤御伤魂 提交于 2019-11-29 13:55:45
Note: This is not a question whether I should "use list or deque". It's a question about the validity of iterators in the face of insert() . This may be a simple question and I'm just too dense to see the right way to do this. I'm implementing (for better or worse) a network traffic buffer as a std::list<char> buf , and I'm maintaining my current read position as an iterator readpos . When I add data, I do something like buf.insert(buf.end(), newdata.begin(), newdata.end()); My question is now, how do I keep the readpos iterator valid? If it points to the middle of the old buf , then it should

Why does removing the _first_ element of a list invalidate `.rend()`?

落爺英雄遲暮 提交于 2019-11-29 02:04:05
Tested on Mac OS X using XCode 4.6. This example code shows removing the last element of an std::list works as I expected: an iterator reference to list::end() is still "1 past the end" and is still valid, even through removal of the last element . But the second example counters my intuition. Removing the first element of the list changes list::rend() , which I thought was "1 past the beginning". Was my expectation wrong? Why was it wrong? Why does your reference to "1 past the end" through deletion of the last element remain valid (should it not?), but a reference to "1 in front of the

Keeping std::list iterators valid through insertion

醉酒当歌 提交于 2019-11-28 07:46:49
问题 Note: This is not a question whether I should "use list or deque". It's a question about the validity of iterators in the face of insert() . This may be a simple question and I'm just too dense to see the right way to do this. I'm implementing (for better or worse) a network traffic buffer as a std::list<char> buf , and I'm maintaining my current read position as an iterator readpos . When I add data, I do something like buf.insert(buf.end(), newdata.begin(), newdata.end()); My question is

Why does removing the _first_ element of a list invalidate `.rend()`?

倖福魔咒の 提交于 2019-11-27 16:20:45
问题 Tested on Mac OS X using XCode 4.6. This example code shows removing the last element of an std::list works as I expected: an iterator reference to list::end() is still "1 past the end" and is still valid, even through removal of the last element . But the second example counters my intuition. Removing the first element of the list changes list::rend() , which I thought was "1 past the beginning". Was my expectation wrong? Why was it wrong? Why does your reference to "1 past the end" through