diff options
Diffstat (limited to 'absl/hash/hash.h')
-rw-r--r-- | absl/hash/hash.h | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/absl/hash/hash.h b/absl/hash/hash.h index 2c8982b8..d36f0960 100644 --- a/absl/hash/hash.h +++ b/absl/hash/hash.h @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -36,25 +36,34 @@ // framework by simply combining its state with the state of known, hashable // types. Hashing of that combined state is separately done by `absl::Hash`. // +// One should assume that a hash algorithm is chosen randomly at the start of +// each process. E.g., absl::Hash<int>()(9) in one process and +// absl::Hash<int>()(9) in another process are likely to differ. +// // Example: // -// // Suppose we have a class `Circle` for which we want to add hashing +// // Suppose we have a class `Circle` for which we want to add hashing: // class Circle { -// public: -// ... -// private: -// std::pair<int, int> center_; -// int radius_; -// }; -// -// // To add hashing support to `Circle`, we simply need to add an ordinary -// // function `AbslHashValue()`, and return the combined hash state of the -// // existing hash state and the class state: +// public: +// ... +// private: +// std::pair<int, int> center_; +// int radius_; +// }; // +// // To add hashing support to `Circle`, we simply need to add a free +// // (non-member) function `AbslHashValue()`, and return the combined hash +// // state of the existing hash state and the class state. You can add such a +// // free function using a friend declaration within the body of the class: +// class Circle { +// public: +// ... // template <typename H> // friend H AbslHashValue(H h, const Circle& c) { // return H::combine(std::move(h), c.center_, c.radius_); // } +// ... +// }; // // For more information, see Adding Type Support to `absl::Hash` below. // @@ -64,7 +73,7 @@ #include "absl/hash/internal/hash.h" namespace absl { -inline namespace lts_2018_12_18 { +inline namespace lts_2019_08_08 { // ----------------------------------------------------------------------------- // `absl::Hash` @@ -236,7 +245,7 @@ using Hash = absl::hash_internal::Hash<T>; // } // private: // virtual void HashValue(absl::HashState state) const = 0; -// }; +// }; // // class Impl : Interface { // private: @@ -244,7 +253,7 @@ using Hash = absl::hash_internal::Hash<T>; // absl::HashState::combine(std::move(state), v1_, v2_); // } // int v1_; -// string v2_; +// std::string v2_; // }; class HashState : public hash_internal::HashStateBase<HashState> { public: @@ -309,6 +318,7 @@ class HashState : public hash_internal::HashStateBase<HashState> { void (*combine_contiguous_)(void*, const unsigned char*, size_t); }; -} // inline namespace lts_2018_12_18 +} // inline namespace lts_2019_08_08 } // namespace absl + #endif // ABSL_HASH_HASH_H_ |