Tuesday, January 19, 2021

Digest for comp.lang.c++@googlegroups.com - 11 updates in 6 topics

red floyd <no.spam@its.invalid>: Jan 18 04:18PM -0800

On 1/18/21 4:03 AM, Tristan B. Kildaire wrote:
> Rick C. Hodgin wrote:
[useless B.S redacted]
 
> Happy new year Rick
 
If you're going to reply to him, please trim his bullshit.
jan4comp.arch@murray-microft.co.uk: Jan 19 06:03PM

On Mon, 18 Jan 2021 16:18:39 -0800
> [useless B.S redacted]
 
> > Happy new year Rick
 
> If you're going to reply to him, please trim his bullshit.
 
+1
 
I do not need to see these conversations, my prospective future has
already been confirmed by private mail. Perhaps more could try this
quick route?
 
Jan Coombs
--
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jan 19 05:53PM -0500

On Tue, 19 Jan 2021 18:03:47 +0000
> already been confirmed by private mail. Perhaps more could try this
> quick route?
 
> Jan Coombs
 
Have any of you ever considered there might be a real reason why posts
like this are made by men and women like me? That maybe there really
is a judgment coming, and that maybe we really are trying to save you
from that judgment and the ramifications to your future because of it?
 
Everybody has sin. But not everybody needs to fear death nor face
the judgment. These messages go forth in love and are given to every
wise soul who will hear the inner call of God upon their life, and
respond. All who do will be saved and enter into eternity alive.
 
These messages are not just noise. They're heralds warning you of
what's to come. Look around the world at the growing chaos, the
increase of information, the increase of wickedness (per God's
viewpoint) and you can see the times we are living in.
 
The Lord's return is near. And so goes the herald.
 
--
Rick C. Hodgin
Mr Flibble <flibble@i42.REMOVETHISBIT.co.uk>: Jan 19 07:11PM

Hi!
 
January 2021: Created neoGFX Chess sample application from scratch (including an AI) in less than 2 weeks demonstrating the maturity of neoGFX -- https://neogfx.org/
 
Message ends.
 
/Flibble
 
--
😎
Bonita Montero <Bonita.Montero@gmail.com>: Jan 19 05:08PM +0100

I had an algorithm which needs fast sorting. So I was curious
about if I can beat std::sort with my own stable sort-function
which allocates the external memory on the stack through alloca()
up to a limit of 64kB.
Here's the code:
 
#pragma once
#include "disarmed-iterators.h"
#include <iterator>
#include <type_traits>
#include <utility>
#include <vector>
 
template<typename ItType, typename IsLess>
void xstable_sort_buf( typename std::iterator_traits<ItType>::value_type
*buf, ItType begin, ItType end, IsLess const &isLess );
 
template<typename ItType, typename IsLess>
void xstable_sort( ItType begin, ItType end, IsLess const &isLess )
{
using namespace std;
using T = typename std::iterator_traits<ItType>::value_type;
static_assert(is_nothrow_move_constructible<T>::value, "*begin must be
nothrow move-contructrible");
static_assert(is_nothrow_move_assignable<T>::value, "*begin must be
nothrow move-assignable");
union TU
{
T t;
};
static_assert(sizeof(TU) == sizeof(T), "sizeof of a single unioned type
must be the same as the type itself");
size_t n = end - begin,
capacity = 0;
for( size_t add = n; add > 2; add -= add / 2 )
capacity += add;
if( ((char *)&*begin - (char *)&*end) <= 0x8000 )
{
T *buf = (T *)alloca( capacity * sizeof(T) );
return xstable_sort_buf( buf, begin, end, isLess );
}
vector<TU> buf;
buf.resize( capacity );
xstable_sort_buf( (T *)&buf[0], begin, end, isLess );
}
 
template<typename ItType, typename IsLess>
void xstable_sort_buf( typename std::iterator_traits<ItType>::value_type
*buf, ItType begin, ItType end, IsLess const &isLess )
{
using namespace std;
using T = typename std::iterator_traits<ItType>::value_type;
static_assert(is_nothrow_move_constructible<T>::value, "*begin must be
nothrow move-contructrible");
static_assert(is_nothrow_move_assignable<T>::value, "*begin must be
nothrow move-assignable");
size_t n = end - begin;
if( n <= 2 )
{
if( n == 2 && isLess( begin[1], begin[0] ) )
swap( begin[1], begin[0] );
return;
}
T *p;
ItType it;
for( p = buf, it = begin; it != end; )
new( (void *)p++ )T( move( *it++ ) );
size_t right = n / 2,
left = n - right;
xstable_sort_buf( buf + n, buf, buf + left, isLess );
xstable_sort_buf( buf + n, buf + left, buf + n, isLess );
T *pLeft = buf,
*pRight = buf + left;
T *pLeftEnd = pRight,
*pRightEnd = buf + n;
for( it = begin; ; )
{
if( isLess( *pLeft, *pRight ) )
{
*it++ = move( *pLeft );
if( ++pLeft == pLeftEnd )
{
do
*it++ = move( *pRight );
while( ++pRight != pRightEnd );
break;
}
}
else
{
*it++ = move( *pRight );
if( ++pRight == pRightEnd )
{
do
*it++ = move( *pLeft );
while( ++pLeft != pLeftEnd );
break;
}
}
}
for( p = buf; p != buf + n; ++p )
p->~T();
}
 
Unfortunately the code needs severely degenerated input to compete
with std::sort. Usually my code is somewhat slower than std::sort,
but nevertheless it's a good fast stable sorting algorithm which
prevents the cost of allocating the buffer for low Ns; and when
the Ns are high enough, the allocation-costs are low in contrast
to the sorting-overhead.
Bonita Montero <Bonita.Montero@gmail.com>: Jan 19 06:28PM +0100

So I changed the code a bit so that the construction of the buffer
-elements is done only once:
 
#pragma once
#include "disarmed-iterators.h"
#include <iterator>
#include <type_traits>
#include <utility>
#include <vector>
#include <memory>
 
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 6255) // alloca may oveflow stack

No comments: