Arcane  4.2.3.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-2026 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-2025 */
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
27namespace Arcane
28{
29class ItemInternal;
30}
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35namespace Arcane::mesh
36{
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
52class ARCANE_MESH_EXPORT ItemInternalMap
53{
54 // Pour accès aux méthodes qui utilisent ItemInternal.
55 friend class DynamicMeshKindInfos;
56
57 private:
58
59 using LegacyImpl = HashTableMapT<Int64, ItemInternal*>;
61 using BaseData = LegacyImpl::Data;
62
63 public:
64
65 static constexpr bool UseNewImpl = 1;
66
67 class LookupData
68 {
69 friend ItemInternalMap;
70
71 public:
72
73 void setValue(ItemInternal* v)
74 {
75 m_value = v;
76 if (m_legacy_data)
77 m_legacy_data->setValue(v);
78 else
79 m_iter->second = v;
80 }
81 ItemInternal* value() const { return m_value; }
82
83 private:
84
85 explicit LookupData(NewImpl::iterator x)
86 : m_iter(x)
87 , m_value(x->second)
88 {}
89 explicit LookupData(BaseData* d)
90 : m_legacy_data(d)
91 , m_value(d->value())
92 {}
93 NewImpl::iterator m_iter;
94 BaseData* m_legacy_data = nullptr;
95 ItemInternal* m_value;
96 };
97
98 public:
99
100 using Data ARCANE_DEPRECATED_REASON("Y2024: Data type is internal to Arcane") = LegacyImpl::Data;
101
102 public:
103
104 using ValueType = ItemInternal*;
105
106 public:
107
108 ItemInternalMap();
109
110 public:
111
120 bool add(Int64 key, ItemInternal* v)
121 {
122 return m_new_impl.insert(std::make_pair(key, v)).second;
123 }
124
126 void clear()
127 {
128 return m_new_impl.clear();
129 }
130
132 Int32 count() const
133 {
134 return CheckedConvert::toInt32(m_new_impl.size());
135 }
136
142 void remove(Int64 key)
143 {
144 auto x = m_new_impl.find(key);
145 if (x == m_new_impl.end())
146 _throwNotFound(key);
147 m_new_impl.erase(x);
148 }
149
151 bool hasKey(Int64 key)
152 {
153 return (m_new_impl.find(key) != m_new_impl.end());
154 }
155
164 void resize(Int32 new_size, [[maybe_unused]] bool use_prime = false)
165 {
166 if (new_size > 0)
167 m_new_impl.reserve(static_cast<uint64_t>(new_size), false);
168 }
169
175 void notifyUniqueIdsChanged();
176
189 template <class Lambda> void
190 eachItem(const Lambda& lambda)
191 {
192 for (auto [key, value] : m_new_impl)
193 lambda(Arcane::impl::ItemBase(value));
194 }
195
197 {
198 return CheckedConvert::toInt32(m_new_impl.bucket_count());
199 }
200
201 public:
202
204 impl::ItemBase tryFind(Int64 key) const
205 {
206 auto x = m_new_impl.find(key);
207 return (x != m_new_impl.end()) ? x->second : impl::ItemBase{};
208 }
209
211 {
212 auto x = m_new_impl.find(key);
213 return (x != m_new_impl.end()) ? x->second->localId() : NULL_ITEM_LOCAL_ID;
214 }
215
221 impl::ItemBase findItem(Int64 uid) const
222 {
223 auto x = m_new_impl.find(uid);
224 if (x == m_new_impl.end())
225 _throwNotFound(uid);
226 return x->second;
227 }
228
235 {
236 auto x = m_new_impl.find(uid);
237 if (x == m_new_impl.end())
238 _throwNotFound(uid);
239 return x->second->localId();
240 }
241
242 void checkValid() const;
243
244 public:
245
246 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
247 Data* lookup([[maybe_unused]] Int64 key)
248 {
249 _throwNotSupported("lookup");
250 }
251
252 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
253 const Data* lookup([[maybe_unused]] Int64 key) const
254 {
255 _throwNotSupported("lookup");
256 }
257
258 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
259 ConstArrayView<BaseData*> buckets() const
260 {
261 _throwNotSupported("buckets");
262 }
263
264 ARCANE_DEPRECATED_REASON("This method is internal to Arcane")
265 BaseData* lookupAdd([[maybe_unused]] Int64 id,
266 [[maybe_unused]] ItemInternal* value,
267 [[maybe_unused]] bool& is_add)
268 {
269 _throwNotSupported("lookupAdd(id,value,is_add)");
270 }
271
272 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
273 BaseData* lookupAdd([[maybe_unused]] Int64 uid)
274 {
275 _throwNotSupported("lookupAdd(uid)");
276 }
277
278 ARCANE_DEPRECATED_REASON("Y2024: Use findItem() instead")
279 ItemInternal* lookupValue([[maybe_unused]] Int64 uid) const
280 {
281 _throwNotSupported("lookupValue");
282 }
283
284 ARCANE_DEPRECATED_REASON("Y2024: Use findItem() instead")
285 ItemInternal* operator[]([[maybe_unused]] Int64 uid) const
286 {
287 _throwNotSupported("operator[]");
288 }
289
290 private:
291
292 NewImpl m_new_impl;
293
294 private:
295
296 // Les trois méthodes suivantes sont uniquement pour la
297 // classe DynamicMeshKindInfos.
298
300 void _changeLocalIds(ArrayView<ItemInternal*> items_internal,
301 ConstArrayView<Int32> old_to_new_local_ids);
302
303 LookupData _lookupAdd(Int64 id, ItemInternal* value, bool& is_add)
304 {
305 auto x = m_new_impl.insert(std::make_pair(id, value));
306 is_add = x.second;
307 return LookupData(x.first);
308 }
309
312 {
313 auto x = m_new_impl.find(key);
314 if (x == m_new_impl.end())
315 return nullptr;
316 _checkValid(key, x->second);
317 return x->second;
318 }
319
320 private:
321
322 void _throwNotFound ARCANE_NORETURN(Int64 id) const;
323 void _throwNotSupported ARCANE_NORETURN(const char* func_name) const;
324 void _checkValid(Int64 uid, ItemInternal* v) const;
325};
326
327/*---------------------------------------------------------------------------*/
328/*---------------------------------------------------------------------------*/
329}
330
331/*---------------------------------------------------------------------------*/
332/*---------------------------------------------------------------------------*/
333
334#endif
Table de hachage pour tableaux associatifs.
Structure interne d'une entité de maillage.
Implementation of std::unordered_map.
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)
Fait de la place pour new_size entités.
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 --
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.