From 59023d2a8877a3fc5fad700deb40373b5fc8f0a9 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 May 2022 16:18:38 -0400 Subject: [PATCH] Add VecSet::insert_all --- compiler/collections/src/vec_set.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/compiler/collections/src/vec_set.rs b/compiler/collections/src/vec_set.rs index 09730f7e95..d139272e89 100644 --- a/compiler/collections/src/vec_set.rs +++ b/compiler/collections/src/vec_set.rs @@ -40,6 +40,17 @@ impl VecSet { } } + /// Returns true iff any of the given elements previoously existed in the set. + pub fn insert_all>(&mut self, values: I) -> bool { + let mut any_existed = false; + + for value in values { + any_existed = any_existed || self.insert(value); + } + + any_existed + } + pub fn contains(&self, value: &T) -> bool { self.elements.contains(value) }