ishkabible, on 24 December 2012  02:01 PM, said:
Examples?
Posted 24 December 2012  12:39 PM
Posted 24 December 2012  03:32 PM
baavgai, on 24 December 2012  07:26 PM, said:
This post has been edited by ishkabible: 24 December 2012  03:34 PM
Posted 24 December 2012  04:49 PM
ishkabible, on 24 December 2012  05:32 PM, said:
Posted 24 December 2012  05:24 PM
template <class _Compare, class _RandomAccessIterator> void __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { // _Compare is known to be a reference type typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; const difference_type __limit = is_trivially_copy_constructible<value_type>::value && is_trivially_copy_assignable<value_type>::value ? 30 : 6; while (true) { __restart: difference_type __len = __last  __first; switch (__len) { case 0: case 1: return; case 2: if (__comp(*__last, *__first)) swap(*__first, *__last); return; case 3: _VSTD::__sort3<_Compare>(__first, __first+1, __last, __comp); return; case 4: _VSTD::__sort4<_Compare>(__first, __first+1, __first+2, __last, __comp); return; case 5: _VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, __last, __comp); return; } if (__len <= __limit) { _VSTD::__insertion_sort_3<_Compare>(__first, __last, __comp); return; } // __len > 5 _RandomAccessIterator __m = __first; _RandomAccessIterator __lm1 = __last; __lm1; unsigned __n_swaps; { difference_type __delta; if (__len >= 1000) { __delta = __len/2; __m += __delta; __delta /= 2; __n_swaps = _VSTD::__sort5<_Compare>(__first, __first + __delta, __m, __m+__delta, __lm1, __comp); } else { __delta = __len/2; __m += __delta; __n_swaps = _VSTD::__sort3<_Compare>(__first, __m, __lm1, __comp); } } // *__m is median // partition [__first, __m) < *__m and *__m <= [__m, __last) // (this inhibits tossing elements equivalent to __m around unnecessarily) _RandomAccessIterator __i = __first; _RandomAccessIterator __j = __lm1; // j points beyond range to be tested, *__m is known to be <= *__lm1 // The search going up is known to be guarded but the search coming down isn't. // Prime the downward search with a guard. if (!__comp(*__i, *__m)) // if *__first == *__m { // *__first == *__m, *__first doesn't go in first part // manually guard downward moving __j against __i while (true) { if (__i == __j) { // *__first == *__m, *__m <= all other elements // Parition instead into [__first, __i) == *__first and *__first < [__i, __last) ++__i; // __first + 1 __j = __last; if (!__comp(*__first, *__j)) // we need a guard if *__first == *(__last1) { while (true) { if (__i == __j) return; // [__first, __last) all equivalent elements if (__comp(*__first, *__i)) { swap(*__i, *__j); ++__n_swaps; ++__i; break; } ++__i; } } // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last  1 if (__i == __j) return; while (true) { while (!__comp(*__first, *__i)) ++__i; while (__comp(*__first, *__j)) ; if (__i >= __j) break; swap(*__i, *__j); ++__n_swaps; ++__i; } // [__first, __i) == *__first and *__first < [__i, __last) // The first part is sorted, sort the secod part // _VSTD::__sort<_Compare>(__i, __last, __comp); __first = __i; goto __restart; } if (__comp(*__j, *__m)) { swap(*__i, *__j); ++__n_swaps; break; // found guard for downward moving __j, now use unguarded partition } } } // It is known that *__i < *__m ++__i; // j points beyond range to be tested, *__m is known to be <= *__lm1 // if not yet partitioned... if (__i < __j) { // known that *(__i  1) < *__m // known that __i <= __m while (true) { // __m still guards upward moving __i while (__comp(*__i, *__m)) ++__i; // It is now known that a guard exists for downward moving __j while (!__comp(*__j, *__m)) ; if (__i > __j) break; swap(*__i, *__j); ++__n_swaps; // It is known that __m != __j // If __m just moved, follow it if (__m == __i) __m = __j; ++__i; } } // [__first, __i) < *__m and *__m <= [__i, __last) if (__i != __m && __comp(*__m, *__i)) { swap(*__i, *__m); ++__n_swaps; } // [__first, __i) < *__i and *__i <= [__i+1, __last) // If we were given a perfect partition, see if insertion sort is quick... if (__n_swaps == 0) { bool __fs = _VSTD::__insertion_sort_incomplete<_Compare>(__first, __i, __comp); if (_VSTD::__insertion_sort_incomplete<_Compare>(__i+1, __last, __comp)) { if (__fs) return; __last = __i; continue; } else { if (__fs) { __first = ++__i; continue; } } } // sort smaller range with recursive call and larger with tail recursion elimination if (__i  __first < __last  __i) { _VSTD::__sort<_Compare>(__first, __i, __comp); // _VSTD::__sort<_Compare>(__i+1, __last, __comp); __first = ++__i; } else { _VSTD::__sort<_Compare>(__i+1, __last, __comp); // _VSTD::__sort<_Compare>(__first, __i, __comp); __last = __i; } } }
This post has been edited by ishkabible: 24 December 2012  05:31 PM
Posted 24 December 2012  06:19 PM
while (true) { __restart: if (__len <= __limit) { return; } { /* strange, pointless, block notation */ } if (!__comp(*__i, *__m)) { while (true) { if (__i == __j) { if (!__comp(*__first, *__j)) { // we need a guard if *__first == *(__last1) while (true) { if (__i == __j) return; if (__comp(*__first, *__i)) { break; } } } if (__i == __j) { return; } while (true) { if (__i >= __j) { break; } } goto __restart; } if (__comp(*__j, *__m)) { break; } } } if (__i < __j) { while (true) { if (__i > __j) { break; } } } if (__n_swaps == 0) { if (_VSTD::__insertion_sort_incomplete<_Compare>(__i+1, __last, __comp)) { if (__fs) { return; } continue; // pointless // pointless else continue; // pointless } } }
while (true) { __restart: if (foo) { while (true) { if (bar) { // stuff goto __restart; } if (baz) { break; } } } // stuff }
while (true) { if (foo) { bool done2 = false; while (!done2) { if (bar) { // stuff done2 = true; } if (!done2 && baz) { break; } } if (done2) { continue; } } // stuff }
This post has been edited by baavgai: 24 December 2012  06:22 PM
Posted 24 December 2012  06:41 PM
This post has been edited by ishkabible: 24 December 2012  06:53 PM
Posted 25 December 2012  09:04 AM
Posted 25 December 2012  07:41 PM
if (current == null  current>nextPtr == endPtr) { // have to deal with current potentially being null or not null here and causing confusion. }
Posted 26 December 2012  06:18 AM
Skydiver, on 25 December 2012  09:41 PM, said:
if (current == null) { // this knows exactly what the variable contains } else if(current>nextPtr == endPtr) { // so does this }
Posted 26 December 2012  06:55 AM
Quote
Posted 26 December 2012  07:18 AM
This post has been edited by Skydiver: 26 December 2012  07:25 AM
Posted 26 December 2012  07:43 AM
Skydiver, on 26 December 2012  09:18 AM, said:
Quote
Posted 26 December 2012  08:29 AM
jon.kiparsky, on 26 December 2012  09:43 AM, said:
Posted 26 December 2012  09:58 AM
Quote
Query failed: unknown local index 'forums_search_posts_main' in search request.
