JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers โ€” header-only, RTTI-free, and concurrency-friendly.
Loading...
Searching...
No Matches
jh::atomic_str_hash Struct Referencefinal

Custom hash functor for atomic_str_ptr and compatible types. More...

#include <jh/core/immutable_str.h>

Public Member Functions

template<typename U>
std::uint64_t operator() (const U &value) const noexcept

Detailed Description

Custom hash functor for atomic_str_ptr and compatible types.

Provides transparent, content-based hashing for associative containers involving jh::immutable_str instances. It enables efficient heterogeneous lookup using const char* or string literals, while ensuring hash consistency across all compatible types.

  • Replaces the default std::shared_ptr hash, which hashes by pointer value, with a deterministic hash computed from string content.
  • Supports both atomic_str_ptr and const char* operands, constrained by immutable_str_compatible.
  • Transparent lookup is supported โ€” for example, a container of atomic_str_ptr keys can be queried with find("key") or contains("key").
  • At least one operand (either the stored key or the lookup key) must represent an actual immutable_str instance.
  • This contract allows future implementations to freely reorder or optimize operand evaluation while maintaining semantic equivalence.
  • When JH_IMMUTABLE_STR_AUTO_TRIM is enabled, leading and trailing ASCII whitespace are ignored in hash computation.
Template Parameters
UInput type โ€” must satisfy immutable_str_compatible (atomic_str_ptr or const char*).
Parameters
valueInput value to hash; may be nullptr (hash result = 0).
Returns
64-bit hash derived from string content.
Note
  • Designed primarily for containers that store atomic_str_ptr as keys.
  • Either operand may be a const char* during lookup, but at least one operand must refer to a valid immutable_str instance.
  • Whitespace trimming behavior is compile-time controlled via JH_IMMUTABLE_STR_AUTO_TRIM.
  • The nested is_transparent typedef enables heterogeneous lookup in standard unordered containers.

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