Wednesday, October 31, 2018

Digest for comp.lang.c++@googlegroups.com - 9 updates in 1 topic

Paul <pepstein5@gmail.com>: Oct 31 07:34AM -0700

Below is my code for determining if a given sequence of distinct
integers has a decreasing subsequence of length 3.
Is there a standard range-based approach for writing for(int i = 2; i < x.size(); ++ i)
 
Thanks. (Of course, any comments on the code are welcome.) I'd be surprised
if it's wrong because I've tested it quite a bit.
 
Paul
 
// A permutation being a riffle shuffle is equivalent to there being no decreasing
// subsequence of length 3. All cards are assumed distinct.
bool isRiffleShuffle(const std::vector<int>& cards)
{
if(cards.size() < 3)
return true;
 
// Keep track of the "largest" decreasing subsequence of length 2
// and whether such a sequence exists.
int maximum = std::max(cards[0], cards[1]);
int afterPeak;
bool decreasing2 = cards[1] < cards[0];
if(decreasing2)
afterPeak = cards[1];
 
for(int i = 2; i < cards.size(); ++i)
{
const int card = cards[i];
if(decreasing2 && card < afterPeak)
return false;
 
if(card > maximum)
maximum = card;
else
{
if(!decreasing2 || card > afterPeak)
afterPeak = card;
decreasing2 = true;
}
}
return true;
}
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Oct 31 04:17PM +0100

On 31.10.2018 15:34, Paul wrote:
> Below is my code for determining if a given sequence of distinct
> integers has a decreasing subsequence of length 3.
> Is there a standard range-based approach for writing for(int i = 2; i < x.size(); ++ i)
 
Not yet, as far as I know. But see below.
 
Before getting to that, however, I suggest compiling with the highest
practical warning levels. For g++ (and presumably clang, since it was
designed as drop-in replacement) that means `-Wall -pedantic-errors
-std=c++17`, and for Visual C++ 2017 (and presumably Intel, ditto) that
means `/W4 /D _CRT_SECURE_NO_WARNINGS /D _STL_SECURE_NO_WARNINGS`.
 
Then you'd discover that the following way of writing the loop,
 
for( int i = 2, n = cards.size(); i < n; ++i )
 
... both avoids warnings and guarantees performance.
 
> {
> const int card = cards[i];
> if(decreasing2 && card < afterPeak)
 
Visual C++ 2017 with `/W4` says,
 
p:\temp\foo.cpp(22) : warning C4701: potentially uninitialized local
variable 'afterPeak' used
 
Upping the warning level can be really useful, not just for writing
loops with efficient execution, but also for correctness.
 
> }
> return true;
> }
 
 
---------------------------------------------------------------------
#include <algorithm>
#include <vector>
 
struct Start_offset{ int value; };
 
template< class It >
class It_range
{
It m_first;
It m_after;
 
public:
auto begin() const -> It { return m_first; }
auto end() const -> It { return m_after; }
 
It_range( const It first, const It after ):
m_first( first ),
m_after( after )
{}
 
It_range( const It first, const It after, const Start_offset offset
= {0} ):
m_first( first + offset.value ),
m_after( after )
{}
};
 
#include <iostream>
#include <iterator> // std::(begin, end)
#include <numeric> // std::iota
#define $items( c ) std::begin( *&c ), std::end( c )
auto main()
-> int
{
using namespace std;
 
vector<int> cardinals( 7 );
iota( $items( cardinals ), 1 );
 
// Output "3 4 5 6 7".
// Using C++17 template parameter deduction from constructor args.
for( const int i : It_range( $items( cardinals ), Start_offset{ 2 } ) )
{
cout << i << ' ';
}
cout << endl;
}
---------------------------------------------------------------------
 
 
Cheers!,
 
- Alf
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Oct 31 04:20PM +0100

On 31.10.2018 16:17, Alf P. Steinbach wrote:
>         m_after( after )
>     {}
> };
 
Oh, instead of `+` should use whatever that std:: function is called,
that behaves appropriately for random access and forward iterators.
 
Sorry,
 
- Alf
Ralf Goertz <me@myprovider.invalid>: Oct 31 04:23PM +0100

Am Wed, 31 Oct 2018 07:34:33 -0700 (PDT)
> }
> return true;
> }
 
"afterPeak" is not initialized if cards[1]>cards[0]. BTW does that mean
it is 0? Seems not to be the case since using "g++ -O6 -Wall" on the
following program always prints 1 regardless of the value of argc but it
doesn't warn about 'x' being used uninitialized.
 
 
#include <iostream>
 
int main(int argc, char *argv[]) {
int x;
if (argc>1) x=1;
std::cout<<x<<"\n";
}
Ralf Goertz <me@myprovider.invalid>: Oct 31 04:35PM +0100

Am Wed, 31 Oct 2018 16:17:02 +0100
> -std=c++17`, and for Visual C++ 2017 (and presumably Intel, ditto)
> that means `/W4 /D _CRT_SECURE_NO_WARNINGS /D
> _STL_SECURE_NO_WARNINGS`.
 
Hm, in the example given in my answer to the op g++ remains silent with
"g++ -Wall -pedantic-errors". Using -O0 prints 0 using -O2 prints 1 when
argc is 1.
 
#include <iostream>
 
int main(int argc, char *argv[]) {
int x;
if (argc>1) x=1;
std::cout<<x<<" "<<argc<<"\n";
}
Paul <pepstein5@gmail.com>: Oct 31 08:53AM -0700

On Wednesday, October 31, 2018 at 3:24:00 PM UTC, Ralf Goertz wrote:
> if (argc>1) x=1;
> std::cout<<x<<"\n";
> }
 
afterPeak is only relevant when decreasing2 is true and afterPeak is only
used when decreasing2 is true. However, it is correct that the compiler
doesn't know that no uninitialised variables are being read.
When I tested a few minutes ago, afterPeak was initialised to 7274116 rather
than 0.
 
I don't see a problem here.
 
Paul
scott@slp53.sl.home (Scott Lurndal): Oct 31 04:12PM

> if (argc>1) x=3D1;
> std::cout<<x<<"\n";
>}
 
The initial value of 'x' is simply whatever value is in
memory at the stack location assigned to x. This may often
be zero, but is not guaranteed to be (e.g. if a bunch of
shared objects are loaded in the crt before calling 'main',
then it's likely that 'x' is reusing a memory location).
Louis Krupp <lkrupp@nospam.pssw.com.invalid>: Oct 31 02:06PM -0600

On Wed, 31 Oct 2018 07:34:33 -0700 (PDT), Paul <pepstein5@gmail.com>
wrote:
 
> }
> return true;
>}
 
Note that decreasing2, once set to true, is never set to false.
 
There's a simpler (or at least shorter) way to do it that lets you use
a range-based for loop:
 
===
#include <iostream>
#include <limits>
#include <vector>
 
bool IsRiffleShuffle(const std::vector<int>& cards)
{
auto n_decreasing = 0;
auto prev_card = std::numeric_limits<int>::min();
 
for (auto card : cards) {
if (card < prev_card) {
// Two decreasing cards indicates a decreasing subsequence
// of 3
if (++n_decreasing == 2)
return false;
} else
n_decreasing = 0;
prev_card = card;
}
 
return true;
}
 
int main()
{
std::cout << std::boolalpha << IsRiffleShuffle({}) << "\n";
std::cout << std::boolalpha << IsRiffleShuffle({1, 2, 3}) << "\n";
std::cout << std::boolalpha << IsRiffleShuffle({3, 2, 1}) << "\n";
std::cout << std::boolalpha << IsRiffleShuffle({3, 2, 2}) << "\n";
std::cout << std::boolalpha << IsRiffleShuffle({3, 4, 2}) << "\n";
}
===
legalize+jeeves@mail.xmission.com (Richard): Oct 31 08:16PM

[Please do not mail me a copy of your followup]
 
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> spake the secret code
 
>Then you'd discover that the following way of writing the loop,
 
> for( int i = 2, n = cards.size(); i < n; ++i )
 
>... both avoids warnings and guarantees performance.
 
Is the performance claim really legitimate?
 
Is there any compiler that isn't going to lift this loop
invariant out of the loop for you when optimizations are turned on?
 
I find doing this just makes the code less clear and introduces a
variable that can be accidentally (or "cleverly") modified when you
didn't intent for it to be modified.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

Digest for comp.programming.threads@googlegroups.com - 4 updates in 3 topics

Elephant Man <conanospamic@gmail.com>: Oct 30 04:23PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 30 09:58PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Horizon68 <horizon@horizon.com>: Oct 30 12:02PM -0700

Hello..
 
 
My Parallel archiver and my Parallel Compression Library were updated
 
 
The Zstandard Dynamic Link Libraries for Windows and the Zstandard
Shared Libraries for Linux were updated to the newer versions.
 
 
You can download them from:
 
https://sites.google.com/site/scalable68/parallel-archiver
 
And from:
 
https://sites.google.com/site/scalable68/parallel-compression-library
 
 
Thank you,
Amine Moulay Ramdane.
Horizon68 <horizon@horizon.com>: Oct 30 08:46AM -0700

Hello...
 
Read this:
 
 
Look at this interesting video:
 
Facebook's Head of AI Research "Machines will have emotions and be as
intelligent as humans"
 
https://www.youtube.com/watch?v=F3Cso1aBZNM
 
 
Thank you,
Amine Moulay Ramdane.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.programming.threads+unsubscribe@googlegroups.com.

Tuesday, October 30, 2018

Digest for comp.programming.threads@googlegroups.com - 2 updates in 2 topics

Elephant Man <conanospamic@gmail.com>: Oct 29 08:29PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Horizon68 <horizon@horizon.com>: Oct 29 09:23AM -0700

Hello..
 
 
Good random number generators version were updated to version 1.02
 
Now RandomizedSeed() method is working correctly.
 
You can download them from:
 
https://sites.google.com/site/scalable68/good-random-number-generators
 
 
 
Thank you,
Amine Moulay Ramdane.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.programming.threads+unsubscribe@googlegroups.com.

Monday, October 29, 2018

Digest for comp.lang.c++@googlegroups.com - 7 updates in 3 topics

"Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>: Oct 29 02:55PM -0700

On 10/28/2018 6:24 AM, Paul wrote:
> else ++numZeros;
 
> return *this;
 
> }
[...]
 
I like it. Did something "kind of" similar wrt fractal iteration that
hit a zero, well, I just chose another root to follow. Counting the
zeros that destroy information is nice. I did another thing wrt avoiding
a division my zero. Just avoided it by setting the zero to a small
epsilon, and setting a bit to reflect that this special scenario has
actually occurred. The caller can detect this bit and act accordingly if
needed.
"Öö Tiib" <ootiib@hot.ee>: Oct 29 03:26PM -0700

On Sunday, 28 October 2018 15:24:16 UTC+2, Paul wrote:
 
> for(int i = 0; i < vec.size(); ++i)
> x *= vec[i];
 
When you iterate over whole container then use range-based for.
 
for (int e : vec)
x *= e;
 
It is easier to read that way.
Or if you are after speed then use std::reduce of C++17 instead
of those loops.
boltar@cylonhq.com: Oct 29 09:34AM

On Fri, 26 Oct 2018 14:57:31 -0400
 
>>> Get a load of this cat.
 
>> Did you just step out of a 1970s B movie?
 
>Were you upset when they canceled Galactica 1980?
 
Gutted mate. Still, at least I now had free time to upgrade the Cylons control
system to C++. The old FORTRAN version had quite a few bugs.
"Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>: Oct 29 02:21PM -0700


>> Were you upset when they canceled Galactica 1980?
 
> Gutted mate. Still, at least I now had free time to upgrade the Cylons control
> system to C++. The old FORTRAN version had quite a few bugs.
 
lol. :^)
bitrex <user@example.net>: Oct 28 08:48PM -0400

On 10/27/2018 09:11 AM, Jorgen Grahn wrote:
 
> On the other hand, fixing bugs in terrible code without rewriting it
> from scratch is a useful skill to have.
 
> /Jorgen
 
the problem is as far as I can tell the task the example code is trying
to accomplish doesn't actually require heap allocation but they're
shoe-horning in some heap allocations anyway and then intentionally
screwing it up so the student "learns"....what, exactly.
 
The example is ill-motivated.
Juha Nieminen <nospam@thanks.invalid>: Oct 29 08:50AM

>> Adding a destructor that has a delete[] is not enough. Google
>> "C++ rule of three".
 
> I'm sure Öö will say "and then rule of five" - see upthread.
 
Wasn't it so that if you follow the "rule of three" even in C++11, nothing
breaks. You can follow the "rule of five" if you want more efficiency
(essentially, copying temporaries around becomes much more efficient).
"Öö Tiib" <ootiib@hot.ee>: Oct 29 06:09AM -0700

On Monday, 29 October 2018 10:50:48 UTC+2, Juha Nieminen wrote:
 
> Wasn't it so that if you follow the "rule of three" even in C++11, nothing
> breaks. You can follow the "rule of five" if you want more efficiency
> (essentially, copying temporaries around becomes much more efficient).
 
Yes. Compiler won't implicitly define move constructors and assignments
when one of other four is user-declared. So when we want to use move
then we either have to declare those or to declare none of the five.
 
Also implicitly declared copy constructors and copy assignments when
one of other two is user-defined is deprecated. However compilers
do not issue any diagnostics about that deprecation so it has no effects
in practice.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

Sunday, October 28, 2018

Digest for comp.lang.c++@googlegroups.com - 7 updates in 4 topics

Juha Nieminen <nospam@thanks.invalid>: Oct 28 09:31AM

> I have tried the very basic solution of using delete[] in the destructor
> without using smart pointers. That is not the intended solution.
 
Adding a destructor that has a delete[] is not enough. Google
"C++ rule of three".
 
You can bypass the requirements of the "rule of three" if you
simply use std::vector or a similar container (which does implement
the rule of three appropriately).
 
Although it's useful to know that rule of thumb anyway, if you
ever need to do something for which the standard data containers
aren't enough.
Vir Campestris <vir.campestris@invalid.invalid>: Oct 28 09:10PM

On 28/10/2018 09:31, Juha Nieminen wrote:
> Adding a destructor that has a delete[] is not enough. Google
> "C++ rule of three".
 
I'm sure Öö will say "and then rule of five" - see upthread.
 
Andy
Paul <pepstein5@gmail.com>: Oct 28 06:24AM -0700

A standard problem involves transforming a vector of ints by replacing
the ith component by the product of all the entries apart from the ith
component. (I assume the mathematicians' convention that the product
of an empty collection is 1).
Naive attempts can be bugged for the case where the vector has a zero.
Below is my solution with accompanying tests. It seems to work and
I'd be interested to see feedback. It seems to tackle directly
the root of the difficulty by introducing a new type of multiplication
which still retains the necessary information when zero is encountered.
 
// Task is to transform a vector so that each entry is the multiple of all the other
// entries
#include <iostream>
#include <vector>
 
// A struct to handle multiplication which doesn't lose the
// information when zero is encountered.
struct intMult{
intMult(int x = 1) : underlying(x){}
int underlying;
int numZeros = underlying == 0; // Number of zeros that have been encountered in the multiplication
intMult operator * (int y)
{
if(y)
underlying *= y;
else ++numZeros;
 
return *this;
 
}
 
intMult& operator *= (int y)
{
*this = *this * y;
return *this;
}
};
 
void multiplyInVector(std::vector<int>& vec)
{
intMult x;
for(int i = 0; i < vec.size(); ++i)
x *= vec[i];
 
switch(x.numZeros)
{
case 0:
for(int i = 0; i < vec.size(); ++i)
vec[i] = x.underlying / vec[i];
 
return;
 
case 1:
for(int i = 0; i < vec.size(); ++i)
if(!vec[i])
vec[i] = x.underlying;
else
vec[i] = 0;
return;
 
default:
vec = std::vector<int>(vec.size());
 
}
}
 
std::ostream& operator<< (std::ostream& ofs, const std::vector<int>& vec)
{
ofs << "Am printing a vector \n";
for(int i = 0; i < vec.size(); ++i)
ofs << vec[i] << " ";
 
ofs << "\n";
return ofs;
}
 
int main()
{
std::vector<int> x;
std::vector<int> y{0};
std::vector<int> z {-1};
std::vector<int> a {-5, -4, 3, 5, 7};
std::vector<int> b {-5, 0, 3, 5, 2};
std::vector<int> c {-5, 0, 3, 1, 0};
std::vector<int> e {-5, 0, 0, 0 , 1, 2};
multiplyInVector(x);
multiplyInVector(y);
multiplyInVector(z);
multiplyInVector(a);
multiplyInVector(b);
multiplyInVector(c);
multiplyInVector(e);
std::cout << x << y << z << a << b << c << e;
}
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Oct 28 02:46PM +0100

On 28.10.2018 14:24, Paul wrote:
> the ith component by the product of all the entries apart from the ith
> component. (I assume the mathematicians' convention that the product
> of an empty collection is 1).
 
Those numbers will exceed the number of range of C++ integers pretty quick.
 
 
> I'd be interested to see feedback. It seems to tackle directly
> the root of the difficulty by introducing a new type of multiplication
> which still retains the necessary information when zero is encountered.
 
Well it's not exactly a new kind of multiplication. I used the principle
in 1986/87 for Dempster-Schafer evidence combination, together with the
corresponding division operation. Because DS has all these updates of
products of sets and set intersections (it's a combinatorial nightmare).
 
I was later told that it's well known to at least /some/ in mathematics,
but somewhat esoteric, off the beaten path.
 
I speculated at some point whether it could be generalized in a way as
complex numbers, because it's pretty similar to multiplication of
complex numbers in polar representation. That was a dead end, a hunch
that did not pan out. The operations do define a new kind of number-like
entities but these entities don't like addition much, then producing yet
new /kinds/ of entities, and so on, ad nauseam... :)
 
 
> else ++numZeros;
 
> return *this;
 
> }
 
You don't want to modify one of the operands of a multiplication.
 
As a member function make that `const` and don't modify.
 
But better make it a freestanding function, because that better supports
operands that convert implicitly to `intMult`.
 
 
> *this = *this * y;
> return *this;
> }
 
Since the infix `*` modifies its left operand the assignment here is
redundant.
 
But this is where to put the code currently used for infix `*`.
 
Then express infix `*` in terms of `*=`.
 
 
> vec = std::vector<int>(vec.size());
 
> }
> }
 
Better factor out the `/` and `/=` operations also.
 
 
> multiplyInVector(e);
> std::cout << x << y << z << a << b << c << e;
> }
 
 
Well. Maybe express that as a vector of vectors and use a loop?
 
 
Cheers!
 
- Alf
Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>: Oct 27 11:45PM -0400

Paul wrote:
 
> Paul
 
Yet another possibility is to use saturated math. e.g.:
 
template <typename B/*base type*/, B L/*low limit*/, B H/*high limit*/>
class SaturatedLimited {
public:
SaturatedLimited(): val_(Limit_(B())) {}
SaturatedLimited(B val): val_(Limit_(val) {}
// operators and functions you need; use native
// B arithmetics, then apply Limit_() to get final result
private:
static B Limit_(B val)
{ return val < L ? L : val > H ? H : val; }
B val_;
};
 
typedef SaturatedLimited<unsigned, 0u, 1000u) NumberOfTests;
 
It is not as expensive as throwing exceptions but the semantics may or
may not be what you want. In case of passing the negative number of
tests to a test!running function it will silently not run a single test
-- which would seem reasonable to some people (mainly mathematicians, I
guess).
 
HTH
-Pavel
Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>: Oct 27 11:48PM -0400

Pavel wrote:
...
 
> typedef SaturatedLimited<unsigned, 0u, 1000u) NumberOfTests;
a little correction :-) :
typedef SaturatedLimited<int, 0, 1000) NumberOfTests;
what was I thinking? ...
woodbrian77@gmail.com: Oct 27 05:01PM -0700

"Exception safety is really about when you are in a room
that is completely burning and filled with smoke and fire;
you can drink your coffee and say, 'this is fine' because
I know how to deal with the problem." Jon Cohen from his
Cppcon 2018 talk: "Ensuring Exception Safety Through Testing"
 
https://duckduckgo.com/?q=%22exception+safety%22+cppcon&t=ffab&iax=videos&ia=videos&iai=XPzHNSUnTc4
 
That quote reminds me of these lyrics:
 
"When peace, like a river, attendeth my way,
When sorrows like sea billows roll;
Whatever my lot, Thou hast taught me to say,
It is well, it is well with my soul." Horatio Spafford
 
I liked the talk in general and that was before it hit
me about the parallel.
 
 
Brian
Ebenezer Enterprises - Enjoying programming again.
https://github.com/Ebenezer-group/onwards
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

Digest for comp.programming.threads@googlegroups.com - 4 updates in 3 topics

Elephant Man <conanospamic@gmail.com>: Oct 27 07:19PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 27 07:19PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Horizon68 <horizon@horizon.com>: Oct 27 10:43AM -0700

Hello..
 
 
About my Good random number generators and scalability..
 
I think my mersenne and splitmix64 random generators can work
with multiple threads and can be "scalable", look at at
ThreadedRandomizedSeed() method to obtain a random seed:
 
==
 
function TMersenne.ThreadedRandomizedSeed():longword;
var a:double;
begin
if bool1=false
then
begin
bool1:=true;
a:=sin(GetCurrentThreadId)*high(longword);
if a < 0 then a:=-a;
if not assigned(mersenne1) then mersenne1:=TMersenne.create;
mersenne1.initialize(round(a));
result:=mersenne1.urand;
end
else result:=mersenne1.urand;
 
end;
 
==
 
You can create a mersenne or splitmix64 object for every
thread and initialize in each thread with ThreadedRandomizedSeed(), and
after than get your random number in each thread, i think this way is
"scalable".
 
 
My Good random number generators for Delphi and FreePascal
was updated to version 1.01, you can port them to C++..
 
Look at them they are powerful.
 
Author: Amine Moulay Ramdane that has enhanced
both random number generators.
 
Description:
 
This is an enhanced versions of both Mersenne Twister that is a
good random number generator and Splitmix64 that is a fast random number
generator, both have passed the BigCrush tests.
 
Look into defines.inc file, there is many options:
 
{$DEFINE CPU32} and {$DEFINE Windows32} for 32 bit systems
 
{$DEFINE CPU64} and {$DEFINE Windows64} for 64 bit systems
 
Look at test.pas demo inside the zip file...
 
You can download it from:
 
https://sites.google.com/site/scalable68/good-random-number-generators
 
Language: FPC Pascal v2.2.0+ / Delphi 5+: http://www.freepascal.org/
 
Operating Systems: Win , Linux and Mac (x86).
 
Required FPC switches: -O3 -Sd
 
-Sd for delphi mode....
 
Required Delphi switches: -$O+
 
 
 
Thank you,
Amine Moulay Ramdane.
Horizon68 <horizon@horizon.com>: Oct 27 09:50AM -0700

Hello,
 
Good random number generators for Delphi and FreePascal
were updated to version 1.01
 
Look at them they are powerful.
 
Author: Amine Moulay Ramdane that has enhanced
both random number generators.
 
Description:
 
This is an enhanced versions of both Mersenne Twister that is a
good random number generator and Splitmix64 that is a fast random number
generator, both have passed the BigCrush tests.
 
Look into defines.inc file, there is many options:
 
{$DEFINE CPU32} and {$DEFINE Windows32} for 32 bit systems
 
{$DEFINE CPU64} and {$DEFINE Windows64} for 64 bit systems
 
Look at test.pas demo inside the zip file...
 
You can download it from:
 
https://sites.google.com/site/scalable68/good-random-number-generators
 
Language: FPC Pascal v2.2.0+ / Delphi 5+: http://www.freepascal.org/
 
Operating Systems: Win , Linux and Mac (x86).
 
Required FPC switches: -O3 -Sd
 
-Sd for delphi mode....
 
Required Delphi switches: -$O+
 
 
 
Thank you,
Amine Moulay Ramdane.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.programming.threads+unsubscribe@googlegroups.com.

Saturday, October 27, 2018

Digest for comp.lang.c++@googlegroups.com - 19 updates in 7 topics

Horizon68 <horizon@horizon.com>: Oct 27 10:42AM -0700

Hello,
 
 
About my Good random number generators and scalability..
 
I think my mersenne and splitmix64 random generators can work
with multiple threads and can be "scalable", look at at
ThreadedRandomizedSeed() method to obtain a random seed:
 
==
 
function TMersenne.ThreadedRandomizedSeed():longword;
var a:double;
begin
if bool1=false
then
begin
bool1:=true;
a:=sin(GetCurrentThreadId)*high(longword);
if a < 0 then a:=-a;
if not assigned(mersenne1) then mersenne1:=TMersenne.create;
mersenne1.initialize(round(a));
result:=mersenne1.urand;
end
else result:=mersenne1.urand;
 
end;
 
==
 
You can create a mersenne or splitmix64 object for every
thread and initialize in each thread with ThreadedRandomizedSeed(), and
after than get your random number in each thread, i think this way is
"scalable".
 
 
My Good random number generators for Delphi and FreePascal
was updated to version 1.01, you can port them to C++..
 
Look at them they are powerful.
 
Author: Amine Moulay Ramdane that has enhanced
both random number generators.
 
Description:
 
This is an enhanced versions of both Mersenne Twister that is a
good random number generator and Splitmix64 that is a fast random number
generator, both have passed the BigCrush tests.
 
Look into defines.inc file, there is many options:
 
{$DEFINE CPU32} and {$DEFINE Windows32} for 32 bit systems
 
{$DEFINE CPU64} and {$DEFINE Windows64} for 64 bit systems
 
Look at test.pas demo inside the zip file...
 
You can download it from:
 
https://sites.google.com/site/scalable68/good-random-number-generators
 
Language: FPC Pascal v2.2.0+ / Delphi 5+: http://www.freepascal.org/
 
Operating Systems: Win , Linux and Mac (x86).
 
Required FPC switches: -O3 -Sd
 
-Sd for delphi mode....
 
Required Delphi switches: -$O+
 
 
 
Thank you,
Amine Moulay Ramdane.
"Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>: Oct 27 03:09PM -0700

On 10/27/2018 10:42 AM, Horizon68 wrote:
> begin
> bool1:=true;
> a:=sin(GetCurrentThreadId)*high(longword);
 
Partitioning wrt angle as thread id...
 
[...]
Paul <pepstein5@gmail.com>: Oct 27 01:16PM -0700

On Tuesday, October 2, 2018 at 7:56:08 PM UTC+1, David Brown wrote:
 
> Marvellous. Keep asking questions, and keep learning. That's what this
> newsgroup is for (despite appearances sometimes).
 
> Once you have had a try, post your code if you are not sure about it.
 
Thanks for your encouragement.
I am actually looking for a C++ tutor, by the way, for online sessions
via something like Google hangout.
 
If anyone is interested, please reply to author and we can discuss rates
and availability.
 
I drafted a new topic with this tutoring request, but I thought I might
get in trouble on OT grounds.
 
I know there are standard websites for tutoring but I think the advice
here is far more expert than what I would get from a tutoring website.
 
Thanks,
 
Paul
Elephant Man <conanospamic@gmail.com>: Oct 27 07:19PM

Article d'annulation émis par un modérateur JNTP via Nemo.
tomusatov@gmail.com: Oct 27 06:21AM -0700

I am wondering if C++ would be the best language to write a program allowing:
 
1. Highlight some text
2. Ctl+HOTKEY1 stores the string of text somewhere as COPIEDTEXT1
3. Highlight another string of text
4. Ctl+HOTKEY1 stores another string of text somewhere as COPIEDTEXT2
 
THEN
 
5. Ctl+HOTKEY2 pastes COPIEDTEXT1
6. Ctl+HOTKEY2 pastes COPIEDTEXT2
 
Can someone point me in the right direction?
 
Thanks,
 
Musatov
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Oct 27 03:32PM +0200


> 5. Ctl+HOTKEY2 pastes COPIEDTEXT1
> 6. Ctl+HOTKEY2 pastes COPIEDTEXT2
 
> Can someone point me in the right direction?
 
You /can/ do it in C++.
 
Depending on the system you want to do this for, some other language
will probably be less work.
 
Right direction pointer: when Microsoft replaced the original Windows
clipboard viewer with one supporting multiple clips, like you sketch,
that marked the end of having a standard clipboard viewer in Windows.
The clipboard relies on simplicity for it to be useful. Adding
complexity and hidden modes is therefore not a good direction.
 
 
Cheers & hth.,
 
- Alf
Luuk <luuk@invalid.lan>: Oct 27 03:38PM +0200


> Can someone point me in the right direction?
 
> Thanks,
 
> Musatov
 
In Windows 10 (from build 1809) you can view your copies with Windows+V.
 
CTRL+C copies (and adds to the list)
CTRL+V pastes
Windows+V (shows the list)
 
Now one has to wait till 1809 get released...
Sam <sam@email-scan.com>: Oct 27 10:02AM -0400


> 5. Ctl+HOTKEY2 pastes COPIEDTEXT1
> 6. Ctl+HOTKEY2 pastes COPIEDTEXT2
 
> Can someone point me in the right direction?
 
The right direction for you would be some general books on computer
programming, where you will learn that in the several thousand of terse,
single-spaced pages that make up the current C++ standard, there is no
mention whatsoever about "highlighting" text, in some mysterious fashion, or
equally-mysterious "hotkeys", that do wondrous things.
 
This is purely a function of your operating system, and the exact task for
implementing these kinds of things depend entirely on the operating system
being used.
 
Since you don't even realize that this is an operating system-specific
question, and you didn't specify which OS you're using, I think it would be
rather difficult, if not impossible, for you to implement the task at hand
right now; but maybe several years down the road.
 
It just so happens that last week I finished implementing copy/cut/paste
support in my X toolkit library (shameless plug:
https://www.libcxx.org/w/copycutpastemenu.html). I don't remember exactly
when I started it, but I've been working on this library for the last eight
years, and coding C++ for …much longer than that. Just to give you a rough
idea how complicated C++-related things are, in the real world.
 
The only other thing I can tell you with some level of confidence is that,
whatever operating system you're using, it's unlikely that you will be able
to modify its default copy/cut/paste behavior in the manner you desire. All
traditional OSrd implement copy/cut/paste internally, behind the scenes, and
their exact mechanics are not exposed to applications. The mouse pointer
operations and/or the keyboard shortcuts for copy/cut/pasting text get
processed entirely by the operating system, or the GUI library being used on
your operating system. The application does not even realize that this is
happening. The OS/GUI library handles the mechanics of this process entirely
on its own. All that the application does is put up text input fields, where
text gets typed in when that text input field has keyboard focus, and the OS
or the GUI library handles copy/cut/paste operations on its own. All the
application cares about is text that mysterious appears in its
aforementioned text input fields, and how it got there, it doesn't really
care.
 
Some OSes might offer third-party add-on tools that enhance the existing
copy/cut/paste behavior. Those tools typically use highly OS-specific
internal functions to modify its copy/cut/paste behavior.
Manfred <noname@add.invalid>: Oct 27 06:41PM +0200

On 10/27/2018 4:02 PM, Sam wrote:
> question, and you didn't specify which OS you're using, I think it would
> be rather difficult, if not impossible, for you to implement the task at
> hand right now; but maybe several years down the road.
The above sounds excessively hard on the poor OP.
 
> last eight years, and coding C++ for …much longer than that. Just to
> give you a rough idea how complicated C++-related things are, in the
> real world.
It is true that C++ is a complex language, but in this case (copy/paste
of strings) the complexity is not about usage of the language, instead
it is mainly about how to interface with the OS - or better, how to
interface with whatever GUI manager is offered by the target platform.
Even this part, however, is not complex in the sense that it be rocket
science. Most of the work would be finding and digging through the
documentation of the system API, the patterns used throughout it, and
such API's are usually very large.
 
> for copy/cut/pasting text get processed entirely by the operating
> system, or the GUI library being used on your operating system. The
> application does not even realize that this is happening.
It is true that it would be impossible or next to impossible to modify
the system clipboard behavior.
It is instead possible to override the relevant commands and implement
your own clipboard scheme. Obviously this would only work within your
own applications.
Again, this is not a C++ problem, it is GUI software development instead.
 
 
The OS/GUI
tomusatov@gmail.com: Oct 27 11:54AM -0700

On Saturday, October 27, 2018 at 8:38:46 AM UTC-5, Luuk wrote:
> CTRL+V pastes
> Windows+V (shows the list)
 
> Now one has to wait till 1809 get released...
 
Bout time. Amen!
Paul <pepstein5@gmail.com>: Oct 27 02:19AM -0700

Below, I will post a question that I would like some help with (if possible).
The best type of help would be something like "Think about using..." rather
than just giving the answer. I would like to avoid using post-C++11 features
if possible.
People sometimes get (rightly) homework-suspicious when they see posts
like these. This question is for self-study purposes only. I am not
a student, and am not enrolled in any course. It is also not part of
any external evaluation process or interview process.
The source of the original question is
https://www.testdome.com/questions/cpp/multiple-choice-test/9808?visibility=1&skillId=7
 
I have tried the very basic solution of using delete[] in the destructor
without using smart pointers. That is not the intended solution.
I tried using unique pointers with release(). This compiled but was also
not the intended solution. reset() wasn't what they wanted either.
 
Many thanks for your help,
 
Paul
 
// CODE BELOW
/*Multiple choice test has several multiple choice questions. Each question can have only one correct answer. Additionally, timed multiple choice test can specify the time allowed for solving each question in the test.
 
The code below satisfies this specification, but the customer complained that the memory usage of the program constantly increases. Fix this problem.*/
 
#include <iostream>
#include <string>
 
class MultipleChoiceTest
{
public:
MultipleChoiceTest(int questionsCount)
{
this->questionsCount = questionsCount;
answers = new int[questionsCount];
for (int i = 0; i < questionsCount; i++)
{
answers[i] = -1;
}
}
 
void setAnswer(int questionIndex, int answer)
{
answers[questionIndex] = answer;
}
 
int getAnswer(int questionIndex) const
{
return answers[questionIndex];
}
 
protected:
int questionsCount;
 
private:
int* answers;
};
 
class TimedMultipleChoiceTest : public MultipleChoiceTest
{
public:
TimedMultipleChoiceTest(int questionsCount)
: MultipleChoiceTest(questionsCount)
{
times = new int[questionsCount];
for (int i = 0; i < questionsCount; i++)
{
times[i] = 0;
}
}
 
void setTime(int questionIndex, int time)
{
times[questionIndex] = time;
}
 
int getTime(int questionIndex) const
{
return times[questionIndex];
}
 
private:
int* times;
};
 
#ifndef RunTests
void executeTest()
{
MultipleChoiceTest test(5);
for (int i = 0; i < 5; i++)
{
test.setAnswer(i, i);
}
 
for (int i = 0; i < 5; i++)
{
std::cout << "Question " << i + 1 << ", correct answer: " << test.getAnswer(i) << "\n";
}
}
 
int main()
{
for (int i = 0; i < 3; i++)
{
std::cout << "Test: " << i + 1 << "\n";
executeTest();
}
}

Digest for comp.programming.threads@googlegroups.com - 24 updates in 3 topics

Elephant Man <conanospamic@gmail.com>: Oct 26 05:06PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:06PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:06PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:06PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:06PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:06PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:06PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:06PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:06PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:07PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:07PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:07PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:07PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:07PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:07PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:07PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:08PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:02PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:03PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 05:03PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 09:30PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Elephant Man <conanospamic@gmail.com>: Oct 26 09:30PM

Article d'annulation émis par un modérateur JNTP via Nemo.
Horizon68 <horizon@horizon.com>: Oct 26 02:30PM -0700

Hello,
 
Read this:
 
 
I have come accross this indian programmer, look at his following
video that prove that the fastest sorting algorithm time complexity
is n*log(n):
 
Fastest Sorting Algorithm. Ever!
 
https://www.youtube.com/watch?v=4Q72kbwyEmk
 
 
I have also "invented" my following Parallel Sort Library that is
powerful, read about it and download it from here:
 
https://sites.google.com/site/scalable68/parallel-sort-library
 
 
 
Thank you,
Amine Moulay Ramdane.
Horizon68 <horizon@horizon.com>: Oct 26 12:04PM -0700

Hello...
 
 
My new "invention" that is a fully scalable algorithm is finished and is
coming soon..
 
I have just today enhanced "much" more my "invention" of a scalable
algorithms of a scalable reference counting with efficient support for
weak references, i think i am the only one who has invented this
scalable algorithm, because it is the only one who is suited for
non-garbage collecting languages such as C++ and Rust and Delphi, my
previous algorithm was not completely scalable, because the first object
that is reference counted was not scalable(it is just the first), but
today i have just made my algorithm "fully" scalable on manycores and
multicores and NUMA systems by using a clever scalable algorithms, so i
think i will "sell" my invention that is my scalable reference counting
algorithm with efficient support for weak references and its
implementation to Microsoft or to Google or to Intel or Embarcadero
 
 
Andf about memory safety and memory leaks in programming languages..
 
Memory safety is the state of being protected from various software bugs
and security vulnerabilities when dealing with memory access, such as
buffer overflows and dangling pointers.
 
I am also working with Delphi and FreePascal and C++, and as you have
noticed i have invented a scalable reference counting with efficient
support for weak references that is really powerful, read about it and
download it from here(it is the Delphi and FreePascal implementation):
 
https://sites.google.com/site/scalable68/scalable-reference-counting-with-efficient-support-for-weak-references
 
And you have to understand that this invention of mine solves
the problem of dangling pointers and it solves the problem of memory
leaks and this reference counting of mine is also "scalable", and i
think that this invention of mine is the only one that you will find,
and you will not find it in C++ and you will not find it in Rust.
 
Also Delphi and FreePascal solve more the out of bounds in arrays and
strings like this by making range checks enabled:
 
In the {$R+} state, all array and string-indexing expressions are
verified as being within the defined bounds, and all assignments to
scalar and subrange variables are checked to be within range. **If a
range check fails, an ERangeError exception is raised (or the program is
terminated if exception handling is not enabled).
 
Range Checks is OFF by default. To enable it, you can add this directive
to your code:
 
{$RANGECHECKS ON}
 
You can use also generic (template) style containers for bound checking,
my following writing to understand more:
 
About C++ and Delphi and FreePascal generic (template) style containers..
 
Generics.Collections of Delphi and FreePascal for generic (template)
style containers that you can download from here:
 
https://github.com/maciej-izak/generics.collections
 
TList of Generics.Collections of Delphi and FreePascal is implemented
the same as STL C++ Vectors: they are array-based. And since data
structureS are the same then also performance should be comparable.
 
So I've done a small test between Tlist of Generics.Collections of
Delphi and FreePascal and C++ vector, it's an addition of 3000000
records of 16 byte length, in one loop, here is the results:
 
Tlist time = 344ms
Vector time = 339ms
 
It seems they are the same, the test use only the function ( List.add ,
vector.push_back).
 
STL vectors with the at() and Delphi TList of Generics.Collections of
Delphi and FreePascal perform bounds checking.
 
 
So i think that with my invention above and with all my other inventions
that are my scalable algorithms and there implementations and such in
C++ and Delphi and FreePascal that you will find
in my following website, Delphi and FreePascal have become powerful:
 
https://sites.google.com/site/scalable68/
 
 
 
Thank you,
Amine Moulay Ramdane.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.programming.threads+unsubscribe@googlegroups.com.