Move the free_list management into a separate class for reuse.

* src/misc/freelist.hh, src/misc/freelist.cc: New files.
* src/misc/Makefile.am (misc_HEADERS, libmisc_la_SOURCES): Add them.
* src/misc/bddalloc.hh (bdd_allocator): Inherit from free_list and
make dump_free_list visible.
* src/misc/bddalloc.cc (bdd_allocator::allocate_variables): Move
all the code into free_list::register_n() and
bdd_allocator::extend(), and call the former.
(bdd_allocator::release_variables): Move all the code into
free_list::release_n() and call it.
(bdd_allocator::extend): New method.
* src/tgba/bdddict.cc (bdd_dict::dump): Call dump_free_list;
This commit is contained in:
Alexandre Duret-Lutz 2004-03-18 15:43:10 +00:00
parent b84e6a6440
commit cf6602a3be
7 changed files with 228 additions and 86 deletions

View file

@ -1,4 +1,4 @@
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
@ -32,7 +32,7 @@ namespace spot
: lvarnum(varnum)
{
initialize();
free_list.push_front(pos_lenght_pair(0, lvarnum));
fl.push_front(pos_lenght_pair(0, lvarnum));
}
void
@ -71,52 +71,27 @@ namespace spot
int
bdd_allocator::allocate_variables(int n)
{
// Browse the free list until we find N consecutive variables. We
// try not to fragment the list my allocating the variables in the
// smallest free range we find.
free_list_type::iterator best = free_list.end();
free_list_type::iterator cur;
for (cur = free_list.begin(); cur != free_list.end(); ++cur)
{
if (cur->second < n)
continue;
if (n == cur->second)
{
best = cur;
break;
}
if (best == free_list.end()
|| cur->second < best->second)
best = cur;
}
return register_n(n);
}
// We have found enough free variables.
if (best != free_list.end())
{
int result = best->first;
best->second -= n;
assert(best->second >= 0);
// Erase the range if it's now empty.
if (best->second == 0)
free_list.erase(best);
else
best->first += n;
return result;
}
// We haven't found enough adjacent free variables;
// ask BuDDy for some more.
void
bdd_allocator::release_variables(int base, int n)
{
release_n(base, n);
}
int
bdd_allocator::extend(int n)
{
// If we already have some free variable at the end
// of the variable space, allocate just the difference.
if (free_list.size() > 0
&& free_list.back().first + free_list.back().second == lvarnum)
if (fl.size() > 0 && fl.back().first + fl.back().second == lvarnum)
{
int res = free_list.back().first;
int endvar = free_list.back().second;
int res = fl.back().first;
int endvar = fl.back().second;
assert(n > endvar);
extvarnum(n - endvar);
free_list.pop_back();
fl.pop_back();
return res;
}
else
@ -127,40 +102,4 @@ namespace spot
return res;
}
}
void
bdd_allocator::release_variables(int base, int n)
{
free_list_type::iterator cur;
int end = base + n;
for (cur = free_list.begin(); cur != free_list.end(); ++cur)
{
// Append to a range ...
if (cur->first + cur->second == base)
{
cur->second += n;
// Maybe the next item on the list can be merged.
free_list_type::iterator next = cur;
++next;
if (next != free_list.end()
&& next->first == end)
{
cur->second += next->second;
free_list.erase(next);
}
return;
}
// ... or prepend to a range ...
if (cur->first == end)
{
cur->first -= n;
cur->second += n;
return;
}
// ... or insert a new range.
if (cur->first > end)
break;
}
free_list.insert(cur, pos_lenght_pair(base, n));
}
}