[PPL-devel] [GIT] ppl/ppl(master): Put under git control.
Enea Zaffanella
zaffanella at cs.unipr.it
Fri Apr 23 00:52:04 CEST 2010
Module: ppl/ppl
Branch: master
Commit: b75b69c4ea3e6f5bd1fb293f5eb89ba855252415
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=b75b69c4ea3e6f5bd1fb293f5eb89ba855252415
Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date: Fri Apr 23 00:51:39 2010 +0200
Put under git control.
---
src/Partial_Function.cc | 41 ++++++++++++++++++
src/Partial_Function.defs.hh | 86 +++++++++++++++++++++++++++++++++++++
src/Partial_Function.inlines.hh | 89 +++++++++++++++++++++++++++++++++++++++
src/Partial_Function.types.hh | 21 +++++++++
4 files changed, 237 insertions(+), 0 deletions(-)
diff --git a/src/Partial_Function.cc b/src/Partial_Function.cc
new file mode 100644
index 0000000..c38a89d
--- /dev/null
+++ b/src/Partial_Function.cc
@@ -0,0 +1,41 @@
+/* Implementation of class Partial_Function (non-inline functions).
+ Copyright (C) 2001-2010 Roberto Bagnara <bagnara at cs.unipr.it>
+
+This file is part of the Parma Polyhedra Library (PPL).
+
+The PPL 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 3 of the License, or (at your
+option) any later version.
+
+The PPL 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 this program; if not, write to the Free Software Foundation,
+Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
+
+For the most up-to-date information see the Parma Polyhedra Library
+site: http://www.cs.unipr.it/ppl/ . */
+
+#include <ppl-config.h>
+#include "Partial_Function.defs.hh"
+#include "Variable.defs.hh"
+#include <iostream>
+
+namespace Parma_Polyhedra_Library {
+
+void
+Partial_Function::print(std::ostream& s) const {
+ using namespace Parma_Polyhedra_Library::IO_Operators;
+ if (has_empty_codomain())
+ s << "empty" << std::endl;
+ else
+ for (dimension_type i = 0, i_end = vec.size(); i < i_end; ++i)
+ if (vec[i] != not_a_dimension())
+ s << Variable(i) << " --> " << Variable(vec[i]) << "\n";
+}
+
+} // namespace Parma_Polyhedra_Library
diff --git a/src/Partial_Function.defs.hh b/src/Partial_Function.defs.hh
new file mode 100644
index 0000000..a500902
--- /dev/null
+++ b/src/Partial_Function.defs.hh
@@ -0,0 +1,86 @@
+/* Partial_Function class declaration.
+ Copyright (C) 2001-2010 Roberto Bagnara <bagnara at cs.unipr.it>
+
+This file is part of the Parma Polyhedra Library (PPL).
+
+The PPL 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 3 of the License, or (at your
+option) any later version.
+
+The PPL 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 this program; if not, write to the Free Software Foundation,
+Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
+
+For the most up-to-date information see the Parma Polyhedra Library
+site: http://www.cs.unipr.it/ppl/ . */
+
+#ifndef PPL_Partial_Function_defs_hh
+#define PPL_Partial_Function_defs_hh 1
+
+#include "Partial_Function.types.hh"
+#include "globals.defs.hh"
+#include <vector>
+#ifndef NDEBUG
+#include <set>
+#endif
+#include <iosfwd>
+
+namespace Parma_Polyhedra_Library {
+
+class Partial_Function {
+public:
+ /*! \brief
+ Default constructor: builds a function with empty codomain
+ (i.e., always undefined).
+ */
+ Partial_Function();
+
+ /*! \brief
+ Returns \c true if and only if the represented partial function
+ has an empty codomain (i.e., it is always undefined).
+ */
+ bool has_empty_codomain() const;
+
+ /*! \brief
+ If the codomain is \e not empty, returns the maximum value in it.
+
+ \exception std::runtime_error
+ Thrown if called when \p *this has an empty codomain.
+ */
+ dimension_type max_in_codomain() const;
+
+ /*! \brief
+ If \p *this maps \p i to a value \c k, assigns \c k to \p j and
+ returns \c true; otherwise, \p j is unchanged and \c false is returned.
+ */
+ bool maps(dimension_type i, dimension_type& j) const;
+
+ void print(std::ostream& s) const;
+
+ /*! \brief
+ Modifies \p *this so that \p i is mapped to \p j.
+
+ \exception std::runtime_error
+ Thrown if \p *this is already mapping \p j.
+ */
+ void insert(dimension_type i, dimension_type j);
+
+private:
+ std::vector<dimension_type> vec;
+ dimension_type max;
+#ifndef NDEBUG
+ std::set<dimension_type> codomain;
+#endif
+}; // class Partial_Function
+
+} // namespace Parma_Polyhedra_Library
+
+#include "Partial_Function.inlines.hh"
+
+#endif // !defined(PPL_Partial_Function_defs_hh)
diff --git a/src/Partial_Function.inlines.hh b/src/Partial_Function.inlines.hh
new file mode 100644
index 0000000..bffc8ad
--- /dev/null
+++ b/src/Partial_Function.inlines.hh
@@ -0,0 +1,89 @@
+/* Partial_Function class implementation: inline functions.
+ Copyright (C) 2001-2010 Roberto Bagnara <bagnara at cs.unipr.it>
+
+This file is part of the Parma Polyhedra Library (PPL).
+
+The PPL 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 3 of the License, or (at your
+option) any later version.
+
+The PPL 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 this program; if not, write to the Free Software Foundation,
+Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
+
+For the most up-to-date information see the Parma Polyhedra Library
+site: http://www.cs.unipr.it/ppl/ . */
+
+#ifndef PPL_Partial_Function_inlines_hh
+#define PPL_Partial_Function_inlines_hh 1
+
+#include <stdexcept>
+#include <cassert>
+
+namespace Parma_Polyhedra_Library {
+
+inline
+Partial_Function::Partial_Function()
+ : max(0) {
+}
+
+inline bool
+Partial_Function::has_empty_codomain() const {
+ PPL_ASSERT(vec.empty() == codomain.empty());
+ return vec.empty();
+}
+
+inline dimension_type
+Partial_Function::max_in_codomain() const {
+ if (has_empty_codomain())
+ throw std::runtime_error("Partial_Function::max_in_codomain() called"
+ " when has_empty_codomain()");
+ PPL_ASSERT(codomain.begin() != codomain.end()
+ && max == *codomain.rbegin());
+ return max;
+}
+
+inline void
+Partial_Function::insert(dimension_type i, dimension_type j) {
+#ifndef NDEBUG
+ // The partial function has to be an injective map.
+ std::pair<std::set<dimension_type>::iterator, bool> s = codomain.insert(j);
+ PPL_ASSERT(s.second);
+#endif // #ifndef NDEBUG
+
+ // Expand `vec' if needed.
+ const dimension_type sz = vec.size();
+ if (i >= sz)
+ vec.insert(vec.end(), i - sz + 1, not_a_dimension());
+
+ // We cannot remap the same index to another one.
+ PPL_ASSERT(i < vec.size() && vec[i] == not_a_dimension());
+ vec[i] = j;
+
+ // Maybe update `max'.
+ if (j > max)
+ max = j;
+ PPL_ASSERT(codomain.begin() != codomain.end()
+ && max == *codomain.rbegin());
+}
+
+inline bool
+Partial_Function::maps(dimension_type i, dimension_type& j) const {
+ if (i >= vec.size())
+ return false;
+ dimension_type vec_i = vec[i];
+ if (vec_i == not_a_dimension())
+ return false;
+ j = vec_i;
+ return true;
+}
+
+} // namespace Parma_Polyhedra_Library
+
+#endif // !defined(PPL_Partial_Function_inlines_hh)
diff --git a/src/Partial_Function.types.hh b/src/Partial_Function.types.hh
new file mode 100644
index 0000000..8146ca2
--- /dev/null
+++ b/src/Partial_Function.types.hh
@@ -0,0 +1,21 @@
+/* Copyright (C) 2001-2010 Roberto Bagnara <bagnara at cs.unipr.it>
+
+This file is free software; as a special exception the author gives
+unlimited permission to copy and/or distribute it, with or without
+modifications, as long as this notice is preserved.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+PURPOSE. */
+
+#ifndef PPL_Partial_Function_types_hh
+#define PPL_Partial_Function_types_hh 1
+
+namespace Parma_Polyhedra_Library {
+
+class Partial_Function;
+
+} // namespace Parma_Polyhedra_Library
+
+#endif // !defined(PPL_Partial_Function_types_hh)
More information about the PPL-devel
mailing list