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

69
src/misc/freelist.hh Normal file
View file

@ -0,0 +1,69 @@
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#ifndef SPOT_MISC_FREELIST_HH
# define SPOT_MISC_FREELIST_HH
#include <list>
#include <utility>
namespace spot
{
/// Manage list of free integers.
class free_list
{
public:
virtual ~free_list();
/// \brief Find \a n consecutive integers.
///
/// Browse the list of free integers until \a n consecutive
/// integers are found. Extend the list (using extend()) otherwise.
/// \return the first integer of the range
int register_n(int n);
/// Release \a n consecutive integers starting at \a base.
void release_n(int base, int n);
/// Dump the list to \a os for debugging.
std::ostream& dump_free_list(std::ostream& os) const;
protected:
/// Allocate \a n integer.
///
/// This function is called by register_n() when the free list is
/// empty or if \a n consecutive integers could not be found. It
/// should allocate more integers, possibly changing the list, and
/// return the first integer on a range of n consecutive integer
/// requested by the user.
virtual int extend(int n) = 0;
/// Such pairs describe \c second free integer starting at \first.
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.
};
}
#endif // SPOT_MISC_FREELIST_HH