Hash from two arrays: Difference between revisions

From Rosetta Code
Content added Content deleted
(Undo revision 6371 by Special:Contributions/RrsVbp (User talk:RrsVbp) linkspam)
mNo edit summary
Line 1: Line 1:
[http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=195 mono ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=199 cheap zyban] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=363 free samsung ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2901 free mp3 ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30235 cheap soma] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=136 cheap ultram] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=72 cheap ambien] [http://students.hsc.unt.edu/housing/item.cfm?type=2862 vicodin online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30258 vicodin online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=182 funny ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2890 online zanaflex] [http://wc1.worldcrossing.com/WebX/.1de609dc albuterol online] [http://wc1.worldcrossing.com/WebX/.1de60a20 cheap nexium] [http://students.hsc.unt.edu/housing/item.cfm?type=2875 buy propecia] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=165 but ambien] [http://wc1.worldcrossing.com/WebX/.1de609f8 free nokia ringtones] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=350 alprazolam online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=139 viagra online] [http://students.hsc.unt.edu/housing/item.cfm?type=2874 ultracet online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=91 cheap hoodia] [http://news.engin.brown.edu/forums/thread-view.asp?tid=175 cheap cyclobenzaprine] [http://news.engin.brown.edu/forums/thread-view.asp?tid=201 free free ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=153 cheap phentermine] [http://students.hsc.unt.edu/housing/item.cfm?type=2848 cheap soma] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30337 free real ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=94 free jazz ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a0a vicodin] [http://students.hsc.unt.edu/housing/item.cfm?type=2896 zyban online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=178 free ericsson ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a01 sagem ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1346 diazepam online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=222 sharp ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a1d cingular ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30230 cheap adipex] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=138 free verizon ringtones] [http://wc1.worldcrossing.com/WebX/.1de609fe qwest ringtones] [http://wc1.worldcrossing.com/WebX/.1de609e4 cheap clonazepam] [http://wc1.worldcrossing.com/WebX/.1de60a31 buy zanaflex] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=106 mtv ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a1a free mtv ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a15 free kyocera ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=218 sony ericsson ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=132 tenuate online] [http://students.hsc.unt.edu/housing/item.cfm?type=2904 real ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=137 cheap valium] [http://news.engin.brown.edu/forums/thread-view.asp?tid=168 cheap paxil] [http://library.cshl.edu/wp/vb/member.php?u=1367 didrex online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30295 sildenafil online] [http://wc1.worldcrossing.com/WebX/.1de609f7 free nextel ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f3 free midi ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1348 cheap ativan] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=337 xanax online] [http://wc1.worldcrossing.com/WebX/.1de609e6 cyclobenzaprine online] [http://library.cshl.edu/wp/vb/member.php?u=1360 cheap lorazepam] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=162 alltel ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=176 didrex online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=204 mp3 ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2911 free cingular ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a07 tracfone ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30241 xanax online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=356 free tracfone ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=111 cheap norco] [http://wc1.worldcrossing.com/WebX/.1de60a13 fioricet online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=191 cheap lorazepam] [http://library.cshl.edu/wp/vb/member.php?u=1369 free ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2858 viagra online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=224 free wwe ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2852 buy xanax] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30307 zoloft online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30331 free ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a27 but sildenafil] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=145 xenical online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30339 samsung ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30294 prozac online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=176 ultracet online] [http://library.cshl.edu/wp/vb/member.php?u=1352 buy norco] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=189 but lipitor] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=362 free motorola ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=224 sagem ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=101 meridia online] [http://wc1.worldcrossing.com/WebX/.1de609ee but hydrocodone] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30244 cheap diazepam] [http://wc1.worldcrossing.com/WebX/.1de609e0 cheap ativan] [http://students.hsc.unt.edu/housing/item.cfm?type=2861 cheap norco] [http://students.hsc.unt.edu/housing/item.cfm?type=2877 cheap prozac] [http://news.engin.brown.edu/forums/thread-view.asp?tid=216 free sonyericsson ringtones] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=360 qwest ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=190 cheap lisinopril] [http://wc1.worldcrossing.com/WebX/.1de60a10 didrex online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=228 ultram online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=76 online cialis] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30259 cheap alprazolam] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=359 free nextel ringtones] [http://wc1.worldcrossing.com/WebX/.1de609e5 free cool ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2888 lortab online] [http://library.cshl.edu/wp/vb/member.php?u=1373 nextel ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=216 zyban online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=206 cheap pharmacy online] [http://library.cshl.edu/wp/vb/member.php?u=1344 xanax online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=344 ativan] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30345 sprint ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30248 ativan online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=131 free sprint ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2871 cheap wellbutrin] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=146 zanaflex online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=154 buy carisoprodol] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30280 cheap propecia] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=118 buy prozac] [http://library.cshl.edu/wp/vb/member.php?u=1341 valium online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=144 cheap xanax] [http://students.hsc.unt.edu/housing/item.cfm?type=2905 motorola ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=112 but ortho] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=223 wellbutrin online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=169 cheap levitra] [http://news.engin.brown.edu/forums/thread-view.asp?tid=156 fioricet] [http://library.cshl.edu/wp/vb/member.php?u=1377 samsung ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30312 ortho online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30356 free cool ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f0 lorazepam online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=187 celexa online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30230 cheap tramadol] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=211 free polyphonic ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=214 cheap zanaflex] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=110 free nokia ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=189 cheap ortho] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=237 free samsung ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=151 cheap soma] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=99 lorazepam online] [http://students.hsc.unt.edu/housing/item.cfm?type=2912 free sagem ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2907 sprint ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a17 lipitor online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30334 free mp3 ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=234 free sprint ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=141 vigrx online] [http://wc1.worldcrossing.com/WebX/.1de60a23 polyphonic ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a1f lisinopril online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=197 free mp3 ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1349 cheap viagra] [http://library.cshl.edu/wp/vb/member.php?u=1382 cingular ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30310 tenuate online] [http://students.hsc.unt.edu/housing/item.cfm?type=2922 free kyocera ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=206 free qwest ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f9 norco online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=351 buy clonazepam] [http://students.hsc.unt.edu/housing/item.cfm?type=2878 sildenafil online] [http://students.hsc.unt.edu/housing/item.cfm?type=2902 nextel ringtones] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=357 funny ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1347 but cialis] [http://library.cshl.edu/wp/vb/member.php?u=1365 cheap ultracet] [http://news.engin.brown.edu/forums/thread-view.asp?tid=210 sprint ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=158 diazepam online] [http://wc1.worldcrossing.com/WebX/.1de609ea free free ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a25 samsung ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=88 free free ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1358 hydrocodone online] [http://library.cshl.edu/wp/vb/member.php?u=1339 tramadol online] [http://students.hsc.unt.edu/housing/item.cfm?type=2868 cheap ambien] [http://news.engin.brown.edu/forums/thread-view.asp?tid=228 free mtv ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=104 free motorola ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=89 free funny ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=211 music ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=80 free cool ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1388 fioricet online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=361 free real ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=172 lorazepam online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=333 cheap soma] [http://news.engin.brown.edu/forums/thread-view.asp?tid=182 clomid online] [http://library.cshl.edu/wp/vb/member.php?u=1355 cheap clonazepam] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=205 cheap paxil] [http://news.engin.brown.edu/forums/thread-view.asp?tid=184 lisinopril online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=124 samsung ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a04 sonyericsson ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=115 cheap phentermine] [http://library.cshl.edu/wp/vb/member.php?u=1387 free alltel ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a05 sprint ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=167 clonazepam online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30283 didrex online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=157 cheap ultram] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=230 free verizon ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30309 celexa online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=348 norco] [http://wc1.worldcrossing.com/WebX/.1de60a11 diethylpropion online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=188 cheap tenuate] [http://news.engin.brown.edu/forums/thread-view.asp?tid=212 verizon ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30308 cheap lipitor] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=82 diazepam online] [http://library.cshl.edu/wp/vb/member.php?u=1380 free verizon ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=163 adipex online] [http://students.hsc.unt.edu/housing/item.cfm?type=2859 meridia online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=209 samsung ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=170 cingular ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=78 clomid online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30298 lisinopril online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=74 cheap carisoprodol] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=352 paxil online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=227 ericsson ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1386 mono ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=69 albuterol online] [http://wc1.worldcrossing.com/WebX/.1de60a12 ericsson ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=171 ambien online] {{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 20:04, 14 July 2007

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

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 }