/* * Copyright (C) 2018-present ScyllaDB */ /* * SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0 */ #pragma once #include "utils/digest_algorithm.hh" #include "utils/hashing.hh" #include "utils/xx_hasher.hh" #include #include namespace query { struct noop_hasher { void update(const char* ptr, size_t length) noexcept { } std::array finalize_array() { return std::array(); }; }; class digester final { std::variant _impl; public: explicit digester(digest_algorithm algo) { switch (algo) { case digest_algorithm::xxHash: _impl = xx_hasher(); break; case digest_algorithm ::none: _impl = noop_hasher(); break; } } template void feed_hash(const T& value, Args&&... args) { // FIXME uncomment the noexcept marking once clang bug 50994 is fixed or gcc compilation is turned on std::visit([&] (auto& hasher) /* noexcept(noexcept(::feed_hash(hasher, value, args...))) */ -> void { ::feed_hash(hasher, value, std::forward(args)...); }, _impl); }; std::array finalize_array() { return std::visit([&] (auto& hasher) { return hasher.finalize_array(); }, _impl); } }; using default_hasher = xx_hasher; template using using_hash_of_hash = std::negation>; template inline constexpr bool using_hash_of_hash_v = using_hash_of_hash::value; }