Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
24
Task/Hash-join/Rust/hash-join.rust
Normal file
24
Task/Hash-join/Rust/hash-join.rust
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
fn main() {
|
||||
let table_a = vec![
|
||||
(27, "Jonah"), (18, "Alan"), (28, "Glory"),
|
||||
(18, "Popeye"), (28, "Alan")
|
||||
];
|
||||
let table_b = vec![
|
||||
("Jonah", "Whales"), ("Jonah", "Spiders"), ("Alan", "Ghosts"),
|
||||
("Alan", "Zombies"), ("Glory", "Buffy")
|
||||
];
|
||||
// hash phase
|
||||
let mut h = HashMap::new();
|
||||
for (i, a) in table_a.iter().enumerate() {
|
||||
h.entry(a.1).or_insert(vec![]).push(i);
|
||||
}
|
||||
// join phase
|
||||
for b in table_b {
|
||||
for i in h.get(b.0).unwrap_or(&vec![]) {
|
||||
let a = table_a.get(*i).unwrap();
|
||||
println!("{:?} {:?}", a, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue