fn transitively_contains(
        bag: &str,
        contained_bag: &str,
        rules: &BTreeMap<String, Vec<BagSpec>>,
        cache: &mut BTreeMap<String, bool>,
    ) -> bool {
        if let Some(&result) = cache.get(bag) {
            return result;
        }

        if let Some(specs) = rules.get(bag) {
            for spec in specs {
                if spec.bagtype == contained_bag
                    || transitively_contains(&spec.bagtype, contained_bag, rules, cache)
                {
                    cache.insert(bag.into(), true);
                    return true;
                }
            }
            cache.insert(bag.into(), false);
            return false;
        } else {
            println!("No rule found for bag '{}'", bag);
            return false;
        }
    }
// recursive function declared inside function to avoid using the same cache
// with different target bagtype
recursive function declared inside function to avoid using the same cache
with different target bagtype
recursive function declared inside function to avoid using the same cache with different target bagtype
fn transitively_contains(
        bag: &str,
        contained_bag: &str,
        rules: &BTreeMap<String, Vec<BagSpec>>,
        cache: &mut BTreeMap<String, bool>,
    ) -> bool {
        if let Some(&result) = cache.get(bag) {
            return result;
        }
        if let Some(specs) = rules.get(bag) {
            for spec in specs {
                if spec.bagtype == contained_bag
                    || transitively_contains(&spec.bagtype, contained_bag, rules, cache)
                {
                    cache.insert(bag.into(), true);
                    return true;
                }
            }
            cache.insert(bag.into(), false);
            return false;
        } else {
            println!("No rule found for bag '{}'", bag);
            return false;
        }
    }
fn transitively_contains ( bag : & str , contained_bag : & str , rules : & BTreeMap < String , Vec < BagSpec > > , cache : & mut BTreeMap < String , bool > , ) -> bool { if let Some ( & result ) = cache . get ( bag ) { return result ; } if let Some ( specs ) = rules . get ( bag ) { for spec in specs { if spec . bagtype == contained_bag || transitively_contains ( & spec . bagtype , contained_bag , rules , cache ) { cache . insert ( bag . into ( ) , true ) ; return true ; } } cache . insert ( bag . into ( ) , false ) ; return false ; } else { println ! ( " " bag ) ; return false ; } }
recursive function declared inside function to avoid using the same cache
with different target bagtype
recursive function declared inside function to avoid using the same cache with different target bagtype
bag
&str
contained_bag
&str
rules
&BTreeMap<String, Vec<BagSpec>>
cache
&mut BTreeMap<String, bool>
bag
&str
contained_bag
&str
rules
&BTreeMap<String, Vec<BagSpec>>
cache
&mut BTreeMap<String, bool>