Hash from two arrays: Difference between revisions

m
no edit summary
mNo edit summary
Line 1:
[http://mike12305.ifrance.com/lib/i-ll/ i ll say a little prayer] [http://raneely.125mb.com/text/belle-aperte.htm belle aperte] [http://superspounge.ifrance.com/gardner-john/ gardner john] [http://raneely.125mb.com/text/www-i.htm www i r a terrorismo] [http://raneely.125mb.com/text/sperma-femminile.htm sperma femminile] [http://mamerium.125mb.com/acer.htm acer 32] [http://kuzelka111.ifrance.com/lib/teach-you/ teach you childres] [http://mamerium.125mb.com/millyd-abbraccio.htm millyd abbraccio] [http://bakedsmurf.ifrance.com/description/campari/ campari] [http://sylverrain.ifrance.com/data/braun-cruzer/ braun cruzer 2865] [http://todkonda.ifrance.com/content/polar-f/ polar f2] [http://bakedsmurf.ifrance.com/description/eizo-tft/ eizo tft 19 l778] [http://madavidan.125mb.com/text/mapa-mentales.htm mapa mentales] [http://dragonzgrace.ifrance.com/description/usb-isdn/ usb isdn ta driver] [http://stbrocke.125mb.com/content/il-management.htm il management nell era della connessione] [http://raneely.125mb.com/text/counting-crows.htm counting crows] [http://prkinardan.125mb.com/styles/formato-a.htm formato a3 stampante laser colori] [http://earthlygnome.ifrance.com/lettore-mp/ lettore mp3 fm mmc] [http://kuzelka111.ifrance.com/lib/kodak-dx/ kodak dx7590 zoom easyshare] [http://raneely.125mb.com/text/albergo-auckland.htm albergo auckland] [http://bakedsmurf.ifrance.com/description/nassirya/ nassirya] [http://raneely.125mb.com/text/luna-e.htm luna e stelle] [http://superspounge.ifrance.com/usb-motorola/ usb motorola pc 220] [http://earthlygnome.ifrance.com/sinfonia-/ sinfonia 40 mozart] [http://stbrocke.125mb.com/content/image.htm image] [http://doloeb.125mb.com/cucina-componibile.htm cucina componibile] [http://prkinardan.125mb.com/styles/giuseppe-martoni.htm giuseppe martoni] [http://mike12305.ifrance.com/lib/parques-nacionales/ parques nacionales de reserva del peru] [http://madavidan.125mb.com/text/you-touch.htm you touch my tra] [http://doloeb.125mb.com/fifa-footbal.htm fifa footbal 2004] [http://superspounge.ifrance.com/light-house/ light house of family] [http://kamedcal.125mb.com/scooty-doesn.htm scooty doesn t know] [http://mcgoley.125mb.com/articles/schiav.htm schiav] [http://bakedsmurf.ifrance.com/description/prova-di/ prova di tecnica e organizzazione aziend] [http://earthlygnome.ifrance.com/frankfurt-an/ frankfurt an der oder] [http://kamedcal.125mb.com/foto-dei.htm foto dei culi piu] [http://kewheatl.125mb.com/library/trans-flash.htm trans flash e1000] [http://vanopo.ifrance.com/library/orgoglio-napoletano/ orgoglio napoletano] [http://todkonda.ifrance.com/content/se-stiamo/ se stiamo insieme] [http://kamedcal.125mb.com/le-parole.htm le parole di girasole di giorgia] [http://kewheatl.125mb.com/library/voglio-fare.htm voglio fare sesso] [http://superspounge.ifrance.com/grotta-frasassi/ grotta frasassi] [http://doloeb.125mb.com/photo-hard.htm photo hard disk] [http://bemedad.125mb.com/blog/arriva-wonder.htm arriva wonder woman] [http://kamedcal.125mb.com/zoom-.htm zoom 90 calcio] [http://kuzelka111.ifrance.com/lib/giochi-di/ giochi di sala gochi 200] [http://stbrocke.125mb.com/content/rs-dual.htm rs dual voltage 128] [http://bakedsmurf.ifrance.com/description/rx-v/ rx v450] [http://superspounge.ifrance.com/shemale-cum/ shemale cum] [http://mike12305.ifrance.com/lib/trust-protector/ trust protector 600] [http://bakedsmurf.ifrance.com/description/liftiba/ liftiba] [http://kewheatl.125mb.com/library/parola-marina.htm parola marina] [http://stbrocke.125mb.com/content/arrebatados.htm arrebatados] [http://todkonda.ifrance.com/content/wwwregione-lazio/ wwwregione lazio it] [http://madavidan.125mb.com/text/i-primi.htm i primi turbamenti] [http://kewheatl.125mb.com/library/fuck-u.htm fuck u right back] [http://doloeb.125mb.com/schiamazzi-notturni.htm schiamazzi notturni] [http://mcgoley.125mb.com/articles/trasparenze-intimo.htm trasparenze intimo] [http://mamerium.125mb.com/plextor-x.htm plextor 48x] [http://earthlygnome.ifrance.com/bonstetten-charles/ bonstetten charles victor de] [http://stbrocke.125mb.com/content/giochi-miniclip.htm giochi miniclip] [http://dragonzgrace.ifrance.com/description/auto-metano/ auto metano occasione] [http://mamerium.125mb.com/fodere-sedili.htm fodere sedili] [http://superspounge.ifrance.com/tour-/ tour 2004 raf] [http://kewheatl.125mb.com/library/conversazioni-erotiche.htm conversazioni erotiche] [http://dragonzgrace.ifrance.com/description/biagio-antonacci/ biagio antonacci midi] [http://mcgoley.125mb.com/articles/three-by.htm three by rambert rambert dance company] [http://kuzelka111.ifrance.com/lib/berluska/ berluska] [http://vanopo.ifrance.com/library/happy-days/ happy days sister acr] [http://raneely.125mb.com/text/registratori-dvd.htm registratori dvd vcr] [http://superspounge.ifrance.com/finalmente-le/ finalmente le due torri] [http://kuzelka111.ifrance.com/lib/sesso-da/ sesso da vedere] [http://doloeb.125mb.com/tutto-per.htm tutto per inculare] [http://kewheatl.125mb.com/library/oakley-a.htm oakley a wire 2 0] [http://kuzelka111.ifrance.com/lib/auto-noleggio/ auto noleggio cosenza] [http://mamerium.125mb.com/fujifilm-z.htm fujifilm z1] [http://mamerium.125mb.com/farinata-ricetta.htm farinata ricetta] [http://stbrocke.125mb.com/content/per-fare.htm per fare quiz patentino] [http://vanopo.ifrance.com/library/rivoluzione-industriale/ rivoluzione industriale scoperte] [http://kuzelka111.ifrance.com/lib/calendario-porcone/ calendario porcone di questo anno] [http://kuzelka111.ifrance.com/lib/hp-deskjet/ hp deskjet 3820] [http://doloeb.125mb.com/amd-sempron.htm amd sempron 2500] [http://mamerium.125mb.com/gallo.htm gallo] [http://mamerium.125mb.com/piccolo-uomo.htm piccolo uomo] [http://raneely.125mb.com/text/the-machine.htm the machine] [http://sylverrain.ifrance.com/data/cameron-dias/ cameron dias] [http://madavidan.125mb.com/text/porta-per.htm porta per doccia] [http://bakedsmurf.ifrance.com/description/dayse-brucieri/ dayse brucieri] [http://mcgoley.125mb.com/articles/weisse-elster.htm weisse elster] [http://kewheatl.125mb.com/library/le-piu.htm le piu belle derbi] [http://madavidan.125mb.com/text/claudia-marsani.htm claudia marsani] [http://mcgoley.125mb.com/articles/valentino-ken.htm valentino ken russell] [http://mike12305.ifrance.com/lib/www-irfo/ www irfo it] [http://madavidan.125mb.com/text/dv-rsmmc.htm dv rsmmc dv 512] [http://bakedsmurf.ifrance.com/description/batteria-a/ batteria a1000] [http://mcgoley.125mb.com/articles/lasciami-viva.htm lasciami viva] [http://bemedad.125mb.com/blog/padre-figlia.htm padre figlia] [http://bemedad.125mb.com/blog/testi-fiorella.htm testi fiorella mannoia] [http://mamerium.125mb.com/dvp-ns.htm dvp ns 32 nero] [http://sylverrain.ifrance.com/data/clip-raggae/ clip raggae] [http://madavidan.125mb.com/text/holding-out.htm holding out for a hero bonnie tyler] [http://vanopo.ifrance.com/library/incontri-trans/ incontri trans] [http://mcgoley.125mb.com/articles/davis.htm davis] [http://stbrocke.125mb.com/content/modem-linux.htm modem linux] [http://raneely.125mb.com/text/sex-fto.htm sex fto] [http://prkinardan.125mb.com/styles/tv-e.htm tv e wifi] [http://mcgoley.125mb.com/articles/kenwood-kit.htm kenwood kit cinema 4 3] [http://sylverrain.ifrance.com/data/videoproiettori-/ videoproiettori 1500 ansi lumen] [http://bemedad.125mb.com/blog/roberto-mariani.htm roberto mariani] [http://todkonda.ifrance.com/content/rescue-dawn/ rescue dawn] [http://raneely.125mb.com/text/palmari-barcode.htm palmari barcode] [http://kewheatl.125mb.com/library/www-regionecampania.htm www regionecampania] [http://mamerium.125mb.com/stampante-hp.htm stampante hp 450] [http://kewheatl.125mb.com/library/tvc-sony.htm tvc sony plasma] [http://kewheatl.125mb.com/library/motore-ricerca.htm motore ricerca posizionamenti] [http://sylverrain.ifrance.com/data/blank-cds/ blank cds] [http://todkonda.ifrance.com/content/la-forza/ la forza della vita] [http://dragonzgrace.ifrance.com/description/dvd-recorder/ dvd recorder 80gb] [http://superspounge.ifrance.com/tommy-v/ tommy v compilation] [http://mamerium.125mb.com/lugo-ravenna.htm lugo (ravenna)] [http://kewheatl.125mb.com/library/execelsior.htm execelsior] [http://earthlygnome.ifrance.com/pentium/ pentium 3 4] [http://madavidan.125mb.com/text/a-marechiaro.htm a marechiaro] [http://dragonzgrace.ifrance.com/description/occhiali-da/ occhiali da sole dolce e gabbana] [http://kuzelka111.ifrance.com/lib/ps-iso/ ps2 iso] [http://sylverrain.ifrance.com/data/last-minute/ last minute rodi] [http://bemedad.125mb.com/blog/la-fidanzata.htm la fidanzata di mio marito] [http://mike12305.ifrance.com/lib/fiat-stilo/ fiat stilo multiwagon jtd] [http://kuzelka111.ifrance.com/lib/teoria-e/ teoria e tecnica] [http://bemedad.125mb.com/blog/rifiuti.htm rifiuti] [http://dragonzgrace.ifrance.com/description/testo-carmelo/ testo carmelo zappulla] [http://superspounge.ifrance.com/software-contabilita/ software contabilita semplificata] [http://prkinardan.125mb.com/styles/zoom-nikkor.htm zoom nikkor] [http://sylverrain.ifrance.com/data/the-doors/ the doors film] [http://kamedcal.125mb.com/fells-like.htm fells like home] [http://superspounge.ifrance.com/toner-ricoh/ toner ricoh cl1000n] [http://sylverrain.ifrance.com/data/pamela-cartoni/ pamela cartoni] [http://doloeb.125mb.com/sex-machine.htm sex machine] [http://todkonda.ifrance.com/content/batterie-sony/ batterie sony v1] [http://mike12305.ifrance.com/lib/iscrizione-registro/ iscrizione registro moto d epoca] [http://doloeb.125mb.com/cover-platinum.htm cover platinum collection mina] [http://raneely.125mb.com/text/pescia.htm pescia] [http://stbrocke.125mb.com/content/big-clarence.htm big clarence] [http://stbrocke.125mb.com/content/foto-mogli.htm foto mogli] [http://stbrocke.125mb.com/content/paradiso-beach.htm paradiso beach] [http://earthlygnome.ifrance.com/campionato-di/ campionato di calcio tedesco] [http://kuzelka111.ifrance.com/lib/kit-gps/ kit gps route 66] [http://kamedcal.125mb.com/leone-di.htm leone di lernia] [http://prkinardan.125mb.com/styles/accessori-per.htm accessori per doccia] [http://dragonzgrace.ifrance.com/description/facciolini/ facciolini] [http://mike12305.ifrance.com/lib/www-mexxico/ www mexxico com] [http://doloeb.125mb.com/memoria-ram.htm memoria ram samsung 512] [http://prkinardan.125mb.com/styles/festa-arma.htm festa arma carabiniere] [http://stbrocke.125mb.com/content/cnc-usati.htm cnc usati] [http://earthlygnome.ifrance.com/foro/ foro] [http://sylverrain.ifrance.com/data/emanuele-filiberto/ emanuele filiberto] [http://kewheatl.125mb.com/library/smallvill.htm smallvill] [http://earthlygnome.ifrance.com/erbe/ erbe] [http://madavidan.125mb.com/text/letras.htm letras] [http://vanopo.ifrance.com/library/eco-der/ eco der core] [http://vanopo.ifrance.com/library/manualidades/ manualidades] [http://bemedad.125mb.com/blog/calde-notti.htm calde notti destate] [http://mcgoley.125mb.com/articles/trova.htm trova] [http://prkinardan.125mb.com/styles/cellulare-e.htm cellulare e palmare gps gprs] [http://earthlygnome.ifrance.com/image-styles/ image styles] [http://todkonda.ifrance.com/content/eternita/ eternita] [http://superspounge.ifrance.com/delirium-tremens/ delirium tremens] [http://kuzelka111.ifrance.com/lib/duran-duran/ duran duran sunrise] [http://earthlygnome.ifrance.com/calenda-maia/ calenda maia] [http://mike12305.ifrance.com/lib/ceramiche-dolomite/ ceramiche dolomite] [http://kamedcal.125mb.com/colombari-it.htm colombari it] [http://kuzelka111.ifrance.com/lib/decreto-legislativo/ decreto legislativo 303 91] [http://mike12305.ifrance.com/lib/d-a/ d a b autoradio] [http://madavidan.125mb.com/text/affinita-nomi.htm affinita nomi] [http://kamedcal.125mb.com/teh-power.htm teh power of love] [http://mike12305.ifrance.com/lib/la-dcc/ la dc52c] [http://prkinardan.125mb.com/styles/noi-no.htm noi no] [http://doloeb.125mb.com/scorte.htm scorte] [http://bemedad.125mb.com/blog/nautica-gommoni.htm nautica gommoni] [http://prkinardan.125mb.com/styles/agarum.htm agarum] [http://prkinardan.125mb.com/styles/eyes-com.htm 99eyes com] [http://dragonzgrace.ifrance.com/description/gnr/ gnr] [http://bemedad.125mb.com/blog/toronto-sun.htm toronto sun com] [http://madavidan.125mb.com/text/el-chad.htm el chad] [http://vanopo.ifrance.com/library/hard-disk/ hard disk usb 500gb] [http://kuzelka111.ifrance.com/lib/amilo-/ amilo 1 6 centrino] [http://prkinardan.125mb.com/styles/i-storm.htm i storm modem atlantis land] [http://prkinardan.125mb.com/styles/embalaje.htm embalaje] [http://mike12305.ifrance.com/lib/smash-hit/ smash hit] [http://superspounge.ifrance.com/canon-pixma/ canon pixma ip3000] [http://bemedad.125mb.com/blog/le-vibrazioni.htm le vibrazioni testi canzoni] [http://madavidan.125mb.com/text/elenco-presidenti.htm elenco presidenti usa] [http://raneely.125mb.com/text/nef.htm nef] [http://stbrocke.125mb.com/content/gli-appuntamenti.htm gli appuntamenti nintendo per il nuovo anno] [http://kamedcal.125mb.com/hard-disck.htm hard disck telecomando] [http://stbrocke.125mb.com/content/arab-film.htm arab film] [http://bakedsmurf.ifrance.com/description/corse-dei/ corse dei cavalii] [http://bakedsmurf.ifrance.com/description/valente-vitantonio/ valente vitantonio] [http://dragonzgrace.ifrance.com/description/hard-disc/ hard disc esterno] [http://mike12305.ifrance.com/lib/www-fichet/ www fichet it] {{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)
Line 44:
end loop;
for I in Key_List'range loop
Ada.Text_Io.Put_Line(To_String(Key_List(I)) & " => " &
To_String(Hash.Element(Key_List(I))));
end loop;
end Hash_Map_Test;
 
==[[C plus plus|C++]]==
[[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).
 
'''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 sharp|C#]]==
[[Category:C sharp]]
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]]==
[[Category:D]]
 
char[][] keys = ["one", "two", "three"]
int[] values = [1, 2, 3];
int[char[]] hash;
foreach(i,k; keys)
hash[k] = values[i];
==[[E]]==
[[Category:E]]
 
def keys := ["one", "two", "three"]
def values := [1, 2, 3]
__makeMap.fromColumns(keys, values)
 
==[[Haskell]]==
[[Category:Haskell]]
'''Interpreter:''' [[GHC|GHCi]] 6.6
import Data.Map
makeMap ks vs = fromList $ zip ks vs
mymap = makeMap ['a','b','c'] [1,2,3]
 
==[[JavaScript]]==
[[Category:JavaScript]]
 
var keys = ['a', 'b', 'c'];
var values = [1, 2, 3];
var map = {};
for(var i in keys) {
map[ keys[i] ] = values[i];
}
 
 
==[[OCaml]]==
[[Category: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]]==
[[Category: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]]==
 
[[Category: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]]==
[[Category: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]]==
 
[[Category:Python]]
'''Interpreter:''' [[Python]] 2.5
<pre>
keys = ['a', 'b', 'c']
values = [1, 2, 3]
hash = dict(zip(keys, values))
 
# Lazily:
from itertools import izip
hash = dict(izip(keys, values))
</pre>
 
==[[Ruby]]==
[[Category: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]] ==
[[Category: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]] ==
[[Category: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 "<i>lists</i> 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 }
Anonymous user