libhatchet
Loading...
Searching...
No Matches
hxhash_table_nodes.hpp
Go to the documentation of this file.
1#pragma once
2// SPDX-FileCopyrightText: © 2017-2026 Adrian Johnston.
3// SPDX-License-Identifier: MIT
4// This file is licensed under the MIT license found in the LICENSE.md file.
5
9
10#include "libhatchet.h"
11
12// HX_USE_MACROS_WITH_MODULE allows including macros alongside the module.
13#if HX_USE_MACROS_WITH_MODULE
14#error Header does not provide macros alone.
15#endif
16
17#include "hxhash_table.hpp"
18
19HX_NS_BEGIN_
20
25template<typename key_t_>
27public:
28 using key_t = key_t_;
29
32 hxhash_table_node_integer(const key_t_& key_) :
33 hxhash_node_base(hxkey_hash(key_)), m_key_(key_) { }
34
39
41 const key_t_& hash_key(void) const { return m_key_; }
43 hxhash_t hash_value(void) const { return this->hash_val; }
46 static hxhash_t hash_value(const key_t_& key_) { return hxkey_hash(key_); }
47
48private:
49 key_t_ m_key_;
50};
51
71
77template <hxsystem_allocator_t allocator_=hxsystem_allocator_heap>
79public:
86
88 ~hxhash_table_node_string(void) { hxfree(const_cast<char *>(this->hash_key())); }
89
93 void operator=(const hxhash_table_node_string&) = delete;
94};
95
96HX_NS_END_
hxhash_t hash_val
Definition hxhash_table.hpp:58
hxhash_node_base(hxhash_t hash_)
Constructs an unlinked node with the given cached hash.
Definition hxhash_table.hpp:55
hxhash_t hash_value(void) const
Returns the cached hash value for the stored key.
Definition hxhash_table_nodes.hpp:43
hxhash_table_node_integer & operator=(const hxhash_table_node_integer &x_)=delete
hxhash_table_node_integer(void)=delete
Assignment is undefined. The key is immutable.
static hxhash_t hash_value(const key_t_ &key_)
Returns the hash of a key without constructing a node.
Definition hxhash_table_nodes.hpp:46
hxhash_table_node_integer(const key_t_ &key_)
Constructs a node wrapping the key and caches its hash.
Definition hxhash_table_nodes.hpp:32
const key_t_ & hash_key(void) const
The key and hash identify the node_t and should not change once added.
Definition hxhash_table_nodes.hpp:41
key_t_ key_t
Definition hxhash_table_nodes.hpp:28
hxhash_table_node_integer(const hxhash_table_node_integer &src_)=delete
hxhash_table_node_string_literal(void)=delete
Assignment is undefined. The key is immutable.
void operator=(const hxhash_table_node_string_literal &)=delete
hxhash_table_node_string_literal(const hxhash_table_node_string_literal &)=delete
hxhash_table_node_string_literal(const char *k_)
Constructor initializes the node with a string key and computes its hash.
Definition hxhash_table_nodes.hpp:63
hxhash_table_node_string(const char *k_)
Constructor allocates and duplicates the string key, then initializes the node.
Definition hxhash_table_nodes.hpp:84
~hxhash_table_node_string(void)
Destructor frees the allocated string key.
Definition hxhash_table_nodes.hpp:88
hxhash_table_node_string(void)=delete
Assignment is undefined. The key is immutable.
hxhash_table_node_string(const hxhash_table_node_string &)=delete
void operator=(const hxhash_table_node_string &)=delete
const const char *& hash_key(void) const
Definition hxhash_table.hpp:93
hxhash_table_set_node(ref_t_ &&key_)
Definition hxhash_table.hpp:73
A fixed-size hash table with embedded singly-linked list buckets.
hxhash_t hxkey_hash(const T &x_)
hxkey_hash - Returns the hash of x, deducing T and invoking hxkey_hash_t<T>.
Definition hxkey.hpp:179
hxinline char * hxstring_duplicate(const char *s_)
hxstring_duplicate - Add default args to C interface.
Definition hxmemory_manager.h:147
void hxfree(void *ptr_) hxattr_noexcept hxattr_hot
hxfree - Frees memory previously allocated with hxmalloc or hxmalloc_ext.
hxattr_noexcept hxsystem_allocator_t allocator_
Definition hxmemory_manager.h:120
#define hxattr_nonnull(...)
hxattr_nonnull - Indicates that a function has args that should not be null.
Definition hxsettings.h:106
Provides core macros, memory management and feature detection.
uint32_t hxhash_t
hxhash_t - Unsigned 32-bit hash value. Expect collisions.
Definition libhatchet.h:210