aGrUM  0.16.0
scoringCache_tpl.h
Go to the documentation of this file.
1 
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 
30 namespace gum {
31 
32  namespace learning {
33 
34 
36  template < template < typename > class ALLOC >
39  return *this;
40  }
41 
42 
44  template < template < typename > class ALLOC >
46  const typename ScoringCache< ALLOC >::allocator_type& alloc) :
47  ALLOC< NodeId >(alloc) {
48  GUM_CONSTRUCTOR(ScoringCache);
49  }
50 
51 
53  template < template < typename > class ALLOC >
55  const ScoringCache< ALLOC >& from,
56  const typename ScoringCache< ALLOC >::allocator_type& alloc) :
57  ALLOC< NodeId >(alloc),
58  __scores(from.__scores) {
59  GUM_CONS_CPY(ScoringCache);
60  }
61 
62 
64  template < template < typename > class ALLOC >
65  INLINE ScoringCache< ALLOC >::ScoringCache(const ScoringCache< ALLOC >& from) :
66  ScoringCache< ALLOC >(from, from.getAllocator()) {}
67 
68 
70  template < template < typename > class ALLOC >
72  ScoringCache< ALLOC >&& from,
73  const typename ScoringCache< ALLOC >::allocator_type& alloc) :
74  ALLOC< NodeId >(alloc),
75  __scores(std::move(from.__scores)) {
76  GUM_CONS_MOV(ScoringCache);
77  }
78 
79 
81  template < template < typename > class ALLOC >
82  INLINE ScoringCache< ALLOC >::ScoringCache(ScoringCache< ALLOC >&& from) :
83  ScoringCache< ALLOC >(std::move(from), from.getAllocator()) {}
84 
85 
87  template < template < typename > class ALLOC >
88  ScoringCache< ALLOC >* ScoringCache< ALLOC >::clone(
89  const typename ScoringCache< ALLOC >::allocator_type& alloc) const {
90  ALLOC< ScoringCache< ALLOC > > allocator(alloc);
91  ScoringCache< ALLOC >* cache = allocator.allocate(1);
92  try {
93  allocator.construct(cache, *this, alloc);
94  } catch (...) {
95  allocator.deallocate(cache, 1);
96  throw;
97  }
98  return cache;
99  }
100 
101 
103  template < template < typename > class ALLOC >
104  ScoringCache< ALLOC >* ScoringCache< ALLOC >::clone() const {
105  return clone(this->getAllocator());
106  }
107 
108 
110  template < template < typename > class ALLOC >
112  GUM_DESTRUCTOR(ScoringCache);
113  }
114 
115 
117  template < template < typename > class ALLOC >
118  INLINE ScoringCache< ALLOC >& ScoringCache< ALLOC >::
119  operator=(const ScoringCache< ALLOC >& from) {
120  if (&from != this) { __scores = from.__scores; }
121  return *this;
122  }
123 
124 
126  template < template < typename > class ALLOC >
127  INLINE ScoringCache< ALLOC >& ScoringCache< ALLOC >::
128  operator=(ScoringCache< ALLOC >&& from) {
129  if (&from != this) { __scores = std::move(from.__scores); }
130  return *this;
131  }
132 
133 
135  template < template < typename > class ALLOC >
136  INLINE void ScoringCache< ALLOC >::insert(const IdSet< ALLOC >& idset,
137  double score) {
138  __scores.insert(idset, score);
139  }
140 
141 
143  template < template < typename > class ALLOC >
144  INLINE void ScoringCache< ALLOC >::insert(IdSet< ALLOC >&& idset,
145  double score) {
146  __scores.insert(std::move(idset), std::move(score));
147  }
148 
149 
151  template < template < typename > class ALLOC >
152  INLINE void ScoringCache< ALLOC >::erase(const IdSet< ALLOC >& idset) {
153  __scores.erase(idset);
154  }
155 
156 
158  template < template < typename > class ALLOC >
159  INLINE bool ScoringCache< ALLOC >::exists(const IdSet< ALLOC >& idset) {
160  return __scores.exists(idset);
161  }
162 
163 
165  template < template < typename > class ALLOC >
166  INLINE double ScoringCache< ALLOC >::score(const IdSet< ALLOC >& idset) {
167  return __scores[idset];
168  }
169 
170 
172  template < template < typename > class ALLOC >
173  INLINE void ScoringCache< ALLOC >::clear() {
174  __scores.clear();
175  }
176 
177 
179  template < template < typename > class ALLOC >
180  INLINE std::size_t ScoringCache< ALLOC >::size() const {
181  return __scores.size();
182  }
183 
184 
185  } /* namespace learning */
186 
187 } /* namespace gum */
188 
189 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
virtual ~ScoringCache()
destructor
STL namespace.
void erase(const IdSet< ALLOC > &idset)
removes a score (if it exists)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
std::size_t size() const
returns the number of scores saved in the cache
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
Definition: scoringCache.h:63
void clear()
removes all the stored scores
double score(const IdSet< ALLOC > &idset)
returns a given score
ScoringCache< ALLOC > & operator=(const ScoringCache< ALLOC > &from)
copy operator
void insert(const IdSet< ALLOC > &idset, double score)
insert a new score into the cache
ScoringCache(const allocator_type &alloc=allocator_type())
default constructor
virtual ScoringCache< ALLOC > * clone() const
virtual copy constructor
allocator_type getAllocator() const
returns the allocator used by the translator
bool exists(const IdSet< ALLOC > &idset)
indicates whether a given score exists
Size NodeId
Type for node ids.
Definition: graphElements.h:98