Examples of generic data collections

 

Hi all!

I would like to ask some examples of generic data collections.
I searched it first, but i didn't find any good example to completely understand how can i use them.

Code Example : 

CArrayList<string> arrayList =  new CArrayList<string>();
arrayList.

If i declare an object of CArrayList like above then i can't access the methods of CArraylist Class.
Of course i have imported the ArrayList Include and there is no error with the declaration.

Thank you!

 
md42:

Hi all!

I would like to ask some examples of generic data collections.
I searched it first, but i didn't find any good example to completely understand how can i use them.

Code Example : 

If i declare an object of CArrayList like above then i can't access the methods of CArraylist Class.
Of course i have imported the ArrayList Include and there is no error with the declaration.

Thank you!


I think it's an issue with the intellisence indexer.

Out of curiosity, have you tried the other collections in Include\Arrays? Incidentally I was testing the performance of the new ArrayList, and when comparing CArrayList<int> to CArrayInt I realized that as long as you know the approximate size of the collection and use Reserve(), the CArrayInt class is much faster... 

#include <Generic\ArrayList.mqh>
#include <Arrays\ArrayInt.mqh>
void OnStart()
{
//---
   
   srand(_RandomSeed);
   int iterations = (int)pow(10,7);
   
   CArrayList<int> list1(iterations);
   CArrayInt       list2;
   list2.Reserve(iterations);
   
   ulong m = GetMicrosecondCount();
   for(int i=0;i<iterations;i++)
      list1.Add(rand()%1000000);
   list1.Sort();
   m = GetMicrosecondCount() - m;
   m/=1000;
   printf("ArrayList time = %d",m);
   
   
   m = GetMicrosecondCount();
   for(int i=0;i<iterations;i++)
      list2.Add(rand()%1000000);
   list2.Sort();
   m = GetMicrosecondCount() - m;
   m/=1000;
   printf("ArrayInt time = %d",m);
}
 
nicholishen:

I think it's an issue with the intellisence indexer.

Out of curiosity, have you tried the other collections in Include\Arrays? Incidentally I was testing the performance of the new ArrayList, and when comparing CArrayList<int> to CArrayInt I realized that as long as you know the approximate size of the collection and use Reserve(), the CArrayInt class is much faster... 


Thank you for the reply.

You have right, probably bug at intellisence indexer! And i agree with the example of CArrayInt if you know the data type you want to use.

Do you have an example that i can store different data types in a single arraylist ?
I would like also an example to store and custom objects inside it.

Thank you!

 

I almost always use this for object pointers

template<typename T>
class objvector : public CArrayObj
{
public:
   T operator[](const int index) const { return At(index); }
};
objvector<CObject*> vect;

vect[index].Method();

 
nicholishen:

I almost always use this for object pointers


Thank you for the advice!

But i would like to use some examples with ArrayList and HashMaps.
For those like me that have some java background i would prefer these data types.

Thank you! 

Reason: