Hash join: Difference between revisions

Content added Content deleted
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
(→‎{{header|Rust}}: Make more idiomatic)
Line 2,288: Line 2,288:


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>
<lang rust>use std::collections::HashMap;
use std::collections::HashMap;


fn main() {
fn main() {
Line 2,303: Line 2,302:
let mut h = HashMap::new();
let mut h = HashMap::new();
for (i, a) in table_a.iter().enumerate() {
for (i, a) in table_a.iter().enumerate() {
h.entry(a.1).or_insert(vec![]).push(i);
h.entry(a.1).or_insert_with(Vec::new).push(i);
}
}
// join phase
// join phase
for b in table_b {
for b in table_b {
for i in h.get(b.0).unwrap_or(&vec![]) {
if let Some(vals) = h.get(b.0) {
let a = table_a.get(*i).unwrap();
for &val in vals {
println!("{:?} {:?}", a, b);
let a = table_a.get(val).unwrap();
println!("{:?} {:?}", a, b);
}
}
}
}
}