shangxinli commented on code in PR #280:
URL: https://github.com/apache/iceberg-cpp/pull/280#discussion_r2485232847
##########
src/iceberg/expression/literal.cc:
##########
@@ -554,4 +554,51 @@ Result<Literal> LiteralCaster::CastTo(const Literal&
literal,
target_type->ToString());
}
+// LiteralValueHash implementation
+std::size_t LiteralValueHash::operator()(const Literal::Value& value) const
noexcept {
+ return std::visit(
+ [](const auto& v) -> std::size_t {
+ using T = std::decay_t<decltype(v)>;
+
+ constexpr size_t kHashPrime = 0x9e3779b9;
+
+ if constexpr (std::is_same_v<T, std::monostate>) {
+ return 0;
+ } else if constexpr (std::is_same_v<T, Literal::BelowMin>) {
+ return std::numeric_limits<std::size_t>::min();
+ } else if constexpr (std::is_same_v<T, Literal::AboveMax>) {
+ return std::numeric_limits<std::size_t>::max();
+ } else if constexpr (std::is_same_v<T, bool> || std::is_same_v<T,
int32_t> ||
+ std::is_same_v<T, int64_t> || std::is_same_v<T,
float> ||
+ std::is_same_v<T, double> ||
+ std::is_same_v<T, std::string>) {
+ return std::hash<T>{}(v);
+ } else if constexpr (std::is_same_v<T, std::vector<uint8_t>>) {
+ std::size_t hash = 0;
+ for (size_t i = 0; i < v.size(); ++i) {
+ hash ^= std::hash<uint8_t>{}(v[i]) + kHashPrime + (hash << 6) +
(hash >> 2);
Review Comment:
I traced through the logic again and realized you are right. The hash is
position-sensitive because each iteration depends on the accumulated hash state
from previous iterations.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]