diff --git a/add-tag/Cargo.lock b/add-tag/Cargo.lock new file mode 100644 index 0000000..456ee48 --- /dev/null +++ b/add-tag/Cargo.lock @@ -0,0 +1,133 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "add-tag" +version = "0.1.0" +dependencies = [ + "rayon", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "crossbeam-channel" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "libc" +version = "0.2.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "rayon" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" diff --git a/add-tag/Cargo.toml b/add-tag/Cargo.toml new file mode 100644 index 0000000..d6ab931 --- /dev/null +++ b/add-tag/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "add-tag" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rayon = "*" diff --git a/add-tag/src/main.rs b/add-tag/src/main.rs new file mode 100644 index 0000000..1af8df3 --- /dev/null +++ b/add-tag/src/main.rs @@ -0,0 +1,63 @@ +use std::env; +use std::fs; +use std::fs::File; +use std::collections::HashSet; +use std::io::BufReader; +use std::io::BufWriter; +use std::io::prelude::*; + +use rayon::prelude::*; + +fn main() -> std::io::Result<()> { + let args: Vec<_> = env::args().collect(); + let map_file_path = args[1].clone(); + let cam_file_path = args[2].clone(); + let out_file_path = args[3].clone(); + println!("In file {}", map_file_path); + + let camera_ids_content = fs::read_to_string(cam_file_path) + .expect("Should have been able to read the file"); + + + let seen_from_camera_ids: HashSet<_> = camera_ids_content.lines().map(|l| format!("w{}", l)).collect(); + + println!("Loaded {} way ids seen from camera", seen_from_camera_ids.len()); + + let input = File::open(map_file_path)?; + let input = BufReader::new(input); + + let output = File::create(out_file_path)?; + let mut output = BufWriter::new(output); + + let mut line_iter = input.lines(); + + loop { + let mut batch = vec![]; + for _ in 0..3_000_000 { + if let Some(line) = line_iter.next() { + batch.push(line?); + } else { + break; + } + } + + if batch.is_empty() { + break; + } + + let out_batch: String = batch.into_par_iter() + .map(|line| { + if line.starts_with('w') && seen_from_camera_ids.contains(line.split(' ').next().unwrap()) { + line.replace(" T", " Tcamera=yes,") + } else { + line + } + }) + .reduce(String::new, + |mut a, b| { a.push_str(&b); a.push('\n'); a }); + + output.write_all(out_batch.as_bytes())?; + } + + Ok(()) +}