libhatchet
Loading...
Searching...
No Matches
hxkey.hpp File Reference

Go to the source code of this file.

Classes

class  hxkey_equal_t< T >
class  hxkey_less_t< T >

Concepts

concept  hxconvertible_to
concept  hxsame_as

Functions

template<typename A_, typename B_>
requires requires(const A_& a_, const B_& b_) { { a_ == b_ } -> hxconvertible_to<bool>; }
constexpr bool hxkey_equal (const A_ &a_, const B_ &b_)
bool hxkey_equal (const hxcstring_const_ &a_, const hxcstring_const_ &b_)
bool hxkey_equal (const hxcstring_const_ &a_, const hxcstring_ &b_)
bool hxkey_equal (const hxcstring_ &a_, const hxcstring_const_ &b_)
bool hxkey_equal (const hxcstring_ &a_, const hxcstring_ &b_)
template<typename A_, typename B_>
requires requires(const A_& a_, const B_& b_) { { a_ < b_ } -> hxconvertible_to<bool>; }
constexpr bool hxkey_less (const A_ &a_, const B_ &b_)
bool hxkey_less (const hxcstring_const_ &a_, const hxcstring_const_ &b_)
bool hxkey_less (const hxcstring_const_ &a_, const hxcstring_ &b_)
bool hxkey_less (const hxcstring_ &a_, const hxcstring_const_ &b_)
bool hxkey_less (const hxcstring_ &a_, const hxcstring_ &b_)
template<typename T>
hxhash_t hxkey_hash (T x_)
hxhash_t hxkey_hash (const char *s_)

Detailed Description

User-overloadable key-equal, key-less, and key-hash functions.

By default this code uses only the == and < operators, which works with a defaulted <=> operator. Alternatively, these functions can be overloaded to resolve key operations without global operator overloads. This code uses C++20 concepts when available and provides no fallbacks for SFINAE otherwise. Partial specialization does not work before C++20. As an alternative, callables are recommended and supported for complex use cases because they are relatively easy to debug. See hxkey_equal_t and hxkey_less_t for generating default callables.

Function Documentation

◆ hxkey_equal() [1/5]

template<typename A_, typename B_>
requires requires(const A_& a_, const B_& b_) { { a_ == b_ } -> hxconvertible_to<bool>; }
bool hxkey_equal ( const A_ & a_,
const B_ & b_ )
inlineconstexpr

hxkey_equal(const A& a, const B& b) - Returns true if two objects are equivalent.

If your key type does not support operator==, then this function may need to be overridden for your key type(s). Function overloads are evaluated when and where the derived container is instantiated and must be consistently available. Uses operator==.

◆ hxkey_equal() [2/5]

bool hxkey_equal ( const hxcstring_ & a_,
const hxcstring_ & b_ )
inline

◆ hxkey_equal() [3/5]

bool hxkey_equal ( const hxcstring_ & a_,
const hxcstring_const_ & b_ )
inline

◆ hxkey_equal() [4/5]

bool hxkey_equal ( const hxcstring_const_ & a_,
const hxcstring_ & b_ )
inline

◆ hxkey_equal() [5/5]

bool hxkey_equal ( const hxcstring_const_ & a_,
const hxcstring_const_ & b_ )
inline

hxkey_equal(const char*, const char*) - Returns true if two C strings are equal (strcmp(a, b) == 0).

  • a : The first C string.
  • b : The second C string.

◆ hxkey_hash() [1/2]

hxhash_t hxkey_hash ( const char * s_)
inline

hxkey_hash(const char*) - Returns the xxhash32 style hash of a C string.

Mixes each byte with the xxhash32 primes in a single pass and applies the xxhash32 avalanche.

  • s : The C string.

◆ hxkey_hash() [2/2]

template<typename T>
hxhash_t hxkey_hash ( T x_)
inline

hxkey_hash(T) - Returns the xxhash32 of a numeric value cast to 32 bits.

Used by the base hash table node. Override for custom key types. Overrides are evaluated when and where the hash table is instantiated. Uses the xxhash32 short-input path for a single 4-byte word.

  • x : The input value.

◆ hxkey_less() [1/5]

template<typename A_, typename B_>
requires requires(const A_& a_, const B_& b_) { { a_ < b_ } -> hxconvertible_to<bool>; }
bool hxkey_less ( const A_ & a_,
const B_ & b_ )
inlineconstexpr

hxkey_less(const T&, const T&) - User-overloadable function for performing comparisons.

Invokes operator< by default. All the other comparison operators can be written using operator<. However hxkey_equal is also used for efficiency. Returns true if the first object is less than the second. Override for custom ordering.

  • a : The first object.
  • b : The second object.

◆ hxkey_less() [2/5]

bool hxkey_less ( const hxcstring_ & a_,
const hxcstring_ & b_ )
inline

◆ hxkey_less() [3/5]

bool hxkey_less ( const hxcstring_ & a_,
const hxcstring_const_ & b_ )
inline

◆ hxkey_less() [4/5]

bool hxkey_less ( const hxcstring_const_ & a_,
const hxcstring_ & b_ )
inline

◆ hxkey_less() [5/5]

bool hxkey_less ( const hxcstring_const_ & a_,
const hxcstring_const_ & b_ )
inline

hxkey_less(const char*, const char*) - Returns true if the first C string is lexicographically less than the second by ASCII.

UTF-8 is assigned a stable ordering without looking up a locale. Uses (strcmp(a, b) < 0).

  • a : The first C string.
  • b : The second C string.