Aleph-w  1.9
General library for algorithms and data structures
Aleph::GenLhashTable< Key, BucketType, Cmp > Class Template Reference

#include <tpl_lhash.H>

Inherits HashStats< HashTbl >.

Classes

class  Iterator
 

Public Types

using Bucket = BucketType
 
using Hash_Fct = std::function< size_t(const Key &)>
 
using Hash_Fct_Ptr = size_t(*)(const Key &)
 
using Key_Type = Key
 
using Item_Type = Key
 

Public Member Functions

Cmp & get_compare ()
 
const Cmp & get_compare () const
 
 GenLhashTable (size_t table_size=Primes::DefaultPrime, Hash_Fct_Ptr hash_fct=Aleph::dft_hash_fct< Key >, Cmp cmp=Cmp(), float lower_alpha=hash_default_lower_alpha, float upper_alpha=hash_default_upper_alpha, bool remove_all_buckets=true, bool with_resize=true)
 
void swap (GenLhashTable &other) noexcept
 
void empty () noexcept
 Vacía la tabla hash; libera memoria de todas las cubetas.
 
Hash_Fct get_hash_fct () const noexcept
 
void set_hash_fct (Hash_Fct fct) noexcept
 Set the internal hash function.
 
void set_hash_fct (Hash_Fct_Ptr fct) noexcept
 
float current_alpha () const noexcept
 return the current table load
 
Bucket * insert (Bucket *bucket)
 
Bucket * search_or_insert (Bucket *bucket)
 
Bucket * search (const Key &key) const noexcept
 
Bucket * remove (Bucket *bucket) noexcept
 
size_t resize (size_t new_size)
 
virtual ~GenLhashTable ()
 
Bucket * search_next (Bucket *bucket) const noexcept
 
const size_t & capacity () const noexcept
 Retorna el tamaño de la tabla.
 
const size_t & size () const noexcept
 Retorna el número de elementos que contiene la tabla.
 
const size_t & get_num_busy_slots () const noexcept
 Retorna la cantidad de entradas del arreglo que están ocupadas.
 
bool is_empty () const noexcept
 
Stats stats () const
 
void print_stats (const Stats &stats) const
 
void set_upper_alpha (const float &__upper_alpha)
 
void set_lower_alpha (const float &__lower_alpha)
 
float get_lower_alpha () const noexcept
 
float get_upper_alpha () const noexcept
 

Protected Member Functions

 GenLhashTable (size_t table_size, Hash_Fct __hash_fct, Cmp __cmp, float __lower_alpha, float __upper_alpha, bool __remove_all_buckets, bool __with_resize)
 

Protected Attributes

Hash_Fct hash_fct
 
size_t len
 
Cmp cmp
 
float lower_alpha
 
float upper_alpha
 

Friends

class HashStats< GenLhashTable< Key, BucketType, Cmp > >
 

Detailed Description

template<typename Key, class BucketType, class Cmp>
class Aleph::GenLhashTable< Key, BucketType, Cmp >

Tabla hash genérica con resolución de colisiones por encadenamiento separado.

El tipo GenLhashTable implanta una tabla hash genérica con resolución de colisiones por encadenamiento separado en la cual el tipo de cubeta es un parámetro tipo.

Normalmente, este es destinado como back-end de los tipos LhashTable y LhashTableVtl, los cuales son fundamentalmente lo mismo, a excepción de que éstos ya tienen definidos su clases cubetas sin o con destructor virtual.

Parameters
Keyclave de indización de la tabla.
BucketTypeel tipo de cubeta.
Cmpclase de comparación entre las claves.
See also
LhashTable LhashTableVtl

Constructor & Destructor Documentation

◆ GenLhashTable()

template<typename Key, class BucketType, class Cmp>
Aleph::GenLhashTable< Key, BucketType, Cmp >::GenLhashTable ( size_t  table_size = Primes::DefaultPrime,
Hash_Fct_Ptr  hash_fct = Aleph::dft_hash_fct<Key>,
Cmp  cmp = Cmp(),
float  lower_alpha = hash_default_lower_alpha,
float  upper_alpha = hash_default_upper_alpha,
bool  remove_all_buckets = true,
bool  with_resize = true 
)
inline

Instancia una tabla hash genérica.

Parameters
[in]__hash_fctla función hash.
[in]table_sizeel tamaño de la tabla.
[in]__remove_all_bucketssi es true, entonces se liberan todas las cubetas cuando se invoca al destructor.
Exceptions
bad_allocsi no hay memoria para apartar la tabla.

◆ ~GenLhashTable()

template<typename Key, class BucketType, class Cmp>
virtual Aleph::GenLhashTable< Key, BucketType, Cmp >::~GenLhashTable ( )
inlinevirtual

Libera la memoria de la tabla y si remove_all_buckets es true (especificado en el constructor), entonces también se libera la memoria de todas las cubetas.

Member Function Documentation

◆ insert()

template<typename Key, class BucketType, class Cmp>
Bucket* Aleph::GenLhashTable< Key, BucketType, Cmp >::insert ( Bucket *  bucket)
inline

Inserta en la tabla la cubeta bucket y retorna su dirección si la clave no está en la tabla; de lo contrario se retorna nullptr

◆ remove()

template<typename Key, class BucketType, class Cmp>
Bucket* Aleph::GenLhashTable< Key, BucketType, Cmp >::remove ( Bucket *  bucket)
inlinenoexcept

Elimina de la tabla la cubeta bucket. Retorna la dirección de la cubeta. ATENCIÓN: no se verifica que la cubeta pertenezca a la tabla.

◆ resize()

template<typename Key, class BucketType, class Cmp>
size_t Aleph::GenLhashTable< Key, BucketType, Cmp >::resize ( size_t  new_size)
inline

Reajusta la dimensión de la tabla hash al valor new_size y reubica las claves. Dispara bad_alloc si no hay suficiente memoria para reubicar el arreglo.

◆ search()

template<typename Key, class BucketType, class Cmp>
Bucket* Aleph::GenLhashTable< Key, BucketType, Cmp >::search ( const Key &  key) const
inlinenoexcept

Busca en la tabla una cubeta con la clave key. Retorna un puntero a la cubeta si se encuentra; nullptr de lo contrario.

◆ search_next()

template<typename Key, class BucketType, class Cmp>
Bucket* Aleph::GenLhashTable< Key, BucketType, Cmp >::search_next ( Bucket *  bucket) const
inlinenoexcept

retorna la próxima cubeta que colisiona con bucket. Si no existe, entonces se retorna nullptr.


The documentation for this class was generated from the following file:

Leandro Rabindranath León