* src/misc/freelist.hh (free_list::remove, free_list::insert): New
methods. * src/misc/freelist.cc (free_list::register_n, free_list::releases_n): Rewrite using free_list::remove and free_list::insert. (free_list::remove, free_list::insert): New methods. * src/tgba/bdddict.hh (bdd_dict::register_anonymous_variables): New method. (bdd_dict::annon_free_list): New subclass. (bdd_dict::free_annonymous_list_of_type_of): New attribute. * src/tgba/bdddict.cc (bdd_dict::register_all_variables_of, bdd_dict::unregister_all_my_variables): Handle anonymous variables too. (bdd_dict::register_anonymous_variables, bdd_dict::annon_free_list::annon_free_list, bdd_dict::annon_free_list::extend): New methods.
This commit is contained in:
parent
aba2dc75d7
commit
784ccafb1b
5 changed files with 213 additions and 33 deletions
|
|
@ -56,13 +56,7 @@ namespace spot
|
|||
if (best != fl.end())
|
||||
{
|
||||
int result = best->first;
|
||||
best->second -= n;
|
||||
assert(best->second >= 0);
|
||||
// Erase the range if it's now empty.
|
||||
if (best->second == 0)
|
||||
fl.erase(best);
|
||||
else
|
||||
best->first += n;
|
||||
remove(best, result, n);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -72,40 +66,119 @@ namespace spot
|
|||
}
|
||||
|
||||
void
|
||||
free_list::release_n(int base, int n)
|
||||
free_list::insert(int base, int n)
|
||||
{
|
||||
free_list_type::iterator cur;
|
||||
int end = base + n;
|
||||
for (cur = fl.begin(); cur != fl.end(); ++cur)
|
||||
{
|
||||
// Append to a range ...
|
||||
if (cur->first + cur->second == base)
|
||||
int cend = cur->first + cur->second;
|
||||
// cur [....[ [......[
|
||||
// to insert [....[ [..[
|
||||
// ----------------------------------
|
||||
// result [......[ [......[
|
||||
if (cend >= base)
|
||||
{
|
||||
cur->second += n;
|
||||
// Maybe the next item on the list can be merged.
|
||||
free_list_type::iterator next = cur;
|
||||
++next;
|
||||
if (next != fl.end() && next->first == end)
|
||||
{
|
||||
cur->second += next->second;
|
||||
fl.erase(next);
|
||||
}
|
||||
return;
|
||||
if (cend >= end)
|
||||
return;
|
||||
// cur->second is set below.
|
||||
}
|
||||
// ... or prepend to a range ...
|
||||
if (cur->first == end)
|
||||
// cur [....[ [..[
|
||||
// to insert [....[ [.......[
|
||||
// ----------------------------------
|
||||
// result [......[ [.......[
|
||||
else if (cend >= base && cur->first <= end)
|
||||
{
|
||||
cur->first -= n;
|
||||
cur->second += n;
|
||||
return;
|
||||
cur->first = base;
|
||||
if (cend >= end)
|
||||
return;
|
||||
// cur->second is set below.
|
||||
}
|
||||
// ... or insert a new range.
|
||||
if (cur->first > end)
|
||||
else if (cur->first > end)
|
||||
// Insert a new range, unconnected.
|
||||
break;
|
||||
else
|
||||
continue;
|
||||
|
||||
// We get here in one of these two situations:
|
||||
//
|
||||
// cur [....[ [..[
|
||||
// to insert [....[ [.......[
|
||||
// ----------------------------------
|
||||
// result [......[ [.......[
|
||||
//
|
||||
// cur->first is already set, be cur->second has yet to be.
|
||||
cur->second = end - cur->first;
|
||||
// Since we have extended the current range, maybe the next
|
||||
// items on the list should be merged.
|
||||
free_list_type::iterator next = cur;
|
||||
++next;
|
||||
while (next != fl.end() && next->first <= end)
|
||||
{
|
||||
cur->second =
|
||||
std::max(next->first + next->second, end) - cur->first;
|
||||
free_list_type::iterator next2 = next++;
|
||||
fl.erase(next2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// We reach this place either because a new unconnected range
|
||||
// should be inserted in the middle of FL, or at the end.
|
||||
fl.insert(cur, pos_lenght_pair(base, n));
|
||||
}
|
||||
|
||||
void
|
||||
free_list::remove(int base, int n)
|
||||
{
|
||||
free_list_type::iterator cur;
|
||||
int end = base + n;
|
||||
for (cur = fl.begin(); cur != fl.end() && cur->first <= end; ++cur)
|
||||
{
|
||||
int cend = cur->first + cur->second;
|
||||
if (cend >= end)
|
||||
remove(cur, base, std::max(n, cend - base));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
free_list::remove(free_list_type::iterator i, int base, int n)
|
||||
{
|
||||
if (base == i->first)
|
||||
{
|
||||
i->second -= n;
|
||||
assert(i->second >= 0);
|
||||
// Erase the range if it's now empty.
|
||||
if (i->second == 0)
|
||||
fl.erase(i);
|
||||
else
|
||||
i->first += n;
|
||||
}
|
||||
else if (base + n == i->first + i->second)
|
||||
{
|
||||
i->second -= n;
|
||||
assert(i->second > 0); // cannot be empty because base != i->first
|
||||
}
|
||||
else
|
||||
{
|
||||
// Removing in the middle of a range.
|
||||
int b1 = i->first;
|
||||
int n1 = base - i->first;
|
||||
int n2 = i->second - n - base;
|
||||
assert(n1 > 0);
|
||||
assert(n2 > 0);
|
||||
*i = pos_lenght_pair(base + n, n2);
|
||||
fl.insert(i, pos_lenght_pair(b1, n1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
free_list::release_n(int base, int n)
|
||||
{
|
||||
insert(base, n);
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
free_list::dump_free_list(std::ostream& os) const
|
||||
{
|
||||
|
|
@ -115,4 +188,5 @@ namespace spot
|
|||
return os;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,13 @@ namespace spot
|
|||
|
||||
/// Dump the list to \a os for debugging.
|
||||
std::ostream& dump_free_list(std::ostream& os) const;
|
||||
|
||||
/// Extend the list by inserting a new pos-lenght pair.
|
||||
void insert(int base, int n);
|
||||
|
||||
/// Remove \a n consecutive entries from the list, starting at \a base.
|
||||
void remove(int base, int n = 0);
|
||||
|
||||
protected:
|
||||
|
||||
/// Allocate \a n integer.
|
||||
|
|
@ -62,6 +69,9 @@ namespace spot
|
|||
typedef std::pair<int, int> pos_lenght_pair;
|
||||
typedef std::list<pos_lenght_pair> free_list_type;
|
||||
free_list_type fl; ///< Tracks unused BDD variables.
|
||||
|
||||
/// Remove \a n consecutive entries from the list, starting at \a base.
|
||||
void remove(free_list_type::iterator i, int base, int n);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue