Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
GroupIndexTable.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/* GroupIndexTable.h (C) 2000-2024 */
9/* */
10/* Table de hachage entre un item et sa position dans la table. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_GROUPINDEXTABLE_H
13#define ARCANE_CORE_GROUPINDEXTABLE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/HashTable.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25class ItemGroupImpl;
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30class ARCANE_CORE_EXPORT GroupIndexTableView
31{
32 friend class GroupIndexTable;
33 typedef Int32 KeyTypeValue;
34 typedef Int32 ValueType;
36 typedef KeyTraitsType::KeyTypeConstRef KeyTypeConstRef;
37
38 public:
39
40 ARCCORE_HOST_DEVICE ValueType operator[](Int32 i) const { return _lookup(i); }
41 ARCCORE_HOST_DEVICE Int32 size() const { return m_key_buffer_span.size(); }
42
43 private:
44
45 SmallSpan<const KeyTypeValue> m_key_buffer_span;
46 SmallSpan<const Int32> m_next_buffer_span;
47 SmallSpan<const Int32> m_buckets_span;
48 Int32 m_nb_bucket = 0;
49
50 private:
51
53 ARCCORE_HOST_DEVICE Int32 _lookup(KeyTypeConstRef id) const
54 {
55 return _lookupBucket(_hash(id), id);
56 }
57 ARCCORE_HOST_DEVICE Int32 _hash(KeyTypeConstRef id) const
58 {
59 return static_cast<Int32>(KeyTraitsType::hashFunction(id) % m_nb_bucket);
60 }
61 ARCCORE_HOST_DEVICE Integer _lookupBucket(Int32 bucket, KeyTypeConstRef id) const
62 {
63 for (Integer i = m_buckets_span[bucket]; i >= 0; i = m_next_buffer_span[i]) {
64 if (m_key_buffer_span[i] == id)
65 return i;
66 }
67 return -1;
68 }
69};
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
82class ARCANE_CORE_EXPORT GroupIndexTable
83: public HashTableBase
84{
85 public:
86
87 typedef Int32 KeyTypeValue;
88 typedef Int32 ValueType;
91
92 public:
93
95
96 public:
97
98 void update();
99
100 void clear();
101
102 void compact(const Int32ConstArrayView* info);
103
104 ValueType operator[](Int32 i) const { return _lookup(i); }
105
106 KeyTypeValue keyLocalId(Int32 i) const { return m_key_buffer[i]; }
107
108 Int32 size() const { return m_key_buffer.size(); }
109
110 GroupIndexTableView view() const
111 {
112 ARCANE_ASSERT((_initialized()), ("GroupIndexTable not initialized"));
113 ARCANE_ASSERT((_checkIntegrity(false)), ("GroupIndexTable integrity failed"));
114 return m_view;
115 }
116
117 private:
118
125 Int32 _hash(KeyTypeConstRef id) const
126 {
127 ARCANE_ASSERT((_initialized()), ("GroupIndexTable not initialized"));
128 return m_view._hash(id);
129 }
131 bool _hasKey(KeyTypeConstRef id) const;
132
134 Int32 _lookupBucket(Int32 bucket, KeyTypeConstRef id) const
135 {
136 ARCANE_ASSERT((_initialized()), ("GroupIndexTable not initialized"));
137 return m_view._lookupBucket(bucket, id);
138 }
139
141 Int32 _lookup(KeyTypeConstRef id) const
142 {
143 ARCANE_ASSERT((_checkIntegrity(false)), ("GroupIndexTable integrity failed"));
144 return _lookupBucket(_hash(id), id);
145 }
146
148 bool _initialized() const;
149
151 bool _checkIntegrity(bool full = true) const;
152
153 private:
154
155 ItemGroupImpl* m_group_impl = nullptr;
156 UniqueArray<KeyTypeValue> m_key_buffer;
159 bool m_disable_check_integrity = false;
160 GroupIndexTableView m_view;
161
162 private:
163
164 void _updateSpan();
165};
166
167/*---------------------------------------------------------------------------*/
168/*---------------------------------------------------------------------------*/
169
170} // namespace Arcane
171
172/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174
175#endif
ARCCORE_HOST_DEVICE Int32 _lookup(KeyTypeConstRef id) const
Recherche d'une clef dans toute la table.
Classe de base d'une table de hachage entre les items d'un groupe et leurs positions dans la table.
UniqueArray< Int32 > m_buckets
Table des index suivant associés.
Int32 _hash(KeyTypeConstRef id) const
Fonction de hachage.
UniqueArray< Int32 > m_next_buffer
Table des clés associées.
Int32 _lookupBucket(Int32 bucket, KeyTypeConstRef id) const
Recherche d'une clef dans un bucket.
Int32 _lookup(KeyTypeConstRef id) const
Recherche d'une clef dans toute la table.
Classe de base d'une table de hachage simple pour les entités.
Definition HashTable.h:37
Implémentation d'un groupe d'entités de maillage.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Vue constante d'un tableau de type T.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-