0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-03-16 22:41:46 +01:00

ircd: Typedef a buf for sha256; improve hash related interface.

This commit is contained in:
Jason Volk 2017-10-11 17:55:07 -07:00
parent 8da4874f2c
commit d3f6ed0320

View file

@ -31,12 +31,12 @@ namespace ircd
// string at compile time leaving an integer residue at runtime.
constexpr size_t hash(const char *const &str, const size_t i = 0);
constexpr size_t hash(const char16_t *const &str, const size_t i = 0);
constexpr size_t hash(const std::string_view &str, const size_t i = 0);
// Note that at runtime this hash uses multiplication on every character
// which can consume many cycles...
size_t hash(const std::string &str, const size_t i = 0);
size_t hash(const std::u16string &str, const size_t i = 0);
size_t hash(const std::string_view &str, const size_t i = 0);
/// ircd:: reserves the $ character over a string as an alias for hash()
template<class string>
@ -107,6 +107,8 @@ struct ircd::crh::sha256
256 / 8
};
using buf = fixed_const_raw_buffer<digest_size>;
protected:
std::unique_ptr<ctx> ctx;
@ -147,14 +149,6 @@ const
};
}
/// Runtime hashing of a string_view. Non-cryptographic.
inline size_t
ircd::hash(const std::string_view &str,
const size_t i)
{
return i >= str.size()? 7681ULL : (hash(str, i+1) * 33ULL) ^ str.at(i);
}
/// Runtime hashing of a std::u16string (for js). Non-cryptographic.
inline size_t
ircd::hash(const std::u16string &str,
@ -171,6 +165,14 @@ ircd::hash(const std::string &str,
return i >= str.size()? 7681ULL : (hash(str, i+1) * 33ULL) ^ str.at(i);
}
/// Runtime hashing of a string_view. Non-cryptographic.
constexpr size_t
ircd::hash(const std::string_view &str,
const size_t i)
{
return i >= str.size()? 7681ULL : (hash(str, i+1) * 33ULL) ^ str.at(i);
}
/// Compile-time hashing of a wider string literal (for js). Non-cryptographic.
constexpr size_t
ircd::hash(const char16_t *const &str,