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)
template<typename T>
inline void update_value(const T &val)
inline std::uint64_t finish() const
inline std::uint32_t finish32() const

Public Members

std::uint64_t state = FNV1A_OFFSET_BASIS
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”)

Public Functions

inline Fnv1aHasherUtility()
~Fnv1aHasherUtility() override = default
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

struct Hash

Hash value for a string/line.

Public Functions

Hash() = default
inline explicit Hash(std::size_t v)
inline bool operator==(const Hash &other) const
inline bool operator!=(const Hash &other) const

Public Members

std::size_t value = 0
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 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 coro::CoroTask<Hash> process(const std::string &input) override
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 coro::CoroTask<Hash> process(const std::string &input) override
inline void update(std::string_view data) override
class StdHasherUtility : public dftracer::utils::utilities::hash::internal::BaseHasherUtility

std::hash-based hasher utility.

Combines hashes of chunks using the boost hash_combine technique.

Public Functions

inline StdHasherUtility()
~StdHasherUtility() override = default
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