// Compare an Add or Self with another Add
Compare an Add or Self with another Add
Compare an Add or Self with another Add
fn cmp_add_chain(&self, other: &Self) -> Option<Self> {
        let mut chain_1 = self.flatten_add_chain();
        let mut chain_2 = other.flatten_add_chain();
        // Remove common elements from chain_1
        chain_1.drain_filter(|cost_1| {
            let res = chain_2.contains(cost_1);
            if res {
                let chain_2_index = chain_2
                    .iter()
                    .position(|cost_2| *cost_1 == *cost_2)
                    .unwrap();
                chain_2.remove(chain_2_index);
            }
            res
        });
        // We can say something only if at least one of them is empty,
        // otherwise cannot decide which has most cost
        if chain_1.is_empty() && chain_2.is_empty() || chain_1.is_empty() {
            // Both chains have equal value OR
            // Chain 2 is bigger
            Some((*other).clone())
        } else if chain_2.is_empty() {
            // Chain 1 is bigger
            Some((*self).clone())
        } else {
            None
        }
    }
fn cmp_add_chain ( & self , other : & Self ) -> Option < Self > { let mut chain_1 = self . flatten_add_chain ( ) ; let mut chain_2 = other . flatten_add_chain ( ) ; // Remove common elements from chain_1 chain_1 . drain_filter ( | cost_1 | { let res = chain_2 . contains ( cost_1 ) ; if res { let chain_2_index = chain_2 . iter ( ) . position ( | cost_2 | * cost_1 == * cost_2 ) . unwrap ( ) ; chain_2 . remove ( chain_2_index ) ; } res } ) ; // We can say something only if at least one of them is empty, // otherwise cannot decide which has most cost if chain_1 . is_empty ( ) && chain_2 . is_empty ( ) || chain_1 . is_empty ( ) { // Both chains have equal value OR // Chain 2 is bigger Some ( ( * other ) . clone ( ) ) } else if chain_2 . is_empty ( ) { // Chain 1 is bigger Some ( ( * self ) . clone ( ) ) } else { None } }
Compare an Add or Self with another Add
Compare an Add or Self with another Add
&self
other
&Self