From 16aaf4cda5fd97da12a7f1da8b0a5168fac2e289 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 11 Oct 2016 13:57:03 +0000 Subject: Problem of merge with tangentialcomplex branch. Redo in an integration branch git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/tangential_integration@1701 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fa029e8e90b3e203ea675f02098ec6fe95596f9f --- .../CGAL/internal/Combination_enumerator.h | 148 +++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 src/common/include/gudhi_patches/CGAL/internal/Combination_enumerator.h (limited to 'src/common/include/gudhi_patches/CGAL/internal/Combination_enumerator.h') diff --git a/src/common/include/gudhi_patches/CGAL/internal/Combination_enumerator.h b/src/common/include/gudhi_patches/CGAL/internal/Combination_enumerator.h new file mode 100644 index 00000000..f411e827 --- /dev/null +++ b/src/common/include/gudhi_patches/CGAL/internal/Combination_enumerator.h @@ -0,0 +1,148 @@ +// Copyright (c) 2009-2014 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// 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. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Samuel Hornus + +#ifndef CGAL_INTERNAL_COMBINATION_ENUMERATOR_H +#define CGAL_INTERNAL_COMBINATION_ENUMERATOR_H + +#include +#include + +namespace CGAL { + +namespace internal { + +class Combination_enumerator +{ + // types and member data + typedef std::vector Combination; + Combination combi_; + const int k_; + const int min_; + const int max_; + const int max_at_pos_0_; + +public: + + // For generating all the combinations of |k| distinct elements in the + // interval [min, max] (both included) + Combination_enumerator(const int k, const int min, const int max) + : combi_(k), k_(k), min_(min), max_(max), max_at_pos_0_(max + 1 - k) + { + CGAL_assertion_msg( min <= max, "min is larger than max"); + CGAL_assertion_msg( 1 <= k && k <= ( max - min + 1 ), "wrong value of k"); + init(); + } + + Combination_enumerator(const Combination_enumerator & c) + : combi_(c.combi_), k_(c.k_), min_(c.min_), max_(c.max_), max_at_pos_0_(c.max_at_pos_0_) + {} + + int number_of_elements() + { + return k_; + } + + void init() + { + combi_.resize(k_); + for( int i = 0; i < k_; ++i ) + element(i) = min_ + i; + } + + bool end() const + { + return ( element(0) > max_at_pos_0_ ); + } + + int element(const int i) const + { + CGAL_assertion( 0 <= i && i < k_ ); + return combi_[i]; + } + + int & element(const int i) + { + CGAL_assertion( 0 <= i && i < k_ ); + return combi_[i]; + } + + int operator[](const int i) const + { + return element(i); + } + + int & operator[](const int i) + { + return element(i); + } + + void operator++() + { + int i = k_ - 1; + int max_at_pos_i(max_); + while( ( i >= 0 ) && ( element(i) >= max_at_pos_i ) ) + { + --i; + --max_at_pos_i; + } + if( -1 == i ) + { + if( element(0) == max_at_pos_0_ ) + ++element(0); // mark then end of the enumeration with an impossible value + // Note than when we have arrived at the end of the enumeration, applying + // operator++() again does not change anything, so it is safe to + // apply it too many times. + } + else + { + ++element(i); + for( int j = i + 1; j < k_; ++j ) + element(j) = element(i) + j - i; + } + } + + Combination_enumerator operator++(int) + { + Combination_enumerator tmp(*this); + ++(*this); + return tmp; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - TESTING +#if 0 + void test() + { + std::cerr << '\n'; + while( ! end() ) + { + std::cerr << '\n'; + for( int i = 0; i < k_; ++i ) + std::cerr << element(i) << ' '; + ++(*this); + } + init(); + } +#endif +}; + +} // end of namespace internal + +} // end of namespace CGAL + +#endif // CGAL_INTERNAL_COMBINATION_ENUMERATOR_H -- cgit v1.2.3