1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

tsort: use iterators to remove from vec

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
This commit is contained in:
jfinkels 2025-01-11 11:47:23 -05:00 committed by GitHub
parent af99952de6
commit 700a5f007a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -105,13 +105,10 @@ fn remove<T>(vec: &mut Vec<T>, x: T) -> Option<usize>
where
T: PartialEq,
{
for i in 0..vec.len() {
if vec[i] == x {
vec.remove(i);
return Some(i);
}
}
None
vec.iter().position(|item| *item == x).map(|i| {
vec.remove(i);
i
})
}
// We use String as a representation of node here