Small speedup in safra_tree::compare().
* src/tgba/tgbasafracomplement.cc (safra_tree::compare): Improve the order of the tests.
This commit is contained in:
parent
a9669d3d17
commit
15c2a9473e
2 changed files with 32 additions and 30 deletions
|
|
@ -1,3 +1,10 @@
|
||||||
|
2012-01-18 Alexandre Duret-Lutz <adl@lrde.epita.fr>
|
||||||
|
|
||||||
|
Small speedup in safra_tree::compare().
|
||||||
|
|
||||||
|
* src/tgba/tgbasafracomplement.cc (safra_tree::compare): Improve
|
||||||
|
the order of the tests.
|
||||||
|
|
||||||
2012-01-18 Alexandre Duret-Lutz <adl@lrde.epita.fr>
|
2012-01-18 Alexandre Duret-Lutz <adl@lrde.epita.fr>
|
||||||
|
|
||||||
* NEWS: Mention the last two changes.
|
* NEWS: Mention the last two changes.
|
||||||
|
|
|
||||||
|
|
@ -197,40 +197,35 @@ namespace spot
|
||||||
/// a signed value.
|
/// a signed value.
|
||||||
int safra_tree::compare(const safra_tree* other) const
|
int safra_tree::compare(const safra_tree* other) const
|
||||||
{
|
{
|
||||||
int subset_compare = 0;
|
int res = name - other->name;
|
||||||
subset_t::const_iterator in1 = nodes.begin();
|
if (res != 0)
|
||||||
subset_t::const_iterator in2 = other->nodes.begin();
|
return res;
|
||||||
|
|
||||||
if (nodes.size() != other->nodes.size())
|
|
||||||
return (nodes.size() - other->nodes.size());
|
|
||||||
|
|
||||||
if (name != other->name)
|
|
||||||
return name - other->name;
|
|
||||||
|
|
||||||
for (; in1 != nodes.end() && in2 != other->nodes.end(); ++in1, ++in2)
|
|
||||||
if ((subset_compare = (*in1)->compare(*in2)) != 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (subset_compare != 0)
|
|
||||||
return subset_compare;
|
|
||||||
|
|
||||||
child_list::const_iterator ic1 = children.begin();
|
|
||||||
child_list::const_iterator ic2 = other->children.begin();
|
|
||||||
|
|
||||||
if (children.size() != other->children.size())
|
|
||||||
return (children.size() - other->children.size());
|
|
||||||
|
|
||||||
for (; ic1 != children.end() && ic2 != other->children.end();
|
|
||||||
++ic1, ++ic2)
|
|
||||||
{
|
|
||||||
int compare_value = (*ic1)->compare(*ic2);
|
|
||||||
if (compare_value != 0)
|
|
||||||
return compare_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (marked != other->marked)
|
if (marked != other->marked)
|
||||||
return (marked) ? -1 : 1;
|
return (marked) ? -1 : 1;
|
||||||
|
|
||||||
|
res = nodes.size() - other->nodes.size();
|
||||||
|
if (res != 0)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
res = children.size() - other->children.size();
|
||||||
|
if (res != 0)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
// Call compare() only as a last resort, because it takes time.
|
||||||
|
|
||||||
|
subset_t::const_iterator in1 = nodes.begin();
|
||||||
|
subset_t::const_iterator in2 = other->nodes.begin();
|
||||||
|
for (; in1 != nodes.end(); ++in1, ++in2)
|
||||||
|
if ((res = (*in1)->compare(*in2)) != 0)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
child_list::const_iterator ic1 = children.begin();
|
||||||
|
child_list::const_iterator ic2 = other->children.begin();
|
||||||
|
for (; ic1 != children.end(); ++ic1, ++ic2)
|
||||||
|
if ((res = (*ic1)->compare(*ic2)) != 0)
|
||||||
|
return res;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue