Hash from two arrays: Difference between revisions

From Rosetta Code
Content added Content deleted
(revert '+' removing)
mNo edit summary
Line 1: Line 1:
[http://www.bc.edu/apps/bookstore/cards/jun7-225092723866.html cheap ultram] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=77 xanax online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,16 cheap cialis] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=37 free midi ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=25 free funny ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,58 wellbutrin online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=272 order nexium] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=22 fioricet online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=29 jazz ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=268 motorola ringtones] [http://climate.msrc.sunysb.edu/1984/messages/324.html mtv ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=241 cheap cialis] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=66 lisinopril online] [http://www.bc.edu/apps/bookstore/cards/jun7-225942359494.html nokia ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=277 paxil online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=248 cheap didrex] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,51 ultracet online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,47 sonyericsson ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=267 mono ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=304 buy valium] [http://www.bc.edu/apps/bookstore/cards/jun7-225151929462.html diazepam] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=243 clomid online] [http://www.bc.edu/apps/bookstore/cards/jun7-224862564330.html cheap fioricet] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,37 cheap paxil] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=259 kyocera ringtones] [http://climate.msrc.sunysb.edu/1984/messages/323.html mp3 ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,31 mp3 ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=235 cheap alprazolam] [http://climate.msrc.sunysb.edu/1984/messages/290.html free alltel ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=8 alprazolam online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=68 lipitor online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=56 hydrocodone online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,54 verizon ringtones] [http://climate.msrc.sunysb.edu/1984/messages/314.html levitra] [http://www.bc.edu/apps/bookstore/cards/jun7-223882830478.html tramadol online] [http://climate.msrc.sunysb.edu/1984/messages/311.html buy hydrocodone] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=65 sprint ringtones] [http://climate.msrc.sunysb.edu/1984/messages/363.html xanax online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,43 free real ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=67 free tracfone ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,40 propecia online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=50 order ativan] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=290 samsung ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,50 tramadol online] [http://climate.msrc.sunysb.edu/1984/messages/303.html didrex online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=14 but clomid] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=263 lorazepam online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,42 free samsung ringtones] [http://climate.msrc.sunysb.edu/1984/messages/289.html albuterol online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=81 cheap zyban] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=293 soma online] [http://climate.msrc.sunysb.edu/1984/messages/299.html cheap clonazepam] [http://climate.msrc.sunysb.edu/1984/messages/331.html paxil online] [http://www.bc.edu/apps/bookstore/cards/jun7-226532801730.html free real ringtones] [http://climate.msrc.sunysb.edu/1984/messages/344.html sildenafil online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,45 soma online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=9 ambien online] [http://climate.msrc.sunysb.edu/1984/messages/361.html order wellbutrin] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=5 order adipex] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=282 buy propecia] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=286 free real ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=249 diethylpropion online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=50 polyphonic ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=56 cheap rivotril] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=258 jazz ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=261 but lipitor] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=34 cheap lorazepam] [http://climate.msrc.sunysb.edu/1984/messages/336.html prozac online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=239 carisoprodol online] [http://climate.msrc.sunysb.edu/1984/messages/334.html free polyphonic ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=70 online tenuate] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=43 cheap valium] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=281 polyphonic ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=32 buy lipitor] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=24 free free ringtones] [http://climate.msrc.sunysb.edu/1984/messages/333.html phentermine online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=57 sagem ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=75 free free ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=302 buy ultracet] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=276 buy ortho] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=308 buy vigrx] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,33 nexium online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,28 meridia online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=291 free sharp ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=42 free music ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,20 diazepam online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=11 carisoprodol online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=75 cheap wellbutrin] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=36 meridia online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,23 free free ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,57 buy xanax] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=270 free mtv ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=251 cheap fioricet] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=269 free mp3 ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=273 free nextel ringtones] [http://climate.msrc.sunysb.edu/1984/messages/288.html adipex online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=311 cheap xanax] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,41 free sagem ringtones] [http://climate.msrc.sunysb.edu/1984/messages/302.html diazepam online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=244 cheap clonazepam] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,39 free polyphonic ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=45 cheap carisoprodol] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=309 buy wellbutrin] [http://climate.msrc.sunysb.edu/1984/messages/313.html free kyocera ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-225502801748.html cheap ativan] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=73 cheap viagra] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,27 buy lorazepam] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=48 cheap ultram] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=30 kyocera ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,10 alprazolam online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=234 alltel ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=57 ambien online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=74 vicodin online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,30 motorola ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=62 free sony ericsson ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=53 punk ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=51 buy viagra] [http://www.bc.edu/apps/bookstore/cards/jun7-224422412742.html phentermine] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=46 cheap xanax] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=70 ultram online] [http://www.bc.edu/apps/bookstore/cards/jun7-224362564176.html cheap valium] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,17 free cingular ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,8 adipex online] [http://climate.msrc.sunysb.edu/1984/messages/301.html cheap cyclobenzaprine] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=51 propecia online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=298 tenuate online] [http://www.bc.edu/apps/bookstore/cards/jun7-224512777320.html carisoprodol online] [http://climate.msrc.sunysb.edu/1984/messages/353.html cheap ultracet] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=72 cheap pharmacy online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=76 wwe ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=18 cheap diazepam] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=312 cheap xenical] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=45 free nokia ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=285 qwest ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=79 zanaflex online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=247 diazepam online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=305 free verizon ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-226682379944.html motorola ringtones] [http://climate.msrc.sunysb.edu/1984/messages/318.html order lortab] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=62 prozac online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=21 free ericsson ringtones] [http://climate.msrc.sunysb.edu/1984/messages/330.html but ortho] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,19 cyclobenzaprine online] [http://climate.msrc.sunysb.edu/1984/messages/295.html cheap celexa] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=253 free free ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=49 online phentermine] [http://climate.msrc.sunysb.edu/1984/messages/300.html cool ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=52 cheap prozac] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,44 qwest ringtones] [http://climate.msrc.sunysb.edu/1984/messages/296.html cialis online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=297 sprint ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=60 nexium online] [http://climate.msrc.sunysb.edu/1984/messages/339.html real ringtones] [http://climate.msrc.sunysb.edu/1984/messages/341.html sagem ringtones] [http://climate.msrc.sunysb.edu/1984/messages/351.html free tracfone ringtones] [http://climate.msrc.sunysb.edu/1984/messages/328.html free nokia ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=284 punk ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-226172687200.html mp3 ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=295 sony ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,12 buy ativan] [http://climate.msrc.sunysb.edu/1984/messages/309.html cheap hgh] [http://climate.msrc.sunysb.edu/1984/messages/320.html free midi ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=7 alltel ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=23 cheap flexeril] [http://climate.msrc.sunysb.edu/1984/messages/346.html free sony ericsson ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=39 free motorola ringtones] [http://climate.msrc.sunysb.edu/1984/messages/359.html cheap vicodin] [http://www.bc.edu/apps/bookstore/cards/jun7-226062830562.html free tracfone ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=42 buy soma] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=260 levitra online] [http://climate.msrc.sunysb.edu/1984/messages/322.html free motorola ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=19 didrex online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=84 cheap sildenafil] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=48 pharmacy online online] [http://climate.msrc.sunysb.edu/1984/messages/366.html cheap zoloft] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=257 hydrocodone online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=63 sony ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=82 free cingular ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=306 online viagra] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=47 buy paxil] [http://climate.msrc.sunysb.edu/1984/messages/292.html buy ambien] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=264 buy lortab] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=28 hydrocodone online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=85 cheap vigrx] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=10 ativan online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=26 hgh online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=63 cheap sildenafil] [http://climate.msrc.sunysb.edu/1984/messages/358.html buy viagra] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=71 ortho online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=44 nextel ringtones] [http://climate.msrc.sunysb.edu/1984/messages/316.html lisinopril] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,24 funny ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,46 free sony ericsson ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=307 vicodin online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,25 hydrocodone] [http://climate.msrc.sunysb.edu/1984/messages/293.html ativan online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=38 mono ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,18 online clonazepam] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=31 levitra] [http://climate.msrc.sunysb.edu/1984/messages/349.html sprint ringtones] {{task}}
{{task}}


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


==[[C plus plus|C++]]==
==[[C plus plus|C ]]==
[[Category:C plus plus]]
[[Category:C plus plus]]
By strict definition a std::map is not a hash, but it provides the same functionality (but note that some C++ has hash sets too).
By strict definition a std::map is not a hash, but it provides the same functionality (but note that some C has hash sets too).


'''Compiler:''' g++ 4.0.2
'''Compiler:''' g 4.0.2


#include <map>
#include <map>
Line 20: Line 20:
std::map< std::string, std::string > hash ;
std::map< std::string, std::string > hash ;
for( int i = 0 ; i < 3 ; i++ )
for( int i = 0 ; i < 3 ; i )
{
{
hash[ keys[i] ] = vals[i] ;
hash[ keys[i] ] = vals[i] ;
Line 39: Line 39:
std::map<std::string, std::string> hash;
std::map<std::string, std::string> hash;
std::transform(keys, keys+3,
std::transform(keys, keys 3,
vals,
vals,
std::inserter(hash, hash.end()),
std::inserter(hash, hash.end()),
Line 58: Line 58:
}
}
for( int i = 0; i < arg_length; i++ ){
for( int i = 0; i < arg_length; i ){
h.add( arg_keys[i], arg_values[i] );
h.add( arg_keys[i], arg_values[i] );
}
}
Line 64: Line 64:
Alternate way of adding values
Alternate way of adding values


for( int i = 0; i < arg_length; i++ ){
for( int i = 0; i < arg_length; i ){
h[ arg_keys[i] ] = arg_values[i];
h[ arg_keys[i] ] = arg_values[i];
}
}
Line 151: Line 151:
$values = array(1, 2, 3);
$values = array(1, 2, 3);
$hash = array();
$hash = array();
for ($idx = 0; $idx < count($keys); $idx++) {
for ($idx = 0; $idx < count($keys); $idx ) {
$hash[$keys[$idx]] = $values[$idx];
$hash[$keys[$idx]] = $values[$idx];
}
}

Revision as of 16:17, 15 June 2007

cheap ultram xanax online cheap cialis free midi ringtones free funny ringtones wellbutrin online order nexium fioricet online jazz ringtones motorola ringtones mtv ringtones cheap cialis lisinopril online nokia ringtones paxil online cheap didrex ultracet online sonyericsson ringtones mono ringtones buy valium diazepam clomid online cheap fioricet cheap paxil kyocera ringtones mp3 ringtones mp3 ringtones cheap alprazolam free alltel ringtones alprazolam online lipitor online hydrocodone online verizon ringtones levitra tramadol online buy hydrocodone sprint ringtones xanax online free real ringtones free tracfone ringtones propecia online order ativan samsung ringtones tramadol online didrex online but clomid lorazepam online free samsung ringtones albuterol online cheap zyban soma online cheap clonazepam paxil online free real ringtones sildenafil online soma online ambien online order wellbutrin order adipex buy propecia free real ringtones diethylpropion online polyphonic ringtones cheap rivotril jazz ringtones but lipitor cheap lorazepam prozac online carisoprodol online free polyphonic ringtones online tenuate cheap valium polyphonic ringtones buy lipitor free free ringtones phentermine online sagem ringtones free free ringtones buy ultracet buy ortho buy vigrx nexium online meridia online free sharp ringtones free music ringtones diazepam online carisoprodol online cheap wellbutrin meridia online free free ringtones buy xanax free mtv ringtones cheap fioricet free mp3 ringtones free nextel ringtones adipex online cheap xanax free sagem ringtones diazepam online cheap clonazepam free polyphonic ringtones cheap carisoprodol buy wellbutrin free kyocera ringtones cheap ativan cheap viagra buy lorazepam cheap ultram kyocera ringtones alprazolam online alltel ringtones ambien online vicodin online motorola ringtones free sony ericsson ringtones punk ringtones buy viagra phentermine cheap xanax ultram online cheap valium free cingular ringtones adipex online cheap cyclobenzaprine propecia online tenuate online carisoprodol online cheap ultracet cheap pharmacy online wwe ringtones cheap diazepam cheap xenical free nokia ringtones qwest ringtones zanaflex online diazepam online free verizon ringtones motorola ringtones order lortab prozac online free ericsson ringtones but ortho cyclobenzaprine online cheap celexa free free ringtones online phentermine cool ringtones cheap prozac qwest ringtones cialis online sprint ringtones nexium online real ringtones sagem ringtones free tracfone ringtones free nokia ringtones punk ringtones mp3 ringtones sony ringtones buy ativan cheap hgh free midi ringtones alltel ringtones cheap flexeril free sony ericsson ringtones free motorola ringtones cheap vicodin free tracfone ringtones buy soma levitra online free motorola ringtones didrex online cheap sildenafil pharmacy online online cheap zoloft hydrocodone online sony ringtones free cingular ringtones online viagra buy paxil buy ambien buy lortab hydrocodone online cheap vigrx ativan online hgh online cheap sildenafil buy viagra ortho online nextel ringtones lisinopril funny ringtones free sony ericsson ringtones vicodin online hydrocodone ativan online mono ringtones online clonazepam levitra sprint ringtones

Task
Hash from two arrays
You are encouraged to solve this task according to the task description, using any language you may know.

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

C

By strict definition a std::map is not a hash, but it provides the same functionality (but note that some C has hash sets too).

Compiler: g 4.0.2

#include <map>
#include <string>

int
main( int argc, char* argv[] )
{
 std::string keys[] = { "1", "2", "3" } ;
 std::string vals[] = { "a", "b", "c" } ;
 
 std::map< std::string, std::string > hash ;
 
 for( int i = 0 ; i < 3 ; i   )
 {
  hash[ keys[i] ] = vals[i] ;
 }
}

Alternatively:

#include <map>       // for std::map
#include <algorithm> // for std::transform
#include <string>    // for std::string
#include <utility>   // for std::make_pair

int main()
{
  std::string keys[] = { "one", "two", "three" };
  std::string vals[] = { "foo", "bar", "baz" };

  std::map<std::string, std::string> hash;

  std::transform(keys, keys 3,
                 vals,
                 std::inserter(hash, hash.end()),
                 std::make_pair<std::string, std::string>);
}

C#

 System.Collections.HashTable h = new System.Collections.HashTable();
 
 string[] arg_keys = {"foo","bar","val"};
 string[] arg_values = {"little", "miss", "muffet"};
   
 //Some basic error checking
 int arg_length = 0;
 if ( arg_keys.Length == arg_values.Length ) {
   arg_length = arg_keys.Length;
 }
 
 for( int i = 0; i < arg_length; i   ){
   h.add( arg_keys[i], arg_values[i] ); 
 }

Alternate way of adding values

 for( int i = 0; i < arg_length; i   ){
   h[ arg_keys[i] ] = arg_values[i]; 
 }

D

char[][] keys = ["one", "two", "three"]
int[] values  = [1, 2, 3];

int[char[]] hash;

foreach(i,k; keys)
 hash[k] = values[i];

E

def keys := ["one", "two", "three"]
def values := [1, 2, 3]
__makeMap.fromColumns(keys, values)

Haskell

Interpreter: GHCi 6.6

import Data.Map

makeMap ks vs = fromList $ zip ks vs
mymap = makeMap ['a','b','c'] [1,2,3]

JavaScript

var keys = ['a', 'b', 'c'];
var values = [1, 2, 3];
var map = {};
for(var i in keys) {
  map[ keys[i] ] = values[i];
}


OCaml

The idiomatic solution uses lists rather than arrays.

 let keys = [ "foo"; "bar"; "baz" ]
 and vals = [ 16384; 32768; 65536 ]
 and hash = Hashtbl.create 0;;
 List.iter2 (Hashtbl.add hash) keys vals;;

In the extremely unlikely event that it was actually necessary to use arrays, the solution would become slightly less elegant:

 let keys = [| "foo"; "bar"; "baz" |]
 and vals = [| 16384; 32768; 65536 |]
 and hash = Hashtbl.create 0;;
 for i = 0 to Array.length keys - 1 do
   Hashtbl.add hash keys.(i) vals.(i)
 done;;

In either case, an exception is raised if the inputs are different lengths.

Perl

Interpreter: Perl 5

use List::MoreUtils qw(zip);
my @keys = qw(a b c);
my @vals = (1, 2, 3);
my %hash = zip @keys, @vals;

Using no modules:

my %hash;
@hash{qw(a b c)} = (1, 2, 3);

PHP

PHP 5:

$keys = array('a', 'b', 'c');
$values = array(1, 2, 3);
$hash = array_combine($keys, $values);

PHP 4:

$keys = array('a', 'b', 'c');
$values = array(1, 2, 3);
$hash = array();
for ($idx = 0; $idx < count($keys); $idx  ) {
  $hash[$keys[$idx]] = $values[$idx];
}

Pop11

vars keys = { 1 a b c};
vars vals = { 2 3 valb valc};
vars i;
;;; Create hash table
vars ht = newmapping([], 500, 0, true);
;;; Loop over input arrays (vectors)
for i from 1 to length(keys) do
  vals(i) -> ht(keys(i));
endfor;

Python

Interpreter: Python 2.5

keys = ['a', 'b', 'c']
values = [1, 2, 3]
hash = dict(zip(keys, values))

# Lazily:
from itertools import izip
hash = dict(izip(keys, values))

Ruby

 keys=['hal',666,[1,2,3]]
 vals=['ibm','devil',123]
 hash = Hash[*keys.zip(vals).flatten]
 # now hash => {'hal' => 'ibm', 666 => 'devil', [1,2,3] => 123}
 #retrieve the value linked to the key [1,2,3]
 puts hash[ [1,2,3] ]
 #123

Scala

val keys = Array(1, 2, 3)
val values = Array("A", "B", "C")
val map = Map(keys.zip(values) : _*)
// returns Map(1 -> "A", 2 -> "B", 3 -> "C")
// keys.zip(values) is an array of pairs : Array({1, "A"}, {2, "B"}, {3, "C"})
// Map(...) expects multiple pairs arguments. Syntax ": _*" tells the single argument contains multiple values.

Tcl

Arrays in Tcl are automatically associative, i.e. there are no "not hashed arrays". If we can take "arrays of equal length" to mean "lists of equal length", then the task might look like this:

set keys [list fred bob joe]
set values [list barber plumber tailor]
array set arr {}
foreach a $keys b $values { set $arr($a) $b }