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

 
sergeev:

Yes. I think we can do without hash in this case. I was too hasty with my advice about hashes. :)

If this option will suit Vasily - we will simply put all parameters into string. The string will be identifier of the class.


But it is correct too. After all, in this case crypto protection is not needed at all. The bad thing, however, is that you still need to convert the string of all parameters into a specific, preferably 32-bit unique number, and for that you probably will need to use hash functions.

Hell, there are no bitwise operators like inversion, offset, etc. in MQL. Yeah, it's a bit hard to do all that in MQL.

 
sergeev:

Yes. In this case we can do without hash.
If this variant suits Vasiliy, then we just put all parameters into string. The string will be the class identifier.

Well, if you implement java hash set, it will be even more interesting...
Like... matching hash -> sorted set -> elements...
The main thing is that a sorted list is associated with the hash.
.
Then everything will also "fly" (though, low and low...).
 
C-4:

Problem: you need to uniquely identify an instance of a class by its unique ID, preferably of long type. The unique ID should be formed considering uniqueness of values of variables belonging to the class.

Geez! I'll have the same task on Monday )))).

I won't be able to use a string, as I'm limited by length - I'll need to name objects based on it.

I was thinking... You can probably use two hashing algorithms at the same time - it will greatly reduce the probability of non-uniqueness... or am I mistaken?

 
C-4:


Hell, MQL doesn't have bitwise operators like inversion, offset, etc. Yeah, it's going to be hard to do all that in MQL.

Why not? It's all there! https://docs.mql4.com/ru/basis/operations/bit

 
C-4:

Hell, MQL doesn't have bitwise operators like inversion, offset, etc. Yes, it would be hard to do all that in MQL.

https://docs.mql4.com/ru/basis/operations/assign
Shift the binary representation of y to the right by x bits y >>= x;
Shift the binary representation of y to the left by x bit y <<= x;
Bitwise AND operation of binary representations of y and x y &= x;
Bitwise OR of binary representations y and x y |= x;
Bitwise exclusive OR operation
of binary representations y and x y ^= x;

Maybe y != x; works too

SZY: about uniqueness of names etc. - the problem, as always, comes down to the old problem: how to save memory and not lose performance

either use an array of strings with unique names and thus increase the amount of data, or use a function that will use an algorithm based on the input data to form a unique name, thereby reducing performance but saving memory

 
sergeev:

not there.

but here https://docs.mql4.com/ru/basis/operations/bit


not there! ;)

SZY: this information is the same, just the example for both assignment and bitwise operations is the same, because my link says "Bitwise operations are performed only with integers", if you want I can tell you the exact link ;), I think C-4 will understand where and where to read the Help

 

Here is a working example of Adler32 hash function:

//+------------------------------------------------------------------+
//|                                                Adler32_Sample.mq5 |
//|                        Copyright 2010, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   string a="mesage 1: Hello word";
   string b="message 2: It's simple code";
   string c="message 2: It's simple codes";
   Print(adler32(a));
   Print(adler32(b));
   Print(adler32(c));
  }
//+------------------------------------------------------------------+

ulong adler32(string buf)
  {
     ulong s1 = 1;
     ulong s2 = 0;
     uint buflength=StringLen(buf);
     uchar array[];
     ArrayResize(array, buflength,0);
     StringToCharArray(buf, array, 0, -1, CP_ACP);
     for (uint n=0; n<buflength; n++)
     {
        s1 = (s1 + array[n]) % 65521;
        s2 = (s2 + s1)     % 65521;
     }
     return ((s2 << 16) + s1);
  }

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

2011.01.22 22:50:10 BitOperations (#MCD,MN1) 2333149633
2011.01.22 22:50:10 BitOperations (#MCD,MN1) 2169506126
2011.01.22 22:50:10 BitOperations (#MCD,MN1) 1202325230

As you can see all values returned by this function are absolutely different, though strings themselves are not very different.

 
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 work:

As you can see all values returned by this function are absolutely different, though strings themselves are not very different.

great.

if you can (so as not to lose it) drop it in the MQL5 codebase.

 
sergeev:

great.

if you can (so as not to lose it) drop it in the MQL5 codebase.


Okie.