Associative array/Iteration: Difference between revisions

Content added Content deleted
m (→‎{{header|ooRexx}}: add output)
(Added the CONTAINSKEY operator needed by the Lychrel Numbers task.)
Line 84: Line 84:
array
array
END; # INIT #
END; # INIT #

# gets a reference to the value corresponding to a particular key in an #
# gets a reference to the value corresponding to a particular key in an #
# associative array - the element is created if it doesn't exist #
# associative array - the element is created if it doesn't exist #
Line 121: Line 122:
result
result
END; # // #
END; # // #

# returns TRUE if array contains key, FALSE otherwise #
PRIO CONTAINSKEY = 1;
OP CONTAINSKEY = ( REF AARRAY array, AAKEY key )BOOL:
BEGIN
# get the hash chain for the key #
REF AAELEMENTLIST element := ( elements OF array )[ HASH key ];
# find the element in the list, if it is there #
BOOL found element := FALSE;
WHILE ( element ISNT nil element list )
AND NOT found element
DO
found element := ( key OF element OF element = key );
IF NOT found element
THEN
element := next OF element
FI
OD;
found element
END; # CONTAINSKEY #


# gets the first element (key, value) from the array #
# gets the first element (key, value) from the array #