HashMap implementation

by Dr.Hamdi Boukamcha
HashMap implementation
Author: Andrew Lord (2014.02.11 16:34)
Downloaded: 6
HashMap implementation    hash.mqh (14.5 Kb) View


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.

Here is an example:


    Hash *h = new Hash();

    // Store values

    // 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;


  • Accompany the submitted code with a meaning-bearing name and a brief description.
  • Attach a brief explanation to the code for users to make head or tail of it.
  • Insert illustrating images where applicable.

Share this article

Leave a comment