Algorithms, solution methods, comparison of their performance - page 18

 
Реter Konow:
Why is a perfect solution to a particular problem perceived as mockery? Seriously, I don't understand...

What was your task? Remind it for yourself here publicly please.

 
Vasiliy Sokolov:

You have written some nonsense. Essentially a variant of accessing an array by its index. In reality transaction numbers are random, and your whole example will collapse when you need to solve the real problem.


Wait till you get it right, I'm sure tomorrow.

 
Реter Konow:

***

If I were to make sure that data doesn't disappear from an array when its size is changed, ***

Here is a check for dynamic arrays: one-dimensionalarr_dynamic and two-dimensionalarr_dynamic_multi.

//+------------------------------------------------------------------+
//|                                                  ArrayResize.mq5 |
//|                              Copyright © 2017, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2017, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.001"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- объявим динамические массивы
   double arr_dynamic[];
   double arr_dynamic_multi[][2];
//--- новый размер в первом измерении массива
   if(ArrayResize(arr_dynamic,5)==-1)
     {
      Print("Ошибка ArrayResize for \"arr_dynamic\"");
      return;
     }
   if(ArrayResize(arr_dynamic_multi,5)==-1)
     {
      Print("Ошибка ArrayResize for \"arr_dynamic_multi\"");
      return;
     }

   for(int i=0;i<ArraySize(arr_dynamic);i++)
      arr_dynamic[i]=i;
   for(int i=0;i<ArrayRange(arr_dynamic_multi,0);i++)
     {
      arr_dynamic_multi[i][0]=i;
      arr_dynamic_multi[i][1]=i*10;
     }

//--- распечатка значений до увеличения размера
   Print("Перед ArrayResize массив \"arr_dynamic\" имеет такие элементы:");
   ArrayPrint(arr_dynamic);
   Print("Перед ArrayResize массив \"arr_dynamic_multi\" имеет такие элементы:");
   ArrayPrint(arr_dynamic_multi);

//--- увеличим размер на два элемента
   if(ArrayResize(arr_dynamic,ArraySize(arr_dynamic)+2)==-1)
     {
      Print("Ошибка ArrayResize for \"arr_dynamic\"");
      return;
     }
   if(ArrayResize(arr_dynamic_multi,ArrayRange(arr_dynamic_multi,0)+2)==-1)
     {
      Print("Ошибка ArrayResize for \"arr_dynamic_multi\"");
      return;
     }
//--- распечатка значений после увеличения размера
   Print("После ArrayResize (увеличения размера) массив \"arr_dynamic\" имеет такие элементы:");
   ArrayPrint(arr_dynamic);
   Print("После ArrayResize (увеличения размера) массив \"arr_dynamic_multi\" имеет такие элементы:");
   ArrayPrint(arr_dynamic_multi);

//--- новый размер в первом измерении массива установим равным 3 (то есть уменьшим размер массива)
   if(ArrayResize(arr_dynamic,3)==-1)
     {
      Print("Ошибка ArrayResize for \"arr_dynamic\"");
      return;
     }
   if(ArrayResize(arr_dynamic_multi,3)==-1)
     {
      Print("Ошибка ArrayResize for \"arr_dynamic_multi\"");
      return;
     }
//--- распечатка значений после уменьшение размера
   Print("После ArrayResize (уменьшение размера) массив \"arr_dynamic\" имеет такие элементы:");
   ArrayPrint(arr_dynamic);
   Print("После ArrayResize (уменьшение размера) массив \"arr_dynamic_multi\" имеет такие элементы:");
   ArrayPrint(arr_dynamic_multi);
  }
//+------------------------------------------------------------------+


As you can see, when the array is increased in size, the previous values remain:

Перед ArrayResize массив "arr_dynamic" имеет такие элементы:
0.00000 1.00000 2.00000 3.00000 4.00000
Перед ArrayResize массив "arr_dynamic_multi" имеет такие элементы:
         [,0]     [,1]
[0,]  0.00000  0.00000
[1,]  1.00000 10.00000
[2,]  2.00000 20.00000
[3,]  3.00000 30.00000
[4,]  4.00000 40.00000
После ArrayResize (увеличения размера) массив "arr_dynamic" имеет такие элементы:
  0.00000   1.00000   2.00000   3.00000   4.00000  -0.00000  +0.00000
После ArrayResize (увеличения размера) массив "arr_dynamic_multi" имеет такие элементы:
         [,0]     [,1]
[0,]  0.00000  0.00000
[1,]  1.00000 10.00000
[2,]  2.00000 20.00000
[3,]  3.00000 30.00000
[4,]  4.00000 40.00000
[5,] +0.00000 +0.00000
[6,] +0.00000 +0.00000
После ArrayResize (уменьшение размера) массив "arr_dynamic" имеет такие элементы:
0.00000 1.00000 2.00000
После ArrayResize (уменьшение размера) массив "arr_dynamic_multi" имеет такие элементы:
         [,0]     [,1]
[0,]  0.00000  0.00000
[1,]  1.00000 10.00000
[2,]  2.00000 20.00000
Files:
 
Vasiliy Sokolov:

You have written some nonsense. Essentially a variant of accessing an array by its index. In reality transaction numbers are random, and your whole example will collapse when you need to solve a real problem.

You're referring to tickets, I guess. I mean sequential transaction numbers.

You can make a parallel array next to each other to record the tickets.

Or several parallel arrays to record the rest of the data of each order.

 
Vladimir Karputov:

Here is a check for dynamic arrays: one-dimensionalarr_dynamic and two-dimensionalarr_dynamic_multi.


As you can see , when the array's size is increased, the previous values remain:


hide it here purely OOP and everything useful

 
Vladimir Karputov:

Here is a check for dynamic arrays: one-dimensionalarr_dynamic and two-dimensionalarr_dynamic_multi.


As you can see , if you increase the size of the array, the previous values remain:

Thank you. This is very valuable information.
 

I would like to discuss Print and Comment - why no one is paying attention

 
Vasiliy Sokolov:

There is a magic property: Capacity, which by the way is absent in CHashMap for some reason (which is a gross oversight of developers). By specifying it, we bypass re-partitioning. You can specify it in this task, so I don't see any problems.

You can specifyCapacity in CHashMap via constructor.

Vasiliy Sokolov:

Why do they have different scaling factors, by the way, is also very strange. It's difficult to rearrange CHashMap than simpler CArrayList.

For CHashMap dictionary size should be a simple number to keep uniformity of hashes in the dictionary.
CHashMap uses CPrimeGenerator for choosing prime numbers.
But unfortunately, the CPrimeGenerator implementation does not meet expectations and contains only the values below:

const static int  CPrimeGenerator::s_primes[]=
  {
   3,7,11,17,23,29,37,47,59,71,89,107,131,163,197,239,293,353,431,521,631,761,919,
   1103,1327,1597,1931,2333,2801,3371,4049,4861,5839,7013,8419,10103,12143,14591,
   17519,21023,25229,30293,36353,43627,52361,62851,75431,90523,108631,130363,156437,
   187751,225307,270371,324449,389357,467237,560689,672827,807403,968897,1162687,1395263,
   1674319,2009191,2411033,2893249,3471899,4166287,4999559,5999471,7199369
  };
The average growth factor is on the order of 1.2
 
Vasiliy Sokolov:

What was your task? Remind it for yourself here publicly please.

To find the fastest and most efficient solution for adding megs to an array (list, dictionary...), and retrieving megs from an array by transaction number, when the number of future transactions is unknown.

 
Реter Konow:

Find the fastest and most efficient solution for adding megs to an array (list, dictionary...), and retrieving megs from the array, with an unknown number of future transactions.


understandably, there was no question of a ticket

Still, I advise you to start complicating your code with all sorts of stuff like boilerplate functions
Reason: