aGrUM  0.14.2
idSet.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
25 #ifndef GUM_LEARNING_ID_SET_H
26 #define GUM_LEARNING_ID_SET_H
27 
28 #include <iostream>
29 #include <sstream>
30 #include <string>
31 #include <type_traits>
32 #include <utility>
33 #include <vector>
34 
35 #include <agrum/agrum.h>
36 #include <agrum/core/sequence.h>
38 
39 namespace gum {
40 
41  namespace learning {
42 
43 
44  template < template < typename > class ALLOC >
45  class IdSet;
46 
47 
53  template < template < typename > class ALLOC = std::allocator >
54  class IdSetIterator {
55  public:
58  using iterator_category = std::forward_iterator_tag;
59  using value_type = NodeId;
60  using reference = NodeId&;
61  using const_reference = const NodeId&;
62  using pointer = NodeId*;
63  using const_pointer = const NodeId*;
64  using difference_type = std::ptrdiff_t;
66 
67 
68  // ##########################################################################
70  // ##########################################################################
72 
74 
75  IdSetIterator();
76 
78 
79  IdSetIterator(const IdSet< ALLOC >& idset);
80 
83 
86 
88  virtual ~IdSetIterator();
89 
91 
92 
93  // ##########################################################################
95  // ##########################################################################
97 
100 
103 
108  NodeId operator*() const;
109 
111  bool operator!=(const IdSetIterator< ALLOC >& from) const;
112 
114  bool operator==(const IdSetIterator< ALLOC >& from) const;
115 
128 
134  IdSetIterator< ALLOC >& operator+=(const std::size_t i);
135 
141  IdSetIterator< ALLOC > operator+(const std::size_t i);
142 
144 
145 
146  // ##########################################################################
148  // ##########################################################################
150 
156  std::size_t pos() const;
157 
159 
160 
161 #ifndef DOXYGEN_SHOULD_SKIP_THIS
162 
163  private:
165  const Sequence< NodeId, ALLOC< NodeId > >* __seq{nullptr};
166 
168  std::size_t __index{std::size_t(0)};
169 
170 
172  void __gotoEnd();
173 
174  friend class IdSet< ALLOC >;
175 
176 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
177  };
178 
179 
193  template < template < typename > class ALLOC = std::allocator >
194  class IdSet : private ALLOC< NodeId > {
195  public:
197  using allocator_type = ALLOC< NodeId >;
198 
203 
204  // ##########################################################################
206  // ##########################################################################
208 
210  IdSet(const allocator_type& alloc = allocator_type());
211 
213 
219  IdSet(const std::vector< NodeId, ALLOC< NodeId > >& ids,
220  const bool rhs_ids,
221  const bool ordered_ids,
222  const allocator_type& alloc = allocator_type());
223 
225 
231  IdSet(NodeId var1,
232  const std::vector< NodeId, ALLOC< NodeId > >& rhs_ids,
233  const bool ordered_rhs_ids = false,
234  const allocator_type& alloc = allocator_type());
235 
237 
248  IdSet(NodeId var1,
249  NodeId var2,
250  const std::vector< NodeId, ALLOC< NodeId > >& rhs_ids,
251  const bool ordered_lhs_vars,
252  const bool ordered_rhs_ids = false,
253  const allocator_type& alloc = allocator_type());
254 
256 
266  IdSet(NodeId var1,
267  NodeId var2,
268  NodeId var3,
269  const std::vector< NodeId, ALLOC< NodeId > >& rhs_ids,
270  const bool ordered_lhs_vars,
271  const bool ordered_rhs_ids = false,
272  const allocator_type& alloc = allocator_type());
273 
275  IdSet(const IdSet< ALLOC >& from);
276 
278  IdSet(const IdSet< ALLOC >& from, const allocator_type& alloc);
279 
281  IdSet(IdSet< ALLOC >&& from);
282 
284  IdSet(IdSet< ALLOC >&& from, const allocator_type& alloc);
285 
287  virtual IdSet< ALLOC >* clone() const;
288 
290  virtual IdSet< ALLOC >* clone(const allocator_type& alloc) const;
291 
293  virtual ~IdSet();
294 
296 
297 
298  // ##########################################################################
300  // ##########################################################################
302 
305 
308 
310  NodeId operator[](const std::size_t index) const;
311 
313  bool operator==(const IdSet< ALLOC >& from) const;
314 
316  bool operator!=(const IdSet< ALLOC >& from) const;
317 
319 
320 
321  // ##########################################################################
323  // ##########################################################################
325 
330  iterator_safe beginSafe() const;
331 
336  const iterator_safe& endSafe() const;
337 
342  iterator begin() const;
343 
348  const iterator& end() const;
349 
351 
352 
353  // ##########################################################################
355  // ##########################################################################
357 
359  const Sequence< NodeId, ALLOC< NodeId > >& ids() const;
360 
362  IdSet< ALLOC > conditionalIdSet() const;
363 
365  std::size_t nbLHSIds() const;
366 
368  std::size_t nbRHSIds() const;
369 
371  bool contains(const IdSet< ALLOC >& set) const;
372 
374  void clear();
375 
377  std::size_t size() const;
378 
380 
381  std::size_t pos(const NodeId id) const;
382 
384  bool exists(const NodeId id) const;
385 
387 
389  void erase(const NodeId id);
390 
392  bool hasConditioningSet() const;
393 
395  bool empty() const;
396 
398  std::string toString() const;
399 
401  allocator_type getAllocator() const;
402 
404 
405 
406 #ifndef DOXYGEN_SHOULD_SKIP_THIS
407 
408  private:
411 
413  std::size_t __nb_lhs_ids{std::size_t(0)};
414 
416  IdSetIterator< ALLOC > __end_safe;
417 
418 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
419  };
420 
421 
423  template < template < typename > class ALLOC >
424  std::ostream& operator<<(std::ostream& stream, const IdSet< ALLOC >& idset);
425 
426  } /* namespace learning */
427 
428 
430  template < template < typename > class ALLOC >
431  class HashFunc< learning::IdSet< ALLOC > >
432  : public HashFuncBase< learning::IdSet< ALLOC > > {
433  public:
439  static Size castToSize(const learning::IdSet< ALLOC >& key);
440 
442  virtual Size
443  operator()(const learning::IdSet< ALLOC >& key) const override final;
444  };
445 
446 
447 } /* namespace gum */
448 
449 
450 // always include the template implementation
452 
453 #endif /* GUM_LEARNING_ID_SET_H */
const NodeId * const_pointer
types for STL compliance
Definition: idSet.h:63
IdSetIterator< ALLOC > operator+(const std::size_t i)
Returns a new iterator pointing to i further elements in the IdSet.
bool operator!=(const IdSetIterator< ALLOC > &from) const
Checks whether two iterators point toward different elements.
IdSetIterator< ALLOC > & operator=(const IdSetIterator< ALLOC > &from)
copy operator
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
The iterators for IdSets.
Definition: idSet.h:54
bool operator==(const IdSetIterator< ALLOC > &from) const
Checks whether two iterators point toward the same elements.
virtual ~IdSetIterator()
destructor
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1019
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
Definition: idSet.h:197
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set...
Definition: idSet.h:45
Class template representing hashing function of LpCol.
Definition: hashFunc.h:469
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
NodeId & reference
types for STL compliance
Definition: idSet.h:60
IdSetIterator< ALLOC > & operator+=(const std::size_t i)
Makes the iterator point to i elements further in the IdSet.
NodeId * pointer
types for STL compliance
Definition: idSet.h:62
Template implementation of idSets.
IdSetIterator()
default constructor
NodeId operator*() const
Gives access to the content of the iterator.
const NodeId & const_reference
types for STL compliance
Definition: idSet.h:61
NodeId value_type
types for STL compliance
Definition: idSet.h:59
All hash functions should inherit from this class.
Definition: hashFunc.h:147
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
IdSetIterator< ALLOC > & operator++()
Makes the iterator point to the next element in the IdSet.
std::forward_iterator_tag iterator_category
types for STL compliance
Definition: idSet.h:58
std::size_t pos() const
Returns the position of the iterator in the IdSet.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
std::ptrdiff_t difference_type
types for STL compliance
Definition: idSet.h:64
some utils for topology : NodeId, Edge, Arc and consorts ...