[PPL-devel] [GIT] ppl/ppl(master): Added helper function to compute the hash code from a space dimension.
Enea Zaffanella
zaffanella at cs.unipr.it
Wed Feb 15 16:41:47 CET 2012
Module: ppl/ppl
Branch: master
Commit: dbd30b078d19997cdfeef23663310025fd8113a0
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=dbd30b078d19997cdfeef23663310025fd8113a0
Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date: Wed Feb 15 16:34:30 2012 +0100
Added helper function to compute the hash code from a space dimension.
Added missing has_code() method to class Box<ITV> and generate corresponding
method in Java interface for boxes.
---
...nterface_generator_java_procedure_generators.m4 | 2 +-
src/BD_Shape.inlines.hh | 2 +-
src/Box.defs.hh | 8 ++++++++
src/Box.inlines.hh | 6 ++++++
src/Grid.inlines.hh | 2 +-
src/Octagonal_Shape.inlines.hh | 2 +-
src/Partially_Reduced_Product.inlines.hh | 2 +-
src/Pointset_Ask_Tell.inlines.hh | 2 +-
src/Pointset_Powerset.inlines.hh | 2 +-
src/Polyhedron.inlines.hh | 2 +-
src/globals.defs.hh | 4 ++++
src/globals.inlines.hh | 6 ++++++
12 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/interfaces/Java/ppl_interface_generator_java_procedure_generators.m4 b/interfaces/Java/ppl_interface_generator_java_procedure_generators.m4
index b86af30..b81340a 100644
--- a/interfaces/Java/ppl_interface_generator_java_procedure_generators.m4
+++ b/interfaces/Java/ppl_interface_generator_java_procedure_generators.m4
@@ -42,7 +42,7 @@ dnl The <name> must be exactly as written here.
m4_define(`m4_procedure_list',
`m4_echo_unquoted(`m4_common_procedure_list',
ppl_free_ at CLASS@/1 +all,
-ppl_ at CLASS@_hashcode/2 +all -box,
+ppl_ at CLASS@_hashcode/2 +all,
ppl_ at CLASS@_string/1 +all,
ppl_termination_test_ at TERMINATION_ID@_ at TOPOLOGY@@CLASS@/1 +simple,
ppl_one_affine_ranking_function_ at TERMINATION_ID@_ at TOPOLOGY@@CLASS@/2 +simple,
diff --git a/src/BD_Shape.inlines.hh b/src/BD_Shape.inlines.hh
index 2b95b2e..bb83e46 100644
--- a/src/BD_Shape.inlines.hh
+++ b/src/BD_Shape.inlines.hh
@@ -838,7 +838,7 @@ BD_Shape<T>::total_memory_in_bytes() const {
template <typename T>
inline int32_t
BD_Shape<T>::hash_code() const {
- return space_dimension() & 0x7fffffff;
+ return hash_code_from_dimension(space_dimension());
}
template <typename T>
diff --git a/src/Box.defs.hh b/src/Box.defs.hh
index 8c1ccd5..695d7d4 100644
--- a/src/Box.defs.hh
+++ b/src/Box.defs.hh
@@ -1692,6 +1692,14 @@ public:
//! Returns the size in bytes of the memory managed by \p *this.
memory_size_type external_memory_in_bytes() const;
+ /*! \brief
+ Returns a 32-bit hash code for \p *this.
+
+ If <CODE>x</CODE> and <CODE>y</CODE> are such that <CODE>x == y</CODE>,
+ then <CODE>x.hash_code() == y.hash_code()</CODE>.
+ */
+ int32_t hash_code() const;
+
PPL_OUTPUT_DECLARATIONS
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
diff --git a/src/Box.inlines.hh b/src/Box.inlines.hh
index b7b0f7e..b38e30f 100644
--- a/src/Box.inlines.hh
+++ b/src/Box.inlines.hh
@@ -133,6 +133,12 @@ Box<ITV>::max_space_dimension() {
}
template <typename ITV>
+inline int32_t
+Box<ITV>::hash_code() const {
+ return hash_code_from_dimension(space_dimension());
+}
+
+template <typename ITV>
inline const ITV&
Box<ITV>::operator[](const dimension_type k) const {
PPL_ASSERT(k < seq.size());
diff --git a/src/Grid.inlines.hh b/src/Grid.inlines.hh
index 222e42a..3500339 100644
--- a/src/Grid.inlines.hh
+++ b/src/Grid.inlines.hh
@@ -228,7 +228,7 @@ Grid::total_memory_in_bytes() const {
inline int32_t
Grid::hash_code() const {
- return space_dimension() & 0x7fffffff;
+ return hash_code_from_dimension(space_dimension());
}
inline Constraint_System
diff --git a/src/Octagonal_Shape.inlines.hh b/src/Octagonal_Shape.inlines.hh
index c42379e..12357e8 100644
--- a/src/Octagonal_Shape.inlines.hh
+++ b/src/Octagonal_Shape.inlines.hh
@@ -864,7 +864,7 @@ Octagonal_Shape<T>::total_memory_in_bytes() const {
template <typename T>
inline int32_t
Octagonal_Shape<T>::hash_code() const {
- return space_dimension() & 0x7fffffff;
+ return hash_code_from_dimension(space_dimension());
}
template <typename T>
diff --git a/src/Partially_Reduced_Product.inlines.hh b/src/Partially_Reduced_Product.inlines.hh
index 8239bd2..a9e53cf 100644
--- a/src/Partially_Reduced_Product.inlines.hh
+++ b/src/Partially_Reduced_Product.inlines.hh
@@ -709,7 +709,7 @@ Partially_Reduced_Product<D1, D2, R>::ascii_dump(std::ostream& s) const {
template <typename D1, typename D2, typename R>
inline int32_t
Partially_Reduced_Product<D1, D2, R>::hash_code() const {
- return space_dimension() & 0x7fffffff;
+ return hash_code_from_dimension(space_dimension());
}
/*! \relates Parma_Polyhedra_Library::Partially_Reduced_Product */
diff --git a/src/Pointset_Ask_Tell.inlines.hh b/src/Pointset_Ask_Tell.inlines.hh
index 61b46fc..b4676b3 100644
--- a/src/Pointset_Ask_Tell.inlines.hh
+++ b/src/Pointset_Ask_Tell.inlines.hh
@@ -173,7 +173,7 @@ Pointset_Ask_Tell<PSET>::total_memory_in_bytes() const {
template <typename PSET>
inline int32_t
Pointset_Ask_Tell<PSET>::hash_code() const {
- return space_dimension() & 0x7fffffff;
+ return hash_code_from_dimension(space_dimension());
}
template <>
diff --git a/src/Pointset_Powerset.inlines.hh b/src/Pointset_Powerset.inlines.hh
index 94d787b..4076cb2 100644
--- a/src/Pointset_Powerset.inlines.hh
+++ b/src/Pointset_Powerset.inlines.hh
@@ -275,7 +275,7 @@ Pointset_Powerset<PSET>::total_memory_in_bytes() const {
template <typename PSET>
inline int32_t
Pointset_Powerset<PSET>::hash_code() const {
- return space_dimension() & 0x7fffffff;
+ return hash_code_from_dimension(space_dimension());
}
template <typename PSET>
diff --git a/src/Polyhedron.inlines.hh b/src/Polyhedron.inlines.hh
index eacb411..ff35596 100644
--- a/src/Polyhedron.inlines.hh
+++ b/src/Polyhedron.inlines.hh
@@ -43,7 +43,7 @@ Polyhedron::space_dimension() const {
inline int32_t
Polyhedron::hash_code() const {
- return space_dimension() & 0x7fffffff;
+ return hash_code_from_dimension(space_dimension());
}
inline dimension_type
diff --git a/src/globals.defs.hh b/src/globals.defs.hh
index 9b59ba1..e564878 100644
--- a/src/globals.defs.hh
+++ b/src/globals.defs.hh
@@ -42,6 +42,10 @@ namespace Parma_Polyhedra_Library {
dimension_type
not_a_dimension();
+//! Returns the hash code for space dimension \p dim.
+int32_t
+hash_code_from_dimension(dimension_type dim);
+
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
/*! \brief
Make sure swap() is specialized when needed.
diff --git a/src/globals.inlines.hh b/src/globals.inlines.hh
index 93d2ba7..9047d1c 100644
--- a/src/globals.inlines.hh
+++ b/src/globals.inlines.hh
@@ -34,6 +34,12 @@ not_a_dimension() {
return std::numeric_limits<dimension_type>::max();
}
+inline int32_t
+hash_code_from_dimension(dimension_type dim) {
+ const dimension_type divisor = 1U << (32 - 1);
+ return static_cast<int32_t>(dim % divisor);
+}
+
inline const Weightwatch_Traits::Threshold&
Weightwatch_Traits::get() {
return weight;
More information about the PPL-devel
mailing list