From 8d4f04b0da0f9aceab436d21c7cc959d7f935a96 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 7 Jun 2025 11:04:30 +0200 Subject: pkgs/tskm: Merge tags of inputs, which have to same url --- pkgs/by-name/ts/tskm/src/interface/input/mod.rs | 32 +++++++++++++++++-------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'pkgs/by-name/ts/tskm/src/interface/input/mod.rs') diff --git a/pkgs/by-name/ts/tskm/src/interface/input/mod.rs b/pkgs/by-name/ts/tskm/src/interface/input/mod.rs index 747ba349..1d1d67f4 100644 --- a/pkgs/by-name/ts/tskm/src/interface/input/mod.rs +++ b/pkgs/by-name/ts/tskm/src/interface/input/mod.rs @@ -9,7 +9,12 @@ // If not, see . use std::{ - collections::HashSet, fmt::Display, fs, io::Write, path::PathBuf, process::Command, + collections::{HashMap, HashSet}, + fmt::Display, + fs, + io::Write, + path::PathBuf, + process::Command, str::FromStr, }; @@ -58,7 +63,7 @@ impl Tag { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Input { url: Url, tags: HashSet, @@ -175,7 +180,7 @@ impl Input { Ok(()) } - /// Get all previously [`Self::commit`]ed inputs. + /// Get all previously [committed][`Self::commit`] inputs. /// /// # Errors /// When IO handling fails. @@ -203,13 +208,20 @@ impl Input { let url_values = fs::read_to_string(PathBuf::from(url_value_file))?; - output.extend( - url_values - .lines() - .map(Self::from_str) - .collect::, _>>()? - .into_iter(), - ); + let mut inputs: HashMap = HashMap::new(); + for input in url_values + .lines() + .map(Self::from_str) + .collect::, _>>()? + { + if let Some(found) = inputs.get_mut(&input.url) { + found.tags = found.tags.union(&input.tags).cloned().collect(); + } else { + assert_eq!(inputs.insert(input.url.clone(), input), None); + } + } + + output.extend(inputs.drain().map(|(_, value)| value)); } Ok(output) -- cgit 1.4.1