|
Boost : |
From: Ivan Matek (libbooze_at_[hidden])
Date: 2024-12-02 20:59:49
Read documentation for 20 minutes so apologies in advance is some of
questions are too obvious.
1) did you consider using something like std::span here? I presume answer
is yes, but you do not want to limit library to C++20 onwards.
HashAlgorithm( unsigned char const* seed, std::size_t n ); void update( void
const* data, std::size_t n );
2) From what I see there is no way for algorithm to say it only works on
aligned data, e.g. to avoid runtime check of data alignment because SIMD
instructions?
E.g
void update_aligned<32>( void const* data, std::size_t n );
Would this be too much complication for too little performance gain(not to
mention UB risk)? Not an expert, just know performance was motivation for
std::assume_aligned
<https://open-std.org/JTC1/SC22/WG21/docs/papers/2018/p1007r1.pdf>
3) I see there is nice trait is_contiguously_hashable trait(padding was one
of first things I wondered when reading docs), and also a documentation on
how to deal with other types, including when user provides his own hash
customization.
One thing I would ask regarding design is the following example:
std::string a; int b; // not part of the salient state void const* c;
friend bool operator==( X const& x1, X const& x2 ) { return x1.a == x2.a &&
x1.b == x2.b; } template<class Hash, class Flavor> friend void tag_invoke(
boost::hash2::hash_append_tag const&, Hash& h, Flavor const& f, X const& v )
{ boost::hash2::hash_append(h, f, v.a); boost::hash2::hash_append(h, f, v.b
); }
Here both tag_invoke and operator == need to remember to use same fields.
Would it be possible to have support so that both hash and operator == can
use member function helper that returns tuple of references( to salient
fields)?
e.g. assume this is my current code and I want to add hash support for it.
struct X {
int a;
short b;
short cached_something;
constexpr auto repr() const {
return std::tie(a,b);
}
constexpr bool operator == (const X& other) const {
return repr() == other.repr();
}
};
I know Mp11 has tuple_for_each, but I wonder if it would be nice to have
something that makes this idiom easier to use?
4) Paper mentioned is quite old, but if you remember... do you have some
feedback paper received at the time?
On Mon, Dec 2, 2024 at 8:49â¯PM Peter Dimov via Boost <boost_at_[hidden]>
wrote:
> I'd like to request a formal review for the Hash2 library
>
> https://github.com/pdimov/hash2
> https://pdimov.github.io/hash2/
>
> (by Christian Mazakas and myself.)
>
> The library implements an extensible framework for implementing
> hashing algorithms that can support user-defined types. Its structure
> is largely based on the paper "Types donât know #" by Howard Hinnant,
> Vinnie Falco and John Bytheway.
>
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3980.html
>
> We're looking for a review manager.
>
> Comments and questions are welcome; you don't need to wait for the
> review.
>
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk