Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
GroupIndexTable.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/* GroupIndexTable.h (C) 2000-2024 */
9/* */
10/* Hash table between an item and its position in the 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;
35 typedef HashTraitsT<KeyTypeValue> KeyTraitsType;
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/*---------------------------------------------------------------------------*/
73
83class ARCANE_CORE_EXPORT GroupIndexTable
84: public HashTableBase
85{
86 public:
87
88 typedef Int32 KeyTypeValue;
89 typedef Int32 ValueType;
90 typedef HashTraitsT<KeyTypeValue> KeyTraitsType;
91 typedef KeyTraitsType::KeyTypeConstRef KeyTypeConstRef;
92
93 public:
94
95 explicit GroupIndexTable(ItemGroupImpl* group_impl);
96
97 public:
98
99 void update();
100
101 void clear();
102
103 void compact(const Int32ConstArrayView* info);
104
105 ValueType operator[](Int32 i) const { return _lookup(i); }
106
107 KeyTypeValue keyLocalId(Int32 i) const { return m_key_buffer[i]; }
108
109 Int32 size() const { return m_key_buffer.size(); }
110
111 GroupIndexTableView view() const
112 {
113 ARCANE_ASSERT((_initialized()), ("GroupIndexTable not initialized"));
114 ARCANE_ASSERT((_checkIntegrity(false)), ("GroupIndexTable integrity failed"));
115 return m_view;
116 }
117
118 private:
119
126 Int32 _hash(KeyTypeConstRef id) const
127 {
128 ARCANE_ASSERT((_initialized()), ("GroupIndexTable not initialized"));
129 return m_view._hash(id);
130 }
131
132 bool _hasKey(KeyTypeConstRef id) const;
133
135 Int32 _lookupBucket(Int32 bucket, KeyTypeConstRef id) const
136 {
137 ARCANE_ASSERT((_initialized()), ("GroupIndexTable not initialized"));
138 return m_view._lookupBucket(bucket, id);
139 }
140
142 Int32 _lookup(KeyTypeConstRef id) const
143 {
144 ARCANE_ASSERT((_checkIntegrity(false)), ("GroupIndexTable integrity failed"));
145 return _lookupBucket(_hash(id), id);
146 }
147
149 bool _initialized() const;
150
152 bool _checkIntegrity(bool full = true) const;
153
154 private:
155
156 ItemGroupImpl* m_group_impl = nullptr;
157 UniqueArray<KeyTypeValue> m_key_buffer;
161 GroupIndexTableView m_view;
162
163 private:
164
165 void _updateSpan();
166};
167
168/*---------------------------------------------------------------------------*/
169/*---------------------------------------------------------------------------*/
170
171} // namespace Arcane
172
173/*---------------------------------------------------------------------------*/
174/*---------------------------------------------------------------------------*/
175
176#endif
__host__ __device__ Int32 _lookup(KeyTypeConstRef id) const
Search for a key in the entire table.
bool m_disable_check_integrity
Bucket array.
UniqueArray< Int32 > m_buckets
Associated next index table.
Int32 _hash(KeyTypeConstRef id) const
Hashing function.
bool _checkIntegrity(bool full=true) const
Tests the integrity of the table relative to its group.
UniqueArray< Int32 > m_next_buffer
Associated keys table.
Int32 _lookupBucket(Int32 bucket, KeyTypeConstRef id) const
Search for a key in a bucket.
Int32 _lookup(KeyTypeConstRef id) const
Search for a key in the entire table.
bool _initialized() const
Tests the initialization of the object.
HashTableBase(Integer table_size, bool use_prime)
Creates a table of size table_size.
Definition HashTable.h:46
Brief: Implementation of a mesh entity group.
View of an array of elements of type T.
Definition Span.h:805
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
std::int32_t Int32
Signed integer type of 32 bits.