Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ItemInternalMap.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ItemInternalMap.h (C) 2000-2024 */
9/* */
10/* Tableau associatif de ItemInternal. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MESH_ITEMINTERNALMAP_H
13#define ARCANE_MESH_ITEMINTERNALMAP_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/HashTableMap.h"
18#include "arcane/utils/CheckedConvert.h"
19
20#include "arcane/mesh/MeshGlobal.h"
21#include "arcane/core/ItemInternal.h"
22#include "arcane/utils/HashTableMap2.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27// Indique si on utilise la nouvelle implémentation pour ItemInternalMap
28// #define ARCANE_USE_NEW_IMPL_FOR_ITEMINTERNALMAP
29
30namespace Arcane
31{
32class ItemInternal;
33}
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38namespace Arcane::mesh
39{
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
55class ARCANE_MESH_EXPORT ItemInternalMap
56{
57 // Pour accès aux méthodes qui utilisent ItemInternal.
58 friend class DynamicMeshKindInfos;
59
60 private:
61
64 using BaseData = LegacyImpl::Data;
65
66 public:
67
68#ifdef ARCANE_USE_HASHTABLEMAP2_FOR_ITEMINTERNALMAP
69 static constexpr bool UseNewImpl = 1;
70#else
71 static constexpr bool UseNewImpl = 0;
72#endif
73
74 public:
75
77 {
78 friend ItemInternalMap;
79
80 public:
81
82 void setValue(ItemInternal* v)
83 {
84 m_value = v;
85 if (m_legacy_data)
86 m_legacy_data->setValue(v);
87 else
88 m_iter->second = v;
89 }
90 ItemInternal* value() const { return m_value; }
91
92 private:
93
94 explicit LookupData(NewImpl::iterator x)
95 : m_iter(x)
96 , m_value(x->second)
97 {}
98 explicit LookupData(BaseData* d)
99 : m_legacy_data(d)
100 , m_value(d->value())
101 {}
102 NewImpl::iterator m_iter;
103 BaseData* m_legacy_data = nullptr;
104 ItemInternal* m_value;
105 };
106
107 public:
108
109 using Data ARCANE_DEPRECATED_REASON("Y2024: Data type is internal to Arcane") = LegacyImpl::Data;
110
111 public:
112
113 using ValueType = ItemInternal*;
114
115 public:
116
118
119 public:
120
129 bool add(Int64 key, ItemInternal* v)
130 {
131 if constexpr (UseNewImpl)
132 return m_new_impl.insert(std::make_pair(key, v)).second;
133 else
134 return m_impl.add(key, v);
135 }
136
138 void clear()
139 {
140 if constexpr (UseNewImpl)
141 return m_new_impl.clear();
142 else
143 return m_impl.clear();
144 }
145
147 Int32 count() const
148 {
149 if constexpr (UseNewImpl)
150 return CheckedConvert::toInt32(m_new_impl.size());
151 else
152 return m_impl.count();
153 }
154
160 void remove(Int64 key)
161 {
162 if constexpr (UseNewImpl) {
163 auto x = m_new_impl.find(key);
164 if (x == m_new_impl.end())
165 _throwNotFound(key);
166 m_new_impl.erase(x);
167 }
168 else
169 m_impl.remove(key);
170 }
171
173 bool hasKey(Int64 key)
174 {
175 if constexpr (UseNewImpl)
176 return (m_new_impl.find(key) != m_new_impl.end());
177 else
178 return m_impl.hasKey(key);
179 }
180
182 void resize(Int32 new_size, bool use_prime = false)
183 {
184 if constexpr (UseNewImpl) {
185 // Nothing to do
186 }
187 else
188 m_impl.resize(new_size, use_prime);
189 }
190
196 void notifyUniqueIdsChanged();
197
210 template <class Lambda> void
212 {
213 if constexpr (UseNewImpl) {
214 for (auto [key, value] : m_new_impl)
216 }
217 else {
218 ConstArrayView<BaseData*> b = m_impl.buckets();
219 for (Int32 k = 0, n = b.size(); k < n; ++k) {
220 BaseData* nbid = b[k];
221 for (; nbid; nbid = nbid->next()) {
223 }
224 }
225 }
226 }
228 Int32 nbBucket() const
229 {
230 if constexpr (UseNewImpl)
231 return CheckedConvert::toInt32(m_new_impl.bucket_count());
232 else
233 return m_impl.buckets().size();
234 }
235
236 public:
237
239 impl::ItemBase tryFind(Int64 key) const
240 {
241 if constexpr (UseNewImpl) {
242 auto x = m_new_impl.find(key);
243 return (x != m_new_impl.end()) ? x->second : impl::ItemBase{};
244 }
245 else {
246 const BaseData* d = m_impl.lookup(key);
247 return (d ? impl::ItemBase(d->value()) : impl::ItemBase{});
248 }
249 }
251 Int32 tryFindLocalId(Int64 key) const
252 {
253 if constexpr (UseNewImpl) {
254 auto x = m_new_impl.find(key);
255 return (x != m_new_impl.end()) ? x->second->localId() : NULL_ITEM_LOCAL_ID;
256 }
257 else {
258 const BaseData* d = m_impl.lookup(key);
259 return (d ? d->value()->localId() : NULL_ITEM_LOCAL_ID);
260 }
261 }
262
268 impl::ItemBase findItem(Int64 uid) const
269 {
270 if constexpr (UseNewImpl) {
271 auto x = m_new_impl.find(uid);
272 if (x == m_new_impl.end())
273 _throwNotFound(uid);
274 return x->second;
275 }
276 else
277 return impl::ItemBase(m_impl.lookupValue(uid));
278 }
279
285 Int32 findLocalId(Int64 uid) const
286 {
287 if constexpr (UseNewImpl) {
288 auto x = m_new_impl.find(uid);
289 if (x == m_new_impl.end())
290 _throwNotFound(uid);
291 return x->second->localId();
292 }
293 else
294 return m_impl.lookupValue(uid)->localId();
295 }
296
297 void checkValid() const;
298
299 public:
300
301 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
302 Data* lookup(Int64 key)
303 {
304 if constexpr (UseNewImpl) {
305 _throwNotSupported("lookup");
306 }
307 else
308 return m_impl.lookup(key);
309 }
310
311 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
312 const Data* lookup(Int64 key) const
313 {
314 if constexpr (UseNewImpl) {
315 _throwNotSupported("lookup");
316 }
317 else
318 return m_impl.lookup(key);
319 }
320
321 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
322 ConstArrayView<BaseData*> buckets() const
323 {
324 if constexpr (UseNewImpl) {
325 _throwNotSupported("buckets");
326 }
327 else
328 return m_impl.buckets();
329 }
330
331 ARCANE_DEPRECATED_REASON("This method is internal to Arcane")
332 BaseData* lookupAdd(Int64 id, ItemInternal* value, bool& is_add)
333 {
334 if constexpr (UseNewImpl) {
335 _throwNotSupported("lookupAdd(id,value,is_add)");
336 }
337 else
338 return m_impl.lookupAdd(id, value, is_add);
339 }
340
341 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
342 BaseData* lookupAdd(Int64 uid)
343 {
344 if constexpr (UseNewImpl) {
345 _throwNotSupported("lookupAdd(uid)");
346 }
347 else
348 return m_impl.lookupAdd(uid);
349 }
350
351 ARCANE_DEPRECATED_REASON("Y2024: Use findItem() instead")
352 ItemInternal* lookupValue(Int64 uid) const
353 {
354 if constexpr (UseNewImpl) {
355 _throwNotSupported("lookupValue");
356 }
357 else
358 return m_impl.lookupValue(uid);
359 }
360
361 ARCANE_DEPRECATED_REASON("Y2024: Use findItem() instead")
362 ItemInternal* operator[](Int64 uid) const
363 {
364 if constexpr (UseNewImpl) {
365 _throwNotSupported("operator[]");
366 }
367 else
368 return m_impl.lookupValue(uid);
369 }
370
371 private:
372
373 NewImpl m_new_impl;
374 LegacyImpl m_impl;
375
376 private:
377
378 // Les trois méthodes suivantes sont uniquement pour la
379 // classe DynamicMeshKindInfos.
380
382 void _changeLocalIds(ArrayView<ItemInternal*> items_internal,
383 ConstArrayView<Int32> old_to_new_local_ids);
384
385 LookupData _lookupAdd(Int64 id, ItemInternal* value, bool& is_add)
386 {
387 if constexpr (UseNewImpl) {
388 auto x = m_new_impl.insert(std::make_pair(id, value));
389 is_add = x.second;
390 return LookupData(x.first);
391 }
392 else
393 return LookupData(m_impl.lookupAdd(id, value, is_add));
394 }
395
398 {
399 if constexpr (UseNewImpl) {
400 auto x = m_new_impl.find(key);
401 if (x == m_new_impl.end())
402 return nullptr;
403 _checkValid(key, x->second);
404 return x->second;
405 }
406 else {
407 const BaseData* d = m_impl.lookup(key);
408 return (d ? d->value() : nullptr);
409 }
410 }
411
412 private:
413
414 void _throwNotFound ARCANE_NORETURN(Int64 id) const;
415 void _throwNotSupported ARCANE_NORETURN(const char* func_name) const;
416 void _checkValid(Int64 uid, ItemInternal* v) const;
417};
418
419/*---------------------------------------------------------------------------*/
420/*---------------------------------------------------------------------------*/
421
427#define ENUMERATE_ITEM_INTERNAL_MAP_DATA(iter,item_list) \
428for( auto __i__##iter : item_list .buckets() ) \
429 for (auto* iter = __i__##iter; iter; iter = iter->next())
430
431/*---------------------------------------------------------------------------*/
432/*---------------------------------------------------------------------------*/
433
434}
435
436/*---------------------------------------------------------------------------*/
437/*---------------------------------------------------------------------------*/
438
439#endif
Classe de base pour les entités du maillage.
Structure interne d'une entité de maillage.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Infos de maillage pour un genre donné d'entité.
Tableau associatif de ItemInternal.
void remove(Int64 key)
Supprime la valeur associée à la clé key.
impl::ItemBase findItem(Int64 uid) const
Retourne l'entité de numéro unique uid.
void eachItem(const Lambda &lambda)
Fonction template pour itérer sur les entités de l'instance.
bool hasKey(Int64 key)
true si une valeur avec la clé id est présente
Int32 nbBucket() const
Nombre de buckets.
void resize(Int32 new_size, bool use_prime=false)
Redimensionne la table de hachage.
bool add(Int64 key, ItemInternal *v)
Ajoute la valeur v correspondant à la clé key.
impl::ItemBase tryFind(Int64 key) const
Retourne l'entité associée à key si trouvé ou l'entité nulle sinon.
Int32 tryFindLocalId(Int64 key) const
Retourne le localId() associé à key si trouvé ou NULL_ITEM_LOCAL_ID sinon aucun.
Int32 findLocalId(Int64 uid) const
Retourne le numéro local de l'entité de numéro unique uid.
Int32 count() const
Nombre d'éléments de la table.
ItemInternal * _tryFindItemInternal(Int64 key) const
Retourne l'entité associée à key si trouvé ou nullptr sinon.
void clear()
Supprime tous les éléments de la table.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-