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). |
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 { |
||
if let Some(vals) = h.get(b.0) { |
|||
for &val in vals { |
|||
let a = table_a.get(val).unwrap(); |
|||
println!("{:?} {:?}", a, b); |
|||
} |
|||
} |
} |
||
} |
} |