I'm working through some problems in Operations Research (in this case graph coloring) and I'd like to make the code below more performant, while still being elegant and expressive [no for loops, if possible]
The vector coloring
has integer values of colors. One of my heavy duty functions is to find all vertices belonging to a color class k
pub fn color_class(&self, k: &usize) -> OrdSet<usize> {
self.coloring.iter().enumerate().filter(|(_, color)| color == *color_class_id).map(|(id, _)| id).collect()
}
In this case, I am using the im
crate, since I use clone
very heavily, creating a lot of structs which are very marginally different from each other.
I have not done any benchmarking to see if it helps wrt. using standard options like BTreeSet, but could do so in the future.