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

 

In the specific task: index => value
FasterCArrayList thanCHashMap

CArrayList takes more than twice less space, also it has less rearrangements when adding new elements (CArrayList has growth factor 2, whileCHashMap in current implementation is about 1.2).
And there is less fuss when reading result ofCArrayList.

 
Sergey Dzyublik:

In this particular task: index => value
CArrayList is faster thanCHashMap

CArrayList takes more than twice less space, also it has less rebuilds when adding new elements (CArrayList has growth factor 2, whileCHashMap in current implementation is about 1.2).
And there is less fuss when reading result ofCArrayList.

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 a problem.

 
Sergey Dzyublik:

In the specific task: index => value
FasterCArrayList thanCHashMap

CArrayList takes more than twice less space, also it has less rearrangements when adding new elements (CArrayList has growth factor 2, whileCHashMap in current implementation is about 1.2).
And there is less fuss while reading result ofCArrayList.

Why coefficients of scale are different is also very strange. It will be more difficult to rearrange CHashMap than simpler CArrayList.

 

An even more condensed version:

//+------------------------------------------------------------------+
//|                                                      Magic 2.mq5 |
//|                                                      Peter Konow |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Peter Konow"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
int    All_magics[];
int    order_number;
int    Random_orders_of_strategy;
//+------------------------------------------------------------------+
void Trading()
{
 Random_orders_of_strategy = MathRand();
 //----------------------------------------
 //Имитируем открытие неопределенного количества ордеров стратегии.
 //----------------------------------------
 for(int a1 =  0; a1 < Random_orders_of_strategy; a1++)
   {
    int this_magic = MathRand();
    //----------------------------
    order_number++;
    //---------------------------------
    //Меняем размрер массива на каждой итерации.
    //---------------------------------
    ArrayResize(All_magics,order_number);
    All_magics[order_number - 1] = this_magic;
    //---------------------------------
   }
 //----------------------------------------
}
//+------------------------------------------------------------------+
int Get_magic(int deal_number)
{
 return(All_magics[deal_number - 1]);
}
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   Trading();
   //--------------------------
   ulong t1 = GetMicrosecondCount();
   Get_magic(1000);
   ulong t2 = GetMicrosecondCount();
   //--------------------------
   Print("Время исполнения функции Get_magic() при количестве ордеров ",Random_orders_of_strategy," равно ",t2 - t1);
   //--------------------------
   Print("Random_orders_of_strategy  ",Random_orders_of_strategy);
   Print("magic 1:  ",Get_magic(1),"  magic 2: ",Get_magic(2),"  magic 3: ",Get_magic(3));
   
  }
//+------------------------------------------------------------------+
 
Реter Konow:

An even more condensed version:


Now let's use

template<typename T>

 
Alexandr Andreev:

Now let's use

template<typename T>

Why?
 
Реter Konow:

An even more condensed version:

The man continues to mock...

 
Реter Konow:

An even more condensed version:

You've written some bullshit. 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.

 
Реter Konow:
What for?

Well, there are functions such as rewrite an array, add a new line... In the standard release they are not universal, so you have to rewrite them all the time.

So you get a template of your own small functions - some kind of common

 
Yury Kulikov:

The man continues to mock...

Why is a perfect solution to a particular problem perceived as bullying? Seriously, I don't understand...
Reason: