12#ifndef ARCANE_UTILS_HASHTABLE_H
13#define ARCANE_UTILS_HASHTABLE_H
17#include "arcane/utils/MultiBuffer.h"
18#include "arcane/utils/Array.h"
19#include "arcane/utils/HashFunction.h"
60 Integer nearestPrimeNumber(Integer n);
72 void _throwNotFound ARCANE_NORETURN()
const;
98template <
typename KeyType,
typename TraitsType>
104 typedef typename TraitsType::KeyTypeConstRef KeyTypeConstRef;
105 typedef typename TraitsType::KeyTypeValue KeyTypeValue;
160 KeyType hf = _hash(
id);
161 for (
HashData* i = m_buckets[hf]; i; i = i->m_next) {
179 if (new_table_size == 0) {
187 m_buckets.resize(new_table_size);
189 for (
Integer z = 0, zs = old_buckets.
size(); z < zs; ++z) {
190 for (
HashData* i = old_buckets[z]; i; i = i->m_next) {
191 _baseAdd(_hash(i->m_key), i->m_key, i);
203 for (
Integer z = 0, zs = old_buckets.
size(); z < zs; ++z) {
204 for (
HashData* i = old_buckets[z]; i;) {
207 _baseAdd(_hash(current->
m_key), current->
m_key, current);
214 inline Integer _hash(KeyTypeConstRef
id)
const
218 inline HashData* _baseLookupBucket(
Integer bucket, KeyTypeConstRef
id)
const
220 for (HashData* i = m_buckets[bucket]; i; i = i->m_next) {
230 if (i->m_key ==
id) {
231 m_buckets[bucket] = i->m_next;
235 for (; i->m_next; i = i->m_next) {
236 if (i->m_next->m_key ==
id) {
238 i->m_next = i->m_next->m_next;
246 inline HashData* _baseLookup(KeyTypeConstRef
id)
const
248 return _baseLookupBucket(_hash(
id),
id);
250 inline HashData* _baseRemove(KeyTypeConstRef
id)
252 return _baseRemoveBucket(_hash(
id),
id);
259 m_buckets[bucket] = hd;
265 UniqueArray<HashData*> m_buckets;
Integer size() const
Number of elements in the vector.
void rehash()
Repositions data after key value change.
HashTableBaseT(Integer table_size, bool use_prime)
Creates a table of size table_size.
void resize(Integer new_table_size, bool use_prime=false)
Resizes the hash table.
bool hasKey(KeyTypeConstRef id) const
true if a value with the key id is present
void clear()
Clears all elements from the table.
HashTableBase(Integer table_size, bool use_prime)
Creates a table of size table_size.
Integer m_nb_bucket
Number of buckets.
Integer nearestPrimeNumber(Integer n)
Returns the nearest prime number greater than n. The nearest prime number greater than n is returned ...
Integer m_count
Number of elements.
Integer count() const
Number of elements in the table.
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
void changeKey(const KeyType &new_key)
Changes the key value.
KeyTypeValue m_key
Search key.