// see if there are any categories such that they can only accept a single set of values
// it takes categories by value and returns a new vec rather than do everything by reference
// to decrease the search space and increase performance by that sweet 10% bringing it all
// [on my machine] below 1ms
see if there are any categories such that they can only accept a single set of values
it takes categories by value and returns a new vec rather than do everything by reference
to decrease the search space and increase performance by that sweet 10% bringing it all
[on my machine] below 1ms
see if there are any categories such that they can only accept a single set of values it takes categories by value and returns a new vec rather than do everything by reference to decrease the search space and increase performance by that sweet 10% bringing it all [ on my machine ] below 1ms
fn try_get_fixed_categories(
    category_values: &mut HashMap<usize, Vec<usize>>,
    categories: Vec<Category>,
) -> (HashMap<usize, Category>, Vec<Category>) {
    let mut matched = HashMap::new();
    let mut remaining = Vec::new();
    for category in categories.into_iter() {
        let mut is_unique = true;
        let mut good_index = usize::max_value();
        for (category_idx, values) in category_values.iter() {
            if values.iter().all(|val| category.is_valid_value(*val)) {
                if good_index != usize::max_value() {
                    is_unique = false;
                    break;
                } else {
                    good_index = *category_idx
                }
            }
        }
        if is_unique && good_index != usize::max_value() {
            matched.insert(good_index, category);
        } else {
            remaining.push(category);
        }
    }
    for idx in matched.keys() {
        category_values.remove(idx);
    }
    (matched, remaining)
}
fn try_get_fixed_categories ( category_values : & mut HashMap < usize , Vec < usize > > , categories : Vec < Category > , ) -> ( HashMap < usize , Category > , Vec < Category > ) { let mut matched = HashMap :: new ( ) ; let mut remaining = Vec :: new ( ) ; for category in categories . into_iter ( ) { let mut is_unique = true ; let mut good_index = usize :: max_value ( ) ; for ( category_idx , values ) in category_values . iter ( ) { if values . iter ( ) . all ( | val | category . is_valid_value ( * val ) ) { if good_index != usize :: max_value ( ) { is_unique = false ; break ; } else { good_index = * category_idx } } } if is_unique && good_index != usize :: max_value ( ) { matched . insert ( good_index , category ) ; } else { remaining . push ( category ) ; } } for idx in matched . keys ( ) { category_values . remove ( idx ) ; } ( matched , remaining ) }
see if there are any categories such that they can only accept a single set of values
it takes categories by value and returns a new vec rather than do everything by reference
to decrease the search space and increase performance by that sweet 10% bringing it all
[on my machine] below 1ms
see if there are any categories such that they can only accept a single set of values it takes categories by value and returns a new vec rather than do everything by reference to decrease the search space and increase performance by that sweet 10% bringing it all [ on my machine ] below 1ms
category_values
&mut HashMap<usize, Vec<usize>>
categories
Vec<Category>