You've already forked openscreen

This updates constant declarations at namespace scope to follow the guidelines in: https://docs.google.com/document/d/1LVfOmlmry5rzbq6iiBSDmyAAvOxM1KpNqKUlyf0inCY/edit?usp=sharing This was done using the following regexps and is not guaranteed to catch 100% of usages. [r"^const ([^=]+)=([^;]+);", r"constexpr \1=\2;", ["*.cc"]], [r"^inline constexpr ([^=]+)=([^;]+);", r"constexpr \1=\2;", ["*.cc"]], [r"^static constexpr ([^=]+)=([^;]+);", r"constexpr \1=\2;", ["*.cc"]], [r"^const ([^=]+)=([^;]+);", r"inline constexpr \1=\2;", ["*.h"]], [r"^constexpr ([^=]+)=([^;]+);", r"inline constexpr \1=\2;", ["*.h"]], [r"^inline const ([^=]+)=([^;]+);", r"inline constexpr \1=\2;", ["*.h"]], [r"^static const ([^=]+)=([^;]+);", r"inline constexpr \1=\2;", ["*.h"]], [r"^static constexpr ([^=]+)=([^;]+);", r"inline constexpr \1=\2;", ["*.h"]], It also does not attempt to update constants in function or class scope, as rewriting those with regexps is significantly more difficult. Change-Id: I05e6bd09aaafe765fdba8d6eb487cc78ded3405c Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/6093132 Reviewed-by: Jordan Bayles <jophba@chromium.org> Commit-Queue: Jordan Bayles <jophba@chromium.org>
57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
// Copyright 2020 The Chromium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef UTIL_HASHING_H_
|
|
#define UTIL_HASHING_H_
|
|
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
namespace openscreen {
|
|
|
|
// This value is taken from absl::Hash implementation.
|
|
inline constexpr uint64_t kDefaultSeed = UINT64_C(0xc3a5c85c97cb3127);
|
|
|
|
// Computes the aggregate hash of the provided hashable objects.
|
|
// Seed must initially use a large prime between 2^63 and 2^64 as a starting
|
|
// value, or the result of a previous call to this function.
|
|
template <typename... T>
|
|
uint64_t ComputeAggregateHash(uint64_t original_seed, const T&... objs) {
|
|
auto hash_combiner = [](uint64_t current_seed,
|
|
uint64_t hash_value) -> uint64_t {
|
|
static const uint64_t kMultiplier = UINT64_C(0x9ddfea08eb382d69);
|
|
uint64_t a = (hash_value ^ current_seed) * kMultiplier;
|
|
a ^= (a >> 47);
|
|
uint64_t b = (current_seed ^ a) * kMultiplier;
|
|
b ^= (b >> 47);
|
|
b *= kMultiplier;
|
|
return b;
|
|
};
|
|
|
|
uint64_t result = original_seed;
|
|
std::vector<uint64_t> hashes = {std::hash<T>()(objs)...};
|
|
for (uint64_t hash : hashes) {
|
|
result = hash_combiner(result, hash);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
template <typename... T>
|
|
uint64_t ComputeAggregateHash(const T&... objs) {
|
|
// This value is taken from absl::Hash implementation.
|
|
constexpr uint64_t default_seed = UINT64_C(0xc3a5c85c97cb3127);
|
|
return ComputeAggregateHash(default_seed, objs...);
|
|
}
|
|
|
|
struct PairHash {
|
|
template <typename TFirst, typename TSecond>
|
|
size_t operator()(const std::pair<TFirst, TSecond>& pair) const {
|
|
return ComputeAggregateHash(pair.first, pair.second);
|
|
}
|
|
};
|
|
|
|
} // namespace openscreen
|
|
|
|
#endif // UTIL_HASHING_H_
|