Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
values-union.hpp
Go to the documentation of this file.
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
41
42 template<class I, class J>
43 class Union {
44 protected:
46 I i;
48 J j;
50 int v;
52 bool done;
53 public:
55
56
57 Union(void);
59 Union(I& i, J& j);
61 void init(I& i, J& j);
63
65
66
67 bool operator ()(void) const;
69 void operator ++(void);
71
73
74
75 int val(void) const;
77 };
78
79
80 template<class I, class J>
82 Union<I,J>::Union(void) : v(0) {}
83
84 template<class I, class J>
85 forceinline void
87 if (i()) {
88 if (j()) {
89 if (i.val() == j.val()) {
90 v=i.val(); ++i; ++j;
91 } else if (i.val() < j.val()) {
92 v=i.val(); ++i;
93 } else {
94 v=j.val(); ++j;
95 }
96 } else {
97 v=i.val(); ++i;
98 }
99 } else if (j()) {
100 v=j.val(); ++j;
101 } else {
102 done=true;
103 }
104 }
105
106 template<class I, class J>
107 inline void
108 Union<I,J>::init(I& i0, J& j0) {
109 i=i0; j=j0; v=0; done=false;
110 operator ++();
111 }
112
113 template<class I, class J>
115 Union<I,J>::Union(I& i0, J& j0) : i(i0), j(j0), v(0), done(false) {
116 operator ++();
117 }
118
119 template<class I, class J>
120 forceinline bool
122 return !done;
123 }
124
125 template<class I, class J>
126 forceinline int
127 Union<I,J>::val(void) const {
128 return v;
129 }
130
131}}}
132
133// STATISTICS: iter-any
void operator++(void)
Move iterator to next value (if possible)
bool done
Whether iterator is done.
int val(void) const
Return current value.
void init(I &i, J &j)
Initialize with values from i and j.
bool operator()(void) const
Test whether iterator is still at a value or done.
Union(void)
Default constructor.
Value iterators.
Definition iter.hh:45
Range and value iterators.
Definition iter.hh:41
Gecode toplevel namespace
#define forceinline
Definition config.hpp:194