Hash Utilities¶
Namespace: dftracer::utils::utilities::hash
-
struct Fnv1aHashBuilder¶
Public Functions
-
inline void update(const void *data, std::size_t len)¶
-
inline void update(std::string_view data)¶
-
inline std::uint64_t finish() const¶
-
inline std::uint32_t finish32() const¶
Public Members
-
std::uint64_t state = FNV1A_OFFSET_BASIS¶
-
inline void update(const void *data, std::size_t len)¶
-
class Fnv1aHasherUtility : public dftracer::utils::utilities::hash::internal::BaseHasherUtility¶
FNV-1a 64-bit streaming hasher utility.
Processes data byte-by-byte, producing consistent results regardless of how input is chunked: update(“Hello”); update(“World”) == update(“HelloWorld”)
-
class HasherUtility : public dftracer::utils::utilities::hash::internal::BaseHasherUtility¶
Unified hasher utility that can use different algorithms.
This utility provides a single interface that can switch between different hash algorithms using a factory pattern.
Usage:
auto hasher = std::make_shared<HasherUtility>(HashAlgorithm::STD); hasher->reset(); hasher->process("chunk1"); hasher->process("chunk2"); Hash final = hasher->get_hash(); // Or use update() directly for raw data hasher->reset(); Hash result = hasher->update("raw data");
Subclassed by dftracer::utils::utilities::hash::MTHasherUtility
Public Functions
-
inline explicit HasherUtility(HashAlgorithm algo = HashAlgorithm::FNV1A_64)¶
-
~HasherUtility() override = default¶
-
inline void set_algorithm(HashAlgorithm algo)¶
Change the hash algorithm. This will reset the current state.
-
inline HashAlgorithm get_algorithm() const¶
-
inline virtual void reset() override¶
Reset/initialize the hash state. Must be called before first process() or update().
-
inline virtual Hash get_hash() const override¶
Get the current hash value.
This returns the hash computed so far. After the last update(), this is the final hash value.
- Returns:
Current hash value
-
inline explicit HasherUtility(HashAlgorithm algo = HashAlgorithm::FNV1A_64)¶
-
class MTHasherUtility : public dftracer::utils::utilities::hash::HasherUtility¶
Thread-safe version of HasherUtility.
Extends HasherUtility with mutex protection, making all operations thread-safe. Supports all the same features (algorithm switching, etc.) with added concurrency safety.
Usage:
// Create thread-safe hasher with default algorithm auto hasher = std::make_shared<MTHasherUtility>(); // Or specify algorithm auto hasher = std::make_shared<MTHasherUtility>(HashAlgorithm::STD); // Safe to use from multiple threads hasher->reset(); Hash result = hasher->update("chunk1"); // Thread-safe result = hasher->update("chunk2"); // Thread-safe
Note: While this makes the hasher thread-safe, you still need to coordinate the order of updates across threads if you want deterministic results.
Public Functions
-
inline explicit MTHasherUtility(HashAlgorithm algo = HashAlgorithm::FNV1A_64)¶
-
~MTHasherUtility() override = default¶
-
inline void set_algorithm(HashAlgorithm algo)¶
-
inline virtual void reset() override¶
Reset/initialize the hash state. Must be called before first process() or update().
-
inline virtual void update(std::string_view data) override¶
Update the hash with new data.
The hash is computed incrementally and stored in current_hash_. After the last update(), current_hash_ contains the final hash.
- Parameters:
data – String view of data to hash
-
inline virtual Hash get_hash() const override¶
Get the current hash value.
This returns the hash computed so far. After the last update(), this is the final hash value.
- Returns:
Current hash value
-
inline void update(std::string_view data) override
-
inline explicit MTHasherUtility(HashAlgorithm algo = HashAlgorithm::FNV1A_64)¶
-
class StdHasherUtility : public dftracer::utils::utilities::hash::internal::BaseHasherUtility¶
std::hash-based hasher utility.
Combines hashes of chunks using the boost hash_combine technique.