Task

The goal is to create an associative array (also known as a dictionary, map, or hash).



Related tasks:

 Associative arrays/Iteration
 Hash from two arrays


See also

 Array
 Associative array: Creation, Iteration
 Collections
 Compound data type
 Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
 Linked list
 Queue: Definition, Usage
 Set
 Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal
 Stack


class MAIN is
  main is
    -- creation of a map between strings and integers
    map ::= #MAP{STR, INT};
 
    -- add some values
    map := map.insert("red", 0xff0000);
    map := map.insert("green", 0xff00);
    map := map.insert("blue", 0xff);
 
    #OUT + map + "\n"; -- show the map...
 
    -- test if "indexes" exist
    #OUT +  map.has_ind("red") + "\n";
    #OUT +  map.has_ind("carpet") + "\n";
 
    -- retrieve a value by index
    #OUT + map["green"] + "\n";
  end;
end;
 