<commit_before>#include "complex_range_selector.h"

namespace dream_hacking {

        ComplexRangeSelector::ComplexRangeSelector() {
        }

        ComplexRangeSelector::~ComplexRangeSelector() {
        }

        bool ComplexRangeSelector::Test(const std::vector<PlayingCard>& deck) const{
                if (selectors.empty()){
                        return true;
                } else {
                        auto localSelectors = selectors;

                        size_t len = deck.size();
                        for (size_t i = start; i < len; ++i){
                                const PlayingCard& card = deck[i];
                                auto it = localSelectors.begin();
                                while (it != localSelectors.end()){
                                        const PRangeSelector& selector = *it;
                                        if (i > selector->to){
                                                if (!selector->DefaultReturn())
                                                        return false;
                                                it = localSelectors.erase(it);
                                        } else if (i >= selector->from){
                                                auto res = selector->CheckCard(card);
                                                if (res == RangeSelector::Error)
                                                        return false;
                                                else if (res == RangeSelector::Ok)
                                                        it = localSelectors.erase(it);
                                                else
                                                        ++it;
                                        } else
                                                ++it;
                                }
                        }

                        for (auto it = localSelectors.begin(); it != localSelectors.end(); ++it){
                                PRangeSelector& selector = *it;
                                if (!selector->DefaultReturn())
                                        return false;
                        }
                        return true;
                }
        }
        <commit_msg>Optimized<commit_after>#include "complex_range_selector.h"

namespace dream_hacking {

        ComplexRangeSelector::ComplexRangeSelector() {
        }

        ComplexRangeSelector::~ComplexRangeSelector() {
        }

        bool ComplexRangeSelector::Test(const std::vector<PlayingCard>& deck) const{
                if (selectors.empty()){
                        return true;
                } else {
                        size_t len = deck.size();
                        size_t selectorsCnt = selectors.size();
                        for (size_t i = 0; i < selectorsCnt; ++i){
                                const PRangeSelector & selector = selectors[i];
                                bool satisfied = false;
                                for (size_t j = selector->from; j <= std::min(selector->to, len - 1); ++j){
                                        const PlayingCard& card = deck[j];
                                        auto res = selector->CheckCard(card);
                                        if (res == RangeSelector::Error)
                                                return false;
                                        else if (res == RangeSelector::Ok){
                                                satisfied = true;
                                                break;
                                        }
                                }
                                if (!satisfied && !selector->DefaultReturn())
                                        return false;
                        }
                        
                        return true;
                }
        }
        
{'fraction_non_alphanumeric': 0.07645415290830582, 'fraction_numerical': 0.000508001016002032, 'mean_word_length': 0.6974137931034483, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 49, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '15317', 'n_tokens_mistral': 705, 'n_tokens_neox': 661, 'n_words': 161}