~chaffra/+junk/trilinos

« back to all changes in this revision

Viewing changes to packages/Sundance/src-utils/Utilities/SundanceSet.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme, Christophe Prud'homme, Johannes Ring
  • Date: 2009-12-13 12:53:22 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091213125322-in0nrdjc55deqsw9
Tags: 10.0.3.dfsg-1
[Christophe Prud'homme]
* New upstream release

[Johannes Ring]
* debian/patches/libname.patch: Add prefix 'libtrilinos_' to all
  libraries. 
* debian/patches/soname.patch: Add soversion to libraries.
* debian/watch: Update download URL.
* debian/control:
  - Remove python-numeric from Build-Depends (virtual package).
  - Remove automake and autotools from Build-Depends and add cmake to
    reflect switch to CMake.
  - Add python-support to Build-Depends.
* debian/rules: 
  - Cleanup and updates for switch to CMake.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
namespace SundanceUtils
43
43
{
44
 
  using namespace Teuchos;
45
 
 
46
 
  /** 
47
 
   * Extension of STL set, adding some nicer syntax 
48
 
   * and an iostream insertion operator.
49
 
   */
50
 
  template<class Key, class Compare = std::less<Key> >
51
 
  class Set : public std::set<Key, Compare>
52
 
  {
53
 
  public:
54
 
    /** */
55
 
    Set() : std::set<Key, Compare>() {;}
56
 
 
57
 
    /** Test whether the specified key is present in the set */
58
 
    bool contains(const Key& key) const {return this->find(key) != this->end();}
59
 
 
60
 
    /** Put a new entry in the set */
61
 
    void put(const Key& key) {insert(key);}
62
 
 
63
 
    /** Write into an array */
64
 
    Array<Key> elements() const ;
65
 
 
66
 
    /** */
67
 
    void elements(Array<Key>& keys) const ;
68
 
 
69
 
    /** */
70
 
    void merge(const Set<Key, Compare>& other);
71
 
 
72
 
    /** */
73
 
    Set<Key, Compare> intersection(const Set<Key, Compare>& other) const ;
74
 
 
75
 
    /** */
76
 
    Set<Key, Compare> setUnion(const Set<Key, Compare>& other) const ;
77
 
 
78
 
    /** */
79
 
    Set<Key, Compare> setDifference(const Set<Key, Compare>& other) const ;
80
 
 
81
 
    /** */
82
 
    std::ostream& toStream(std::ostream& os) const ;
83
 
 
84
 
    /** */
85
 
    string toString() const ;
86
 
  };
87
 
 
88
 
 
89
 
  template<class Key, class Compare> inline
90
 
  Array<Key> Set<Key, Compare>::elements() const
91
 
  {
92
 
    Array<Key> rtn;
93
 
 
94
 
    typename Set<Key, Compare>::const_iterator iter;
95
 
 
96
 
    for (iter=this->begin(); iter != this->end(); iter++)
97
 
      {
98
 
        rtn.append(*iter);
99
 
      }
100
 
    return rtn;
101
 
  }
102
 
 
103
 
 
104
 
  template<class Key, class Compare> inline
105
 
  void Set<Key, Compare>::elements(Array<Key>& rtn) const
106
 
  {
107
 
    rtn.resize(0);
108
 
    typename Set<Key, Compare>::const_iterator iter;
109
 
 
110
 
    for (iter=this->begin(); iter != this->end(); iter++)
111
 
      {
112
 
        rtn.append(*iter);
113
 
      }
114
 
  }
115
 
 
116
 
  template<class Key, class Compare> inline
117
 
  void Set<Key, Compare>::merge(const Set<Key, Compare>& other)
118
 
  {
119
 
    typename Set<Key, Compare>::const_iterator iter;
120
 
 
121
 
    for (iter=other.begin(); iter != other.end(); iter++)
122
 
      {
123
 
        put(*iter);
124
 
      }
125
 
  }
126
 
 
127
 
  template<class Key, class Compare> inline
128
 
  Set<Key, Compare> Set<Key, Compare>::intersection(const Set<Key, Compare>& other) const
129
 
  {
130
 
    Set<Key, Compare> rtn;
131
 
 
132
 
    set_intersection(this->begin(), this->end(),
133
 
                     other.begin(), other.end(), 
134
 
                     std::insert_iterator<Set<Key, Compare> >(rtn, rtn.begin())); 
135
 
    return rtn;
136
 
  }
137
 
 
138
 
  template<class Key, class Compare> inline
139
 
  Set<Key, Compare> Set<Key, Compare>::setUnion(const Set<Key, Compare>& other) const
140
 
  {
141
 
    Set<Key, Compare> rtn;
142
 
 
143
 
    set_union(this->begin(), this->end(),
144
 
              other.begin(), other.end(), 
145
 
              std::insert_iterator<Set<Key, Compare> >(rtn, rtn.begin())); 
146
 
    return rtn;
147
 
  }
148
 
 
149
 
  template<class Key, class Compare> inline
150
 
  Set<Key, Compare> Set<Key, Compare>::setDifference(const Set<Key, Compare>& other) const
151
 
  {
152
 
    Set<Key, Compare> rtn;
153
 
 
154
 
    set_difference(this->begin(), this->end(),
155
 
                   other.begin(), other.end(), 
156
 
                   std::insert_iterator<Set<Key, Compare> >(rtn, rtn.begin())); 
157
 
    return rtn;
158
 
  }
159
 
 
160
 
  template<class Key, class Compare> inline
161
 
  std::ostream& Set<Key, Compare>::toStream(std::ostream& os) const
162
 
  {
163
 
    typename Set<Key, Compare>::const_iterator iter;
164
 
 
165
 
    unsigned int k = 0;
166
 
    os << "{";
167
 
    for (iter=this->begin(); iter != this->end(); iter++, k++)
168
 
      {
169
 
        os << *iter;
170
 
        if (k<(this->size()-1)) os << ", ";
171
 
      }
172
 
    os << "}";
173
 
 
174
 
    return os;
175
 
  }
176
 
 
177
 
  template<class Key, class Compare> inline
178
 
  string Set<Key, Compare>::toString() const
179
 
  {
180
 
    std::ostringstream os;
181
 
    os << *this;
182
 
    return os.str();
183
 
  }
184
 
 
185
 
  /** \relates Set Creates a set */
186
 
  template<class Key> inline
187
 
  Set<Key> makeSet(const Key& k)
188
 
  {
189
 
    Set<Key> rtn;
190
 
    rtn.put(k);
191
 
    return rtn;
192
 
  }
193
 
 
194
 
  /** \relates Set Creates a set */
195
 
  template<class Key> inline
196
 
  Set<Key> makeSet(const Key& k1, const Key& k2)
197
 
  {
198
 
    Set<Key> rtn = makeSet<Key>(k1);
199
 
    rtn.put(k2);
200
 
    return rtn;
201
 
  }
202
 
 
203
 
  /** \relates Set Creates a set */
204
 
  template<class Key> inline
205
 
  Set<Key> makeSet(const Key& k1, const Key& k2, const Key& k3)
206
 
  {
207
 
    Set<Key> rtn = makeSet<Key>(k1, k2);
208
 
    rtn.put(k3);
209
 
    return rtn;
210
 
  }
211
 
 
212
 
  /** \relates Set Creates a set */
213
 
  template<class Key> inline
214
 
  Set<Key> makeSet(const Key& k1, const Key& k2, const Key& k3, const Key& k4)
215
 
  {
216
 
    Set<Key> rtn = makeSet<Key>(k1, k2, k3);
217
 
    rtn.put(k4);
218
 
    return rtn;
219
 
  }
220
 
 
221
 
  /** \relates Set Creates a set */
222
 
  template<class Key> inline
223
 
  Set<Key> makeSet(const Key& k1, const Key& k2, const Key& k3, const Key& k4,
224
 
                   const Key& k5)
225
 
  {
226
 
    Set<Key> rtn = makeSet<Key>(k1, k2, k3, k4);
227
 
    rtn.put(k5);
228
 
    return rtn;
229
 
  }
230
 
 
231
 
  /** \relates Set Creates a set */
232
 
  template<class Key> inline
233
 
  Set<Key> makeSet(const Key& k1, const Key& k2, const Key& k3, const Key& k4,
234
 
                   const Key& k5, const Key& k6)
235
 
  {
236
 
    Set<Key> rtn = makeSet<Key>(k1, k2, k3, k4, k5);
237
 
    rtn.put(k6);
238
 
    return rtn;
239
 
  }
240
 
 
241
 
  /** \relates Set Creates a set */
242
 
  template<class Key> inline
243
 
  Set<Key> makeSet(const Key& k1, const Key& k2, const Key& k3, const Key& k4,
244
 
                   const Key& k5, const Key& k6, const Key& k7)
245
 
  {
246
 
    Set<Key> rtn = makeSet<Key>(k1, k2, k3, k4, k5, k6);
247
 
    rtn.put(k7);
248
 
    return rtn;
249
 
  }
250
 
 
251
 
  /** \relates Set Creates a set */
252
 
  template<class Key> inline
253
 
  Set<Key> makeSet(const Key& k1, const Key& k2, const Key& k3, const Key& k4,
254
 
                   const Key& k5, const Key& k6, const Key& k7, const Key& k8)
255
 
  {
256
 
    Set<Key> rtn = makeSet<Key>(k1, k2, k3, k4, k5, k6, k7);
257
 
    rtn.put(k8);
258
 
    return rtn;
259
 
  }
260
 
 
 
44
using namespace Teuchos;
 
45
 
 
46
/** 
 
47
 * Extension of STL set, adding some nicer syntax 
 
48
 * and an iostream insertion operator.
 
49
 */
 
50
template<class Key, class Compare = std::less<Key> >
 
51
class Set 
 
52
{
 
53
public:
 
54
    
 
55
  typedef typename std::set<Key, Compare>::iterator iterator;
 
56
  typedef typename std::set<Key, Compare>::const_iterator const_iterator;
 
57
  typedef typename std::set<Key, Compare>::reverse_iterator reverse_iterator;
 
58
  typedef typename std::set<Key, Compare>::const_reverse_iterator const_reverse_iterator;
 
59
 
 
60
  typedef typename std::set<Key, Compare>::size_type size_type;
 
61
  typedef typename std::set<Key, Compare>::pointer pointer;
 
62
  typedef typename std::set<Key, Compare>::const_pointer const_pointer;
 
63
  typedef typename std::set<Key, Compare>::const_reference const_reference;
 
64
  typedef typename std::set<Key, Compare>::reference reference;
 
65
  typedef typename std::set<Key, Compare>::difference_type difference_type;
 
66
    
 
67
  /** */
 
68
  Set() : set_() {;}
 
69
 
 
70
  /** */
 
71
  Set(const std::set<Key>& s) : set_(s) {;}
 
72
 
 
73
  /** */
 
74
  iterator begin() {return set_.begin();}
 
75
 
 
76
  /** */
 
77
  const_iterator begin() const {return set_.begin();}
 
78
 
 
79
  /** */
 
80
  iterator end() {return set_.end();}
 
81
 
 
82
  /** */
 
83
  const_iterator end() const {return set_.end();}
 
84
 
 
85
  /** */
 
86
  reverse_iterator rbegin() {return set_.rbegin();}
 
87
 
 
88
  /** */
 
89
  const_reverse_iterator rbegin() const {return set_.rbegin();}
 
90
 
 
91
  /** */
 
92
  reverse_iterator rend() {return set_.rend();}
 
93
 
 
94
  /** */
 
95
  const_reverse_iterator rend() const {return set_.rend();}
 
96
 
 
97
  /** */
 
98
  std::pair<iterator, bool> insert(const Key& x) {return set_.insert(x);}
 
99
 
 
100
  /** */
 
101
  iterator insert(iterator pos, const Key& x) {return set_.insert(pos,x);}
 
102
 
 
103
  /** */
 
104
  void erase(iterator pos) {set_.erase(pos);}
 
105
 
 
106
  /** */
 
107
  void erase(const Key& x) {set_.erase(x);}
 
108
 
 
109
  /** */
 
110
  void erase(iterator first, iterator last) {set_.erase(first, last);}
 
111
 
 
112
  /** */
 
113
  void clear() {set_.clear();}
 
114
 
 
115
  /** */
 
116
  iterator find(const Key& x) {return set_.find(x);}
 
117
 
 
118
  /** */
 
119
  const_iterator find(const Key& x) const {return set_.find(x);}
 
120
 
 
121
  /** */
 
122
  iterator lower_bound(const Key& x) {return set_.lower_bound(x);}
 
123
 
 
124
  /** */
 
125
  const_iterator lower_bound(const Key& x) const {return set_.lower_bound(x);}
 
126
 
 
127
  /** */
 
128
  iterator upper_bound(const Key& x) {return set_.upper_bound(x);}
 
129
 
 
130
  /** */
 
131
  const_iterator upper_bound(const Key& x) const {return set_.upper_bound(x);}
 
132
 
 
133
  /** */
 
134
  std::pair<iterator,iterator> equal_range(const Key& x)
 
135
    {return set_.equal_range(x);}
 
136
 
 
137
  /** */
 
138
  std::pair<const_iterator,const_iterator> equal_range(const Key& x) const 
 
139
    {return set_.equal_range(x);}
 
140
 
 
141
  /** */
 
142
  size_type size() const {return set_.size();}
 
143
 
 
144
  /** */
 
145
  size_type max_size() const {return set_.max_size();}
 
146
 
 
147
  /** */
 
148
  bool empty() const {return set_.empty();}
 
149
    
 
150
  /** */
 
151
  const std::set<Key, Compare>& set() const {return set_;}
 
152
    
 
153
  /** */
 
154
  std::set<Key, Compare>& set() {return set_;}
 
155
 
 
156
  /** Test whether the specified key is present in the set */
 
157
  bool contains(const Key& key) const {return this->find(key) != this->end();}
 
158
 
 
159
  /** Put a new entry in the set */
 
160
  void put(const Key& key) {insert(key);}
 
161
 
 
162
  /** Write into an array */
 
163
  Array<Key> elements() const ;
 
164
 
 
165
  /** */
 
166
  void elements(Array<Key>& keys) const ;
 
167
 
 
168
  /** */
 
169
  void merge(const Set<Key, Compare>& other);
 
170
 
 
171
  /** */
 
172
  Set<Key, Compare> intersection(const Set<Key, Compare>& other) const ;
 
173
 
 
174
  /** */
 
175
  Set<Key, Compare> setUnion(const Set<Key, Compare>& other) const ;
 
176
 
 
177
  /** */
 
178
  Set<Key, Compare> setDifference(const Set<Key, Compare>& other) const ;
 
179
 
 
180
  /** */
 
181
  std::ostream& toStream(std::ostream& os) const ;
 
182
 
 
183
  /** */
 
184
  string toString() const ;
 
185
 
 
186
private:
 
187
  std::set<Key, Compare> set_;
 
188
};
 
189
 
 
190
 
 
191
template<class Key, class Compare> inline
 
192
Array<Key> Set<Key, Compare>::elements() const
 
193
{
 
194
  Array<Key> rtn;
 
195
 
 
196
  typename Set<Key, Compare>::const_iterator iter;
 
197
 
 
198
  for (iter=this->begin(); iter != this->end(); iter++)
 
199
  {
 
200
    rtn.append(*iter);
 
201
  }
 
202
  return rtn;
 
203
}
 
204
 
 
205
 
 
206
template<class Key, class Compare> inline
 
207
void Set<Key, Compare>::elements(Array<Key>& rtn) const
 
208
{
 
209
  rtn.resize(0);
 
210
  typename Set<Key, Compare>::const_iterator iter;
 
211
 
 
212
  for (iter=this->begin(); iter != this->end(); iter++)
 
213
  {
 
214
    rtn.append(*iter);
 
215
  }
 
216
}
 
217
 
 
218
template<class Key, class Compare> inline
 
219
void Set<Key, Compare>::merge(const Set<Key, Compare>& other)
 
220
{
 
221
  typename Set<Key, Compare>::const_iterator iter;
 
222
 
 
223
  for (iter=other.begin(); iter != other.end(); iter++)
 
224
  {
 
225
    put(*iter);
 
226
  }
 
227
}
 
228
 
 
229
template<class Key, class Compare> inline
 
230
Set<Key, Compare> Set<Key, Compare>::intersection(const Set<Key, Compare>& other) const
 
231
{
 
232
  Set<Key, Compare> rtn;
 
233
 
 
234
  set_intersection(this->begin(), this->end(),
 
235
    other.begin(), other.end(), 
 
236
    std::insert_iterator<Set<Key, Compare> >(rtn, rtn.begin())); 
 
237
  return rtn;
 
238
}
 
239
 
 
240
template<class Key, class Compare> inline
 
241
Set<Key, Compare> Set<Key, Compare>::setUnion(const Set<Key, Compare>& other) const
 
242
{
 
243
  Set<Key, Compare> rtn;
 
244
 
 
245
  set_union(this->begin(), this->end(),
 
246
    other.begin(), other.end(), 
 
247
    std::insert_iterator<Set<Key, Compare> >(rtn, rtn.begin())); 
 
248
  return rtn;
 
249
}
 
250
 
 
251
template<class Key, class Compare> inline
 
252
Set<Key, Compare> Set<Key, Compare>::setDifference(const Set<Key, Compare>& other) const
 
253
{
 
254
  Set<Key, Compare> rtn;
 
255
 
 
256
  set_difference(this->begin(), this->end(),
 
257
    other.begin(), other.end(), 
 
258
    std::insert_iterator<Set<Key, Compare> >(rtn, rtn.begin())); 
 
259
  return rtn;
 
260
}
 
261
 
 
262
template<class Key, class Compare> inline
 
263
std::ostream& Set<Key, Compare>::toStream(std::ostream& os) const
 
264
{
 
265
  typename Set<Key, Compare>::const_iterator iter;
 
266
 
 
267
  unsigned int k = 0;
 
268
  os << "{";
 
269
  for (iter=this->begin(); iter != this->end(); iter++, k++)
 
270
  {
 
271
    os << *iter;
 
272
    if (k<(this->size()-1)) os << ", ";
 
273
  }
 
274
  os << "}";
 
275
 
 
276
  return os;
 
277
}
 
278
 
 
279
template<class Key, class Compare> inline
 
280
string Set<Key, Compare>::toString() const
 
281
{
 
282
  std::ostringstream os;
 
283
  os << *this;
 
284
  return os.str();
 
285
}
 
286
 
 
287
/** \relates Set Creates a set */
 
288
template<class Key> inline
 
289
Set<Key> makeSet(const Key& k)
 
290
{
 
291
  Set<Key> rtn;
 
292
  rtn.put(k);
 
293
  return rtn;
 
294
}
 
295
 
 
296
/** \relates Set Creates a set */
 
297
template<class Key> inline
 
298
Set<Key> makeSet(const Key& k1, const Key& k2)
 
299
{
 
300
  Set<Key> rtn = makeSet<Key>(k1);
 
301
  rtn.put(k2);
 
302
  return rtn;
 
303
}
 
304
 
 
305
/** \relates Set Creates a set */
 
306
template<class Key> inline
 
307
Set<Key> makeSet(const Key& k1, const Key& k2, const Key& k3)
 
308
{
 
309
  Set<Key> rtn = makeSet<Key>(k1, k2);
 
310
  rtn.put(k3);
 
311
  return rtn;
 
312
}
 
313
 
 
314
/** \relates Set Creates a set */
 
315
template<class Key> inline
 
316
Set<Key> makeSet(const Key& k1, const Key& k2, const Key& k3, const Key& k4)
 
317
{
 
318
  Set<Key> rtn = makeSet<Key>(k1, k2, k3);
 
319
  rtn.put(k4);
 
320
  return rtn;
 
321
}
 
322
 
 
323
/** \relates Set Creates a set */
 
324
template<class Key> inline
 
325
Set<Key> makeSet(const Key& k1, const Key& k2, const Key& k3, const Key& k4,
 
326
  const Key& k5)
 
327
{
 
328
  Set<Key> rtn = makeSet<Key>(k1, k2, k3, k4);
 
329
  rtn.put(k5);
 
330
  return rtn;
 
331
}
 
332
 
 
333
/** \relates Set Creates a set */
 
334
template<class Key> inline
 
335
Set<Key> makeSet(const Key& k1, const Key& k2, const Key& k3, const Key& k4,
 
336
  const Key& k5, const Key& k6)
 
337
{
 
338
  Set<Key> rtn = makeSet<Key>(k1, k2, k3, k4, k5);
 
339
  rtn.put(k6);
 
340
  return rtn;
 
341
}
 
342
 
 
343
/** \relates Set Creates a set */
 
344
template<class Key> inline
 
345
Set<Key> makeSet(const Key& k1, const Key& k2, const Key& k3, const Key& k4,
 
346
  const Key& k5, const Key& k6, const Key& k7)
 
347
{
 
348
  Set<Key> rtn = makeSet<Key>(k1, k2, k3, k4, k5, k6);
 
349
  rtn.put(k7);
 
350
  return rtn;
 
351
}
 
352
 
 
353
/** \relates Set Creates a set */
 
354
template<class Key> inline
 
355
Set<Key> makeSet(const Key& k1, const Key& k2, const Key& k3, const Key& k4,
 
356
  const Key& k5, const Key& k6, const Key& k7, const Key& k8)
 
357
{
 
358
  Set<Key> rtn = makeSet<Key>(k1, k2, k3, k4, k5, k6, k7);
 
359
  rtn.put(k8);
 
360
  return rtn;
 
361
}
 
362
 
 
363
 
 
364
/** \relates Set */
 
365
template <typename Key, typename Compare> bool operator==(
 
366
  const Set<Key, Compare>& L,
 
367
  const Set<Key, Compare>& R)
 
368
{
 
369
  return L.set() == R.set();
 
370
}
 
371
 
 
372
/** \relates Set */
 
373
template <typename Key, typename Compare> bool operator!=(
 
374
  const Set<Key, Compare>& L,
 
375
  const Set<Key, Compare>& R)
 
376
{
 
377
  return L.set() != R.set();
 
378
}
 
379
 
 
380
/** \relates Set */
 
381
template <typename Key, typename Compare> bool operator<=(
 
382
  const Set<Key, Compare>& L,
 
383
  const Set<Key, Compare>& R)
 
384
{
 
385
  return L.set() <= R.set();
 
386
}
 
387
 
 
388
/** \relates Set */
 
389
template <typename Key, typename Compare> bool operator<(
 
390
  const Set<Key, Compare>& L,
 
391
  const Set<Key, Compare>& R)
 
392
{
 
393
  return L.set() < R.set();
 
394
}
 
395
 
 
396
 
 
397
/** \relates Set */
 
398
template <typename Key, typename Compare> bool operator>(
 
399
  const Set<Key, Compare>& L,
 
400
  const Set<Key, Compare>& R)
 
401
{
 
402
  return L.set() > R.set();
 
403
}
 
404
 
 
405
/** \relates Set */
 
406
template <typename Key, typename Compare> bool operator>=(
 
407
  const Set<Key, Compare>& L,
 
408
  const Set<Key, Compare>& R)
 
409
{
 
410
  return L.set() >= R.set();
 
411
}
 
412
 
 
413
 
 
414
 
 
415
  
261
416
}
262
417
 
263
418
namespace std
264
419
{
265
 
  /** \relates SundanceUtils::Set */
266
 
  template<class Key, class Compare> inline
267
 
  ostream& operator<<(ostream& os, const SundanceUtils::Set<Key, Compare>& m)
268
 
  {return m.toStream(os);}
 
420
/** \relates SundanceUtils::Set */
 
421
template<class Key, class Compare> inline
 
422
ostream& operator<<(ostream& os, const SundanceUtils::Set<Key, Compare>& m)
 
423
{return m.toStream(os);}
269
424
}
270
425
 
271
426
#endif /* DOXYGEN_DEVELOPER_ONLY */