Skip to main content
edited body
Source Link
struct State {
    State * partent; // parent is not hashed    
    std::pair<int8_t, int8_t> data;
    std::array<std::pair<int8_t, int8_t>, N> more_data;
};

bool Temp::is_equal(const State & state) const {
    if (!value) return false;
    if (value->data>more_data != state.datamore_data) return false;
    if (value->more_data>data == state.more_datadata) return true;


    // this last line where I use the additional information 
    // field is a 2D array it can be generetad from State and is_reachable function compere the cell value with a const value 
    // (field[data.first][data.second]) >= X);
    return field->is_reachable(state.data);
}
struct State {
    State * partent; // parent is not hashed    
    std::pair<int8_t, int8_t> data;
    std::array<std::pair<int8_t, int8_t>, N> more_data;
};

bool Temp::is_equal(const State & state) const {
    if (!value) return false;
    if (value->data != state.data) return false;
    if (value->more_data == state.more_data) return true;


    // this last line where I use the additional information 
    // field is a 2D array it can be generetad from State and is_reachable function compere the cell value with a const value 
    // (field[data.first][data.second]) >= X);
    return field->is_reachable(state.data);
}
struct State {
    State * partent; // parent is not hashed    
    std::pair<int8_t, int8_t> data;
    std::array<std::pair<int8_t, int8_t>, N> more_data;
};

bool Temp::is_equal(const State & state) const {
    if (!value) return false;
    if (value->more_data != state.more_data) return false;
    if (value->data == state.data) return true;


    // this last line where I use the additional information 
    // field is a 2D array it can be generetad from State and is_reachable function compere the cell value with a const value 
    // (field[data.first][data.second]) >= X);
    return field->is_reachable(state.data);
}
deleted 51 characters in body
Source Link

Edit:

I might skipped some important details:

struct Temp hold additional information which makes it a bit slower to create than the simplified version, this information is used in temp.is_equal() function so it slows down the comperation between Temps as well.

struct State {
    State * partent; // parent is not hashed    
    std::pair<int8_t, int8_t> data;
    std::array<std::pair<int8_t, int8_t>, N> more_data;
};

bool Temp::is_equal(const State & state) const {
    if (!value) return false;
    if (value->data != state.data) return false;
    if (value->more_data == state.more_data) return true;


    // this last line where I use the additional information 
    // field is a 2D array it can be generetad from State and is_reachable function compere the cell value with a const value 
    // (field[data.first][data.second]) >= X);
    return field->is_reachable(state.data);
}

Edit:

I might skipped some important details:

struct Temp hold additional information which makes it a bit slower to create than the simplified version, this information is used in temp.is_equal() function so it slows down the comperation between Temps as well.

struct State {
    State * partent; // parent is not hashed    
    std::pair<int8_t, int8_t> data;
    std::array<std::pair<int8_t, int8_t>, N> more_data;
};

bool Temp::is_equal(const State & state) const {
    if (!value) return false;
    if (value->data != state.data) return false;
    if (value->more_data == state.more_data) return true;


    // this last line where I use the additional information 
    // field is a 2D array it can be generetad from State and is_reachable function compere the cell value with a const value 
    // (field[data.first][data.second]) >= X);
    return field->is_reachable(state.data);
}
deleted 51 characters in body
Source Link
void m_finalize_cycle(std::multimap<std::size_t, Temp> & multimap) {
    auto head = m_queue.consume_all();
    auto node = head.ptr;
    while (node != nullptr) {
        if (!node->data.value == false) { node = node->next;  continue; }
        auto & temp = node->data;
        const auto range = multimap.equal_range(temp.hash);
        if (range.first == range.second) {
            multimap.emplace(std::make_pair(temp.hash, temp.move()));
        } else {
            const auto it = std::find_if(range.first, range.second, [&temp](const auto & pair) {
                return temp.is_equal(pair.second.value.get());
            });
            if (it == range.second) {
                multimap.emplace_hint(range.first, std::make_pair(temp.hash, temp.move()));
            } else if (temp.deepness < it->second.deepness) {
                it->second.value.reset(temp.value.release());
                it->second.deepness = temp.deepness;
            }
        }
        node = node->next;
    }
}
void m_finalize_cycle(std::multimap<std::size_t, Temp> & multimap) {
    auto head = m_queue.consume_all();
    auto node = head.ptr;
    while (node != nullptr) {
        if (node->data.value == false) { node = node->next;  continue; }
        auto & temp = node->data;
        const auto range = multimap.equal_range(temp.hash);
        if (range.first == range.second) {
            multimap.emplace(std::make_pair(temp.hash, temp.move()));
        } else {
            const auto it = std::find_if(range.first, range.second, [&temp](const auto & pair) {
                return temp.is_equal(pair.second.value.get());
            });
            if (it == range.second) {
                multimap.emplace_hint(range.first, std::make_pair(temp.hash, temp.move()));
            } else if (temp.deepness < it->second.deepness) {
                it->second.value.reset(temp.value.release());
                it->second.deepness = temp.deepness;
            }
        }
        node = node->next;
    }
}
void m_finalize_cycle(std::multimap<std::size_t, Temp> & multimap) {
    auto head = m_queue.consume_all();
    auto node = head.ptr;
    while (node) {
        if (!node->data.value) { node = node->next;  continue; }
        auto & temp = node->data;
        const auto range = multimap.equal_range(temp.hash);
        if (range.first == range.second) {
            multimap.emplace(temp.hash, temp.move());
        } else {
            const auto it = std::find_if(range.first, range.second, [&temp](const auto & pair) {
                return temp.is_equal(pair.second.value.get());
            });
            if (it == range.second) {
                multimap.emplace_hint(range.first, temp.hash, temp.move());
            } else if (temp.deepness < it->second.deepness) {
                it->second.value.reset(temp.value.release());
                it->second.deepness = temp.deepness;
            }
        }
        node = node->next;
    }
}
added 2 characters in body
Source Link
Loading
Source Link
Loading