Any questions from a PROFI to a SUPER PROFI - 1. - page 8

 
C-4:

Here is a working example of Adler32 hash function:

The basic code of the function is taken from wikipedia and slightly modified for MQL5. Here is the result of the script:

As you can see, all values returned by this function are absolutely different, although strings themselves don't differ much.

Why ulong and not uint?

And the operations with arrays in this function are extremely inefficient. It is easier to modify the code and divide unicode into two independent symbols - it will be 50 times faster.

uint adler32__(string buf)
  {
     uint s1 = 1;
     uint s2 = 0;
     uint buflength=StringLen(buf);
     ushort dat;
     for (uint n=0; n<buflength; n++)
     {
        dat = StringGetCharacter(buf, n);
        s1 = (s1 + (dat % 256)) % 65521;
        s2 = (s2 + s1)     % 65521;
        s1 = (s1 + (dat>>8)) % 65521;
        s2 = (s2 + s1)     % 65521;
     }
     return ((s2 << 16) + s1);
  }
3681 ms vs 13822 ms at 3 million runs.... only 4 times different...... but no conversion loss
 

Yes, that's right, because 32 bits is an integer, not a long. Although, frankly speaking, I would modify the hash function for 64-bit version. After all, collision probability is less, and it is easy to adjust for magic expert. Although, on the other hand, the current implementation is fully compatible with MQL4 (for it has no long type)

P.S. Wouldn't it be faster, if I convert string to uchar array before looping, and already in loop one by one go through array values? But I think calling StringGetCharacter(buf, n) every time in the loop is too expensive.

 
C-4:

Yes, that's right, because 32 bits is an integer, not a long. Although, frankly speaking, I would modify the hash function for 64-bit version. After all, collision probability is less, and it is easy to adjust for magic expert. However, on the other hand, the current implementation is fully compatible with MQL4 (for it has no long type)

P.S. Wouldn't it be faster, if I convert string to uchar array before loop, and then in loop I have to go through array values one by one? Still, I think calling StringGetCharacter(buf, n) every time in the loop is quite expensive.

I understand that this algorithm can only be 32-bit.

And what about conversion before the loop - how? You would then need an array... dynamic allocation... Yes and there is a loss of information when converting

 
AlexSTAL:

I understand that this algorithm can only be 32-bit.

More precisely, for each block length, we have to specifically select a characteristic polynomial that will have "good" hashing properties, i.e. more or less uniformly map the input set to the hash set.
 
AlexSTAL:
3681 ms vs 13822 ms at 3 million runs.... only 4 times different...... but no conversion loss

would be even faster if dat % 256 operation is replaced by dat & 0xFF, and s = (...)%65521; decompose to s = (...); if(s>=65521) s-=65521;


 

А по поводу конвертации перед циклом - это как? Вам массив тогда понадобится... динамическое распределение... Да и при конвертации происходит потеря информации

So this is the regular conversion before the cycle:

uchar array[];
ArrayResize(array, buflength,0);
StringToCharArray(buf, array, 0, -1, CP_ACP);
// Дальше идет цикл

But again, this function is only available in MQL5. The loss of information, as I understand it, occurs in Unicode-->ASCII, which is quite acceptable.

 
C-4:

So this is the regular conversion before the cycle:

But again, this function is only available in MQL5. The loss of information, as I understand it, occurs in Unicode-->ASCII, which is quite acceptable.

Well, yes... It's only acceptable for you in your particular task, while not for the algorithm.

Take a closer look at the 64-bit MaHash8v64 (ulong) algorithm, or perhaps both of them together (at least, I will do so for me).

There's no Unicode in MQL4, so there's no problem either.

P.S. StringGetCharacter is pretty fast function, it only returns WORD(ushort for MQL5) from the required position, i.e. it doesn't work with string at all

 

If anyone has a C++ windows VS application project, preferably for version 10. The project needs to use a dll in its work. I will use it as a template.

Preferably the dll should be called MLP2HL.dll.

Thanks in advance.

 
joo:

If anyone has a C++ windows VS application project, preferably for version 10. The project needs to use a dll in its work. I will use it as a template.

Preferably the dll should be called MLP2HL.dll.

Thank you in advance.

Template is here: ...MetaTrader 4\experts\samples\DLLSample

VS 2010 will convert it automatically. The name can be changed.
 
Zhunko:

The template is here: ...MetaTrader 4\experts\samples\DLLSample

VS 2010 converts it automatically. The name can be changed.

Nah, I know about the dll template. :)

I need an exe project template which project contains in it the sources of dll, so that I could debug it. A dll is not executable and must be called by someone. I decided to study Intel Parallel Studio 2011 for VS.

Reason: