Arcane  v4.1.0.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-2025 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
157 void resize([[maybe_unused]] Int32 new_size, [[maybe_unused]] bool use_prime = false)
158 {
159 }
160
166 void notifyUniqueIdsChanged();
167
180 template <class Lambda> void
181 eachItem(const Lambda& lambda)
182 {
183 for (auto [key, value] : m_new_impl)
184 lambda(Arcane::impl::ItemBase(value));
185 }
186
188 {
189 return CheckedConvert::toInt32(m_new_impl.bucket_count());
190 }
191
192 public:
193
195 impl::ItemBase tryFind(Int64 key) const
196 {
197 auto x = m_new_impl.find(key);
198 return (x != m_new_impl.end()) ? x->second : impl::ItemBase{};
199 }
200
202 {
203 auto x = m_new_impl.find(key);
204 return (x != m_new_impl.end()) ? x->second->localId() : NULL_ITEM_LOCAL_ID;
205 }
206
212 impl::ItemBase findItem(Int64 uid) const
213 {
214 auto x = m_new_impl.find(uid);
215 if (x == m_new_impl.end())
216 _throwNotFound(uid);
217 return x->second;
218 }
219
226 {
227 auto x = m_new_impl.find(uid);
228 if (x == m_new_impl.end())
229 _throwNotFound(uid);
230 return x->second->localId();
231 }
232
233 void checkValid() const;
234
235 public:
236
237 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
238 Data* lookup([[maybe_unused]] Int64 key)
239 {
240 _throwNotSupported("lookup");
241 }
242
243 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
244 const Data* lookup([[maybe_unused]] Int64 key) const
245 {
246 _throwNotSupported("lookup");
247 }
248
249 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
250 ConstArrayView<BaseData*> buckets() const
251 {
252 _throwNotSupported("buckets");
253 }
254
255 ARCANE_DEPRECATED_REASON("This method is internal to Arcane")
256 BaseData* lookupAdd([[maybe_unused]] Int64 id,
257 [[maybe_unused]] ItemInternal* value,
258 [[maybe_unused]] bool& is_add)
259 {
260 _throwNotSupported("lookupAdd(id,value,is_add)");
261 }
262
263 ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
264 BaseData* lookupAdd([[maybe_unused]] Int64 uid)
265 {
266 _throwNotSupported("lookupAdd(uid)");
267 }
268
269 ARCANE_DEPRECATED_REASON("Y2024: Use findItem() instead")
270 ItemInternal* lookupValue([[maybe_unused]] Int64 uid) const
271 {
272 _throwNotSupported("lookupValue");
273 }
274
275 ARCANE_DEPRECATED_REASON("Y2024: Use findItem() instead")
276 ItemInternal* operator[]([[maybe_unused]] Int64 uid) const
277 {
278 _throwNotSupported("operator[]");
279 }
280
281 private:
282
283 NewImpl m_new_impl;
284
285 private:
286
287 // Les trois méthodes suivantes sont uniquement pour la
288 // classe DynamicMeshKindInfos.
289
291 void _changeLocalIds(ArrayView<ItemInternal*> items_internal,
292 ConstArrayView<Int32> old_to_new_local_ids);
293
294 LookupData _lookupAdd(Int64 id, ItemInternal* value, bool& is_add)
295 {
296 auto x = m_new_impl.insert(std::make_pair(id, value));
297 is_add = x.second;
298 return LookupData(x.first);
299 }
300
303 {
304 auto x = m_new_impl.find(key);
305 if (x == m_new_impl.end())
306 return nullptr;
307 _checkValid(key, x->second);
308 return x->second;
309 }
310
311 private:
312
313 void _throwNotFound ARCANE_NORETURN(Int64 id) const;
314 void _throwNotSupported ARCANE_NORETURN(const char* func_name) const;
315 void _checkValid(Int64 uid, ItemInternal* v) const;
316};
317
318/*---------------------------------------------------------------------------*/
319/*---------------------------------------------------------------------------*/
320}
321
322/*---------------------------------------------------------------------------*/
323/*---------------------------------------------------------------------------*/
324
325#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)
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 -*-
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.