HashMap implementation – library MetaTrader 4

Description:

This is a HashMap implementation. This allows something like arrays but with string indexes. It maps strings to Objects. The Objects must be a subclass of the HashValue class provided.

The Hash by default will ‘adopt’ the value objects. In which case it will free the memory when they are no longer in the hash. This can be disabled in the constructor.

The Codebase version might not be the most recent. The latest version can be found here.

Documentation:

Hash class

HashLoop class

Version

125


Below is an example, and it is also used in my JSON Parser class, to represent JSON Objects.

    
    Hash *h = new Hash();

    // Store values
    h.hPutInt("low",0);
    h.hPutInt("high",1);

    // Get values
    int high = h.gGetInt("high");
 
    // Loop
    HashLoop *l ;
    for( l = new HashLoop(h) ; l.hasNext() ; l.next()) {

        string key = l.key();

        int j = l.valInt();

        Print(key," = ",j);

    }
    delete l;

    delete h;


📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks