this repo has no description
at develop 3.3 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Copyright: 7 * Christian Schulte, 2008 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34namespace Gecode { namespace Iter { namespace Values { 35 36 /** 37 * \brief Value iterator for the intersection of two value iterators 38 * 39 * \ingroup FuncIterValues 40 */ 41 42 template<class I, class J> 43 class Inter { 44 protected: 45 /// First iterator 46 I i; 47 /// Second iterator 48 J j; 49 /// Find next element from intersection 50 void next(void); 51 public: 52 /// \name Constructors and initialization 53 //@{ 54 /// Default constructor 55 Inter(void); 56 /// Initialize with values from \a i and \a j 57 Inter(I& i, J& j); 58 /// Initialize with values from \a i and \a j 59 void init(I& i, J& j); 60 //@} 61 62 /// \name Iteration control 63 //@{ 64 /// Test whether iterator is still at a value or done 65 bool operator ()(void) const; 66 /// Move iterator to next value (if possible) 67 void operator ++(void); 68 //@} 69 70 /// \name Value access 71 //@{ 72 /// Return current value 73 int val(void) const; 74 //@} 75 }; 76 77 78 template<class I, class J> 79 forceinline 80 Inter<I,J>::Inter(void) {} 81 82 template<class I, class J> 83 forceinline void 84 Inter<I,J>::next(void) { 85 do { 86 while (i() && j() && (i.val() < j.val())) 87 ++i; 88 while (i() && j() && (j.val() < i.val())) 89 ++j; 90 } while (i() && j() && (i.val() != j.val())); 91 } 92 93 template<class I, class J> 94 inline void 95 Inter<I,J>::init(I& i0, J& j0) { 96 i=i0; j=j0; next(); 97 } 98 99 template<class I, class J> 100 forceinline 101 Inter<I,J>::Inter(I& i0, J& j0) : i(i0), j(j0) { 102 next(); 103 } 104 105 template<class I, class J> 106 forceinline void 107 Inter<I,J>::operator ++(void) { 108 ++i; ++j; next(); 109 } 110 111 template<class I, class J> 112 forceinline bool 113 Inter<I,J>::operator ()(void) const { 114 return i() && j(); 115 } 116 117 template<class I, class J> 118 forceinline int 119 Inter<I,J>::val(void) const { 120 assert(i.val() == j.val()); 121 return i.val(); 122 } 123 124}}} 125 126// STATISTICS: iter-any