Hash from two arrays: Difference between revisions

m
comment re indexes
m (comment re indexes)
Line 1,136:
 
=={{header|Phix}}==
You could of course make the values in the dictionary be indexes to valuearray instead, as shown commented out.
<lang Phix>function make_hash(sequence keyarray, sequence valuearray)
integer dict = new_dict()
for i=1 to length(keyarray) do
setd(keyarray[i],valuearray[i],dict)
-- setd(keyarray[i],i,dict)
end for
return dict
end function
 
integerconstant keyarray dict = make_hash({1,"two",PI},{"one",2,PI})
constant valuearray = {"one",2,PI}
integer dict = make_hash(keyarray,valuearray)
?getd(1,dict)
?getd("two",dict)
?getd(PI,dict)</lang>
--?valuearray[getd(1,dict)]</lang>
{{out}}
<pre>
7,820

edits