[traverse] use same method for finding index; this fixes

the last uu case in union_multi (and is better anyways)
This commit is contained in:
Barend Gehrels
2016-02-27 18:16:19 +01:00
parent 83320f528e
commit 577c3bcfe4
2 changed files with 4 additions and 72 deletions

View File

@@ -237,64 +237,6 @@ struct side_sorter
}
}
// Returns first index which is outgoing, and all incoming arcs are balanced
// by outgoing arcs
std::size_t first_open_index()
{
// map source index to state
typedef std::map<int, int> map_type;
map_type state;
bool free = false;
std::size_t result = m_ranked_points.size();
std::size_t last_main_rank = 0;
for (std::size_t i = 0; i < m_ranked_points.size(); i++)
{
const rp& ranked = m_ranked_points[i];
if (free && ranked.main_rank > last_main_rank)
{
return result;
}
free = false;
if (ranked.index == index_from)
{
state[ranked.seg_id.source_index]++;
}
else
{
state[ranked.seg_id.source_index]--;
}
if (ranked.index == index_to)
{
int sum = 0;
for (map_type::const_iterator it = state.begin();
it != state.end(); ++it)
{
sum += it->second;
}
if (sum == 0)
{
// It is open. If next is a new main rank,
// then this is the result
free = true;
result = i;
last_main_rank = ranked.main_rank;
}
}
}
if (free)
{
return result;
}
return m_ranked_points.size();
}
template <signed_size_type segment_identifier::*Member, typename Map>
void find_open_generic(Map& handled)
{

View File

@@ -257,7 +257,7 @@ struct traversal
inline bool select_from_cluster(signed_size_type& turn_index,
int& op_index, signed_size_type start_turn_index,
sbs_type const& sbs)
sbs_type const& sbs, bool allow_pass_rank)
{
bool const is_union = OperationType == operation_union;
bool const is_intersection = OperationType == operation_intersection;
@@ -314,7 +314,7 @@ struct traversal
result = true;
selected_rank = ranked_point.main_rank;
}
else
else if (! allow_pass_rank)
{
return result;
}
@@ -396,20 +396,10 @@ struct traversal
if (open_count > 1)
{
sbs.reverse();
std::size_t index = sbs.first_open_index();
if (index < sbs.m_ranked_points.size())
{
typename sbs_type::rp const& ranked_point = sbs.m_ranked_points[index];
turn_index = ranked_point.turn_index;
op_index = ranked_point.op_index;
return true;
}
return false;
return select_from_cluster(turn_index, op_index, start_turn_index, sbs, true);
}
return select_from_cluster(turn_index, op_index, start_turn_index, sbs);
return select_from_cluster(turn_index, op_index, start_turn_index, sbs, false);
}
inline void change_index_for_self_turn(signed_size_type& to_vertex_index,