Finding max values in a sequence

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.

What is the approximate length of self.coloring? You might consider bitvec if it's not too big.

it can be 1000s of elements long, unlikely to reach 10,000

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.