Task

Using two Arrays of equal length, create a Hash object
where the elements from one array (the keys) are linked
to the elements of the other (the values)



Related task

   Associative arrays/Creation


 
MODULE HashFromArrays;
IMPORT 
  ADT:Dictionary,
  Object:Boxed;
TYPE
  Key= STRING;
  Value= Boxed.LongInt;
 
  PROCEDURE Do;
  VAR
    a: ARRAY 128 OF Key;
    b: ARRAY 128 OF Value;
    hash: Dictionary.Dictionary(Key,Value);
    i: INTEGER;
 
  BEGIN
    hash := NEW(Dictionary.Dictionary(Key,Value));
    a[0] := "uno";
    a[1] := "dos";
    a[2] := "tres";
    a[3] := "cuatro";
    b[0] := Boxed.ParseLongInt("1");
    b[1] := Boxed.ParseLongInt("2");
    b[2] := Boxed.ParseLongInt("3");
    b[3] := Boxed.ParseLongInt("4");
    i := 0;
    WHILE (i < LEN(a)) & (a[i] # NIL) DO
      hash.Set(a[i],b[i]);
      INC(i)
    END;
 
  END Do;
BEGIN
  Do;
END HashFromArrays.
 