PPL  1.2
Parma_Polyhedra_Library::Partial_Function Class Reference

#include <Partial_Function_defs.hh>

Public Member Functions

 Partial_Function ()
 Default constructor: builds a function with empty codomain (i.e., always undefined). More...
 
bool has_empty_codomain () const
 Returns true if and only if the represented partial function has an empty codomain (i.e., it is always undefined). More...
 
dimension_type max_in_codomain () const
 If the codomain is not empty, returns the maximum value in it. More...
 
bool maps (dimension_type i, dimension_type &j) const
 If *this maps i to a value k, assigns k to j and returns true; otherwise, j is unchanged and false is returned. More...
 
void print (std::ostream &s) const
 
void insert (dimension_type i, dimension_type j)
 Modifies *this so that i is mapped to j. More...
 

Private Attributes

std::vector< dimension_typevec
 
dimension_type max
 
std::set< dimension_typecodomain
 

Detailed Description

Definition at line 37 of file Partial_Function_defs.hh.

Constructor & Destructor Documentation

Parma_Polyhedra_Library::Partial_Function::Partial_Function ( )
inline

Default constructor: builds a function with empty codomain (i.e., always undefined).

Definition at line 33 of file Partial_Function_inlines.hh.

34  : max(0) {
35 }

Member Function Documentation

bool Parma_Polyhedra_Library::Partial_Function::has_empty_codomain ( ) const
inline

Returns true if and only if the represented partial function has an empty codomain (i.e., it is always undefined).

Definition at line 38 of file Partial_Function_inlines.hh.

References codomain, and vec.

Referenced by Parma_Polyhedra_Library::Box< ITV >::map_space_dimensions(), Parma_Polyhedra_Library::Octagonal_Shape< T >::map_space_dimensions(), Parma_Polyhedra_Library::BD_Shape< T >::map_space_dimensions(), Parma_Polyhedra_Library::Grid::map_space_dimensions(), Parma_Polyhedra_Library::Polyhedron::map_space_dimensions(), max_in_codomain(), and print().

38  {
39  PPL_ASSERT(vec.empty() == codomain.empty());
40  return vec.empty();
41 }
void Parma_Polyhedra_Library::Partial_Function::insert ( dimension_type  i,
dimension_type  j 
)
inline

Modifies *this so that i is mapped to j.

Exceptions
std::runtime_errorThrown if *this is already mapping j.

Definition at line 55 of file Partial_Function_inlines.hh.

References codomain, max, Parma_Polyhedra_Library::not_a_dimension(), and vec.

55  {
56 #ifndef NDEBUG
57  // The partial function has to be an injective map.
58  std::pair<std::set<dimension_type>::iterator, bool> s = codomain.insert(j);
59  PPL_ASSERT(s.second);
60 #endif // #ifndef NDEBUG
61 
62  // Expand `vec' if needed.
63  const dimension_type sz = vec.size();
64  if (i >= sz) {
65  vec.insert(vec.end(), i - sz + 1, not_a_dimension());
66  }
67 
68  // We cannot remap the same index to another one.
69  PPL_ASSERT(i < vec.size() && vec[i] == not_a_dimension());
70  vec[i] = j;
71 
72  // Maybe update `max'.
73  if (j > max) {
74  max = j;
75  }
76  PPL_ASSERT(codomain.begin() != codomain.end()
77  && max == *codomain.rbegin());
78 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type not_a_dimension()
Returns a value that does not designate a valid dimension.
bool Parma_Polyhedra_Library::Partial_Function::maps ( dimension_type  i,
dimension_type j 
) const
inline

If *this maps i to a value k, assigns k to j and returns true; otherwise, j is unchanged and false is returned.

Definition at line 81 of file Partial_Function_inlines.hh.

References Parma_Polyhedra_Library::not_a_dimension(), and vec.

Referenced by Parma_Polyhedra_Library::Pointset_Ask_Tell< PSET >::map_space_dimensions(), Parma_Polyhedra_Library::Pointset_Powerset< PSET >::map_space_dimensions(), Parma_Polyhedra_Library::Box< ITV >::map_space_dimensions(), Parma_Polyhedra_Library::Octagonal_Shape< T >::map_space_dimensions(), Parma_Polyhedra_Library::BD_Shape< T >::map_space_dimensions(), Parma_Polyhedra_Library::Grid::map_space_dimensions(), and Parma_Polyhedra_Library::Polyhedron::map_space_dimensions().

81  {
82  if (i >= vec.size()) {
83  return false;
84  }
85  const dimension_type vec_i = vec[i];
86  if (vec_i == not_a_dimension()) {
87  return false;
88  }
89  j = vec_i;
90  return true;
91 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type not_a_dimension()
Returns a value that does not designate a valid dimension.
dimension_type Parma_Polyhedra_Library::Partial_Function::max_in_codomain ( ) const
inline

If the codomain is not empty, returns the maximum value in it.

Exceptions
std::runtime_errorThrown if called when *this has an empty codomain.

Definition at line 44 of file Partial_Function_inlines.hh.

References codomain, has_empty_codomain(), and max.

Referenced by Parma_Polyhedra_Library::Box< ITV >::map_space_dimensions(), Parma_Polyhedra_Library::Octagonal_Shape< T >::map_space_dimensions(), Parma_Polyhedra_Library::BD_Shape< T >::map_space_dimensions(), Parma_Polyhedra_Library::Grid::map_space_dimensions(), and Parma_Polyhedra_Library::Polyhedron::map_space_dimensions().

44  {
45  if (has_empty_codomain()) {
46  throw std::runtime_error("Partial_Function::max_in_codomain() called"
47  " when has_empty_codomain()");
48  }
49  PPL_ASSERT(codomain.begin() != codomain.end()
50  && max == *codomain.rbegin());
51  return max;
52 }
bool has_empty_codomain() const
Returns true if and only if the represented partial function has an empty codomain (i...
void Parma_Polyhedra_Library::Partial_Function::print ( std::ostream &  s) const

Definition at line 32 of file Partial_Function.cc.

References has_empty_codomain(), Parma_Polyhedra_Library::not_a_dimension(), and vec.

32  {
34  if (has_empty_codomain()) {
35  s << "empty" << std::endl;
36  }
37  else {
38  for (dimension_type i = 0, i_end = vec.size(); i < i_end; ++i) {
39  if (vec[i] != not_a_dimension()) {
40  s << Variable(i) << " --> " << Variable(vec[i]) << "\n";
41  }
42  }
43  }
44 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type not_a_dimension()
Returns a value that does not designate a valid dimension.
bool has_empty_codomain() const
Returns true if and only if the represented partial function has an empty codomain (i...
All input/output operators are confined to this namespace.

Member Data Documentation

std::set<dimension_type> Parma_Polyhedra_Library::Partial_Function::codomain
private

Definition at line 79 of file Partial_Function_defs.hh.

Referenced by has_empty_codomain(), insert(), and max_in_codomain().

dimension_type Parma_Polyhedra_Library::Partial_Function::max
private

Definition at line 77 of file Partial_Function_defs.hh.

Referenced by insert(), and max_in_codomain().

std::vector<dimension_type> Parma_Polyhedra_Library::Partial_Function::vec
private

Definition at line 76 of file Partial_Function_defs.hh.

Referenced by has_empty_codomain(), insert(), maps(), and print().


The documentation for this class was generated from the following files: