aGrUM  0.14.2
scoringCache_tpl.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 DOXYGEN_SHOULD_SKIP_THIS
26 
27 namespace gum {
28 
29  namespace learning {
30 
31 
33  template < template < typename > class ALLOC >
36  return *this;
37  }
38 
39 
41  template < template < typename > class ALLOC >
43  const typename ScoringCache< ALLOC >::allocator_type& alloc) :
44  ALLOC< NodeId >(alloc) {
45  GUM_CONSTRUCTOR(ScoringCache);
46  }
47 
48 
50  template < template < typename > class ALLOC >
52  const ScoringCache< ALLOC >& from,
53  const typename ScoringCache< ALLOC >::allocator_type& alloc) :
54  ALLOC< NodeId >(alloc),
55  __scores(from.__scores) {
56  GUM_CONS_CPY(ScoringCache);
57  }
58 
59 
61  template < template < typename > class ALLOC >
62  INLINE ScoringCache< ALLOC >::ScoringCache(const ScoringCache< ALLOC >& from) :
63  ScoringCache< ALLOC >(from, from.getAllocator()) {}
64 
65 
67  template < template < typename > class ALLOC >
69  ScoringCache< ALLOC >&& from,
70  const typename ScoringCache< ALLOC >::allocator_type& alloc) :
71  ALLOC< NodeId >(alloc),
72  __scores(std::move(from.__scores)) {
73  GUM_CONS_MOV(ScoringCache);
74  }
75 
76 
78  template < template < typename > class ALLOC >
79  INLINE ScoringCache< ALLOC >::ScoringCache(ScoringCache< ALLOC >&& from) :
80  ScoringCache< ALLOC >(std::move(from), from.getAllocator()) {}
81 
82 
84  template < template < typename > class ALLOC >
85  ScoringCache< ALLOC >* ScoringCache< ALLOC >::clone(
86  const typename ScoringCache< ALLOC >::allocator_type& alloc) const {
87  ALLOC< ScoringCache< ALLOC > > allocator(alloc);
88  ScoringCache< ALLOC >* cache = allocator.allocate(1);
89  try {
90  allocator.construct(cache, *this, alloc);
91  } catch (...) {
92  allocator.deallocate(cache, 1);
93  throw;
94  }
95  return cache;
96  }
97 
98 
100  template < template < typename > class ALLOC >
101  ScoringCache< ALLOC >* ScoringCache< ALLOC >::clone() const {
102  return clone(this->getAllocator());
103  }
104 
105 
107  template < template < typename > class ALLOC >
109  GUM_DESTRUCTOR(ScoringCache);
110  }
111 
112 
114  template < template < typename > class ALLOC >
115  INLINE ScoringCache< ALLOC >& ScoringCache< ALLOC >::
116  operator=(const ScoringCache< ALLOC >& from) {
117  if (&from != this) { __scores = from.__scores; }
118  return *this;
119  }
120 
121 
123  template < template < typename > class ALLOC >
124  INLINE ScoringCache< ALLOC >& ScoringCache< ALLOC >::
125  operator=(ScoringCache< ALLOC >&& from) {
126  if (&from != this) { __scores = std::move(from.__scores); }
127  return *this;
128  }
129 
130 
132  template < template < typename > class ALLOC >
133  INLINE void ScoringCache< ALLOC >::insert(const IdSet< ALLOC >& idset,
134  double score) {
135  __scores.insert(idset, score);
136  }
137 
138 
140  template < template < typename > class ALLOC >
141  INLINE void ScoringCache< ALLOC >::insert(IdSet< ALLOC >&& idset,
142  double score) {
143  __scores.insert(std::move(idset), std::move(score));
144  }
145 
146 
148  template < template < typename > class ALLOC >
149  INLINE void ScoringCache< ALLOC >::erase(const IdSet< ALLOC >& idset) {
150  __scores.erase(idset);
151  }
152 
153 
155  template < template < typename > class ALLOC >
156  INLINE bool ScoringCache< ALLOC >::exists(const IdSet< ALLOC >& idset) {
157  return __scores.exists(idset);
158  }
159 
160 
162  template < template < typename > class ALLOC >
163  INLINE double ScoringCache< ALLOC >::score(const IdSet< ALLOC >& idset) {
164  return __scores[idset];
165  }
166 
167 
169  template < template < typename > class ALLOC >
170  INLINE void ScoringCache< ALLOC >::clear() {
171  __scores.clear();
172  }
173 
174 
176  template < template < typename > class ALLOC >
177  INLINE std::size_t ScoringCache< ALLOC >::size() const {
178  return __scores.size();
179  }
180 
181 
182  } /* namespace learning */
183 
184 } /* namespace gum */
185 
186 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
virtual ~ScoringCache()
destructor
STL namespace.
void erase(const IdSet< ALLOC > &idset)
removes a score (if it exists)
gum is the global namespace for all aGrUM entities
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:60
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:97