VTK
9.3.0
|
Represent a string by its integer hash. More...
#include <vtkStringToken.h>
Public Types | |
using | Hash = std::uint32_t |
Public Member Functions | |
vtkStringToken (const char *data=nullptr, std::size_t size=std::string::npos) | |
Construct a token from a string literal. | |
vtkStringToken (const std::string &data) | |
Construct a token from a std::string. | |
constexpr | vtkStringToken (Hash tokenId) noexcept |
Construct a token given its hash value. | |
Hash | GetId () const |
Return the token's ID (usually its hash but possibly not in the case of collisions). | |
const std::string & | Data () const |
Return the string corresponding to the token. | |
bool | operator== (const vtkStringToken &other) const |
Fast equality comparison (compares hashes, not strings). | |
bool | operator!= (const vtkStringToken &other) const |
Fast inequality comparison (compares hashes, not strings). | |
bool | operator< (const vtkStringToken &other) const |
Slow, but unsurprising string comparison (preserves lexical string ordering). | |
bool | operator> (const vtkStringToken &other) const |
bool | operator<= (const vtkStringToken &other) const |
bool | operator>= (const vtkStringToken &other) const |
Static Public Member Functions | |
static constexpr Hash | StringHash (const char *data, std::size_t size) noexcept |
Return the hash of a string This is used internally but also by the ""_token() literal operator. | |
static const vtkStringManager * | GetManager () |
Return the database of strings and their tokens (hashes). | |
Static Protected Member Functions | |
static vtkStringManager * | GetManagerInternal () |
static constexpr uint32_t | hash_32_fnv1a_const (const char *const str, std::size_t size, const uint32_t value=hash32a_const) noexcept |
Protected Attributes | |
Hash | Id |
Static Protected Attributes | |
static vtkSmartPointer< vtkStringManager > | Manager |
static constexpr uint32_t | hash32a_const = 0x811c9dc5 |
static constexpr uint32_t | hash32b_const = 0x1000193 |
static constexpr uint64_t | hash64a_const = 0xcbf29ce484222325 |
static constexpr uint64_t | hash64b_const = 0x100000001b3 |
Represent a string by its integer hash.
This class does not inherit vtkObject; it is a lightweight object for representing a string as a 32-bit integer token. Tokens can be constructed at compile-time (via the ""_token string-literal operator below) or run-time (via the constructor).
Equality comparisons are simple integer tests, while inequality operators attempt to locate the original source strings and compare them alphanumerically to preserve lexicographic ordering.
This class can be used inside ordered and unordered STL containers.
Definition at line 33 of file vtkStringToken.h.
using vtkStringToken::Hash = std::uint32_t |
Definition at line 36 of file vtkStringToken.h.
vtkStringToken::vtkStringToken | ( | const char * | data = nullptr , |
std::size_t | size = std::string::npos |
||
) |
Construct a token from a string literal.
vtkStringToken::vtkStringToken | ( | const std::string & | data | ) |
Construct a token from a std::string.
|
inlineconstexprnoexcept |
Construct a token given its hash value.
NOTE: This will NOT insert a string into the manager as other constructors do.
Definition at line 44 of file vtkStringToken.h.
|
inline |
Return the token's ID (usually its hash but possibly not in the case of collisions).
Definition at line 50 of file vtkStringToken.h.
const std::string & vtkStringToken::Data | ( | ) | const |
Return the string corresponding to the token.
bool vtkStringToken::operator== | ( | const vtkStringToken & | other | ) | const |
Fast equality comparison (compares hashes, not strings).
bool vtkStringToken::operator!= | ( | const vtkStringToken & | other | ) | const |
Fast inequality comparison (compares hashes, not strings).
bool vtkStringToken::operator< | ( | const vtkStringToken & | other | ) | const |
Slow, but unsurprising string comparison (preserves lexical string ordering).
bool vtkStringToken::operator> | ( | const vtkStringToken & | other | ) | const |
bool vtkStringToken::operator<= | ( | const vtkStringToken & | other | ) | const |
bool vtkStringToken::operator>= | ( | const vtkStringToken & | other | ) | const |
|
inlinestaticconstexprnoexcept |
Return the hash of a string This is used internally but also by the ""_token() literal operator.
Definition at line 67 of file vtkStringToken.h.
|
static |
Return the database of strings and their tokens (hashes).
|
staticprotected |
|
inlinestaticconstexprprotectednoexcept |
Definition at line 92 of file vtkStringToken.h.
|
protected |
Definition at line 76 of file vtkStringToken.h.
|
staticprotected |
Definition at line 77 of file vtkStringToken.h.
|
staticconstexprprotected |
Definition at line 84 of file vtkStringToken.h.
|
staticconstexprprotected |
Definition at line 85 of file vtkStringToken.h.
|
staticconstexprprotected |
Definition at line 86 of file vtkStringToken.h.
|
staticconstexprprotected |
Definition at line 87 of file vtkStringToken.h.