From 70800b7f7f300bb307a5bba15f0572cfb6fdc47c Mon Sep 17 00:00:00 2001 From: James Ring Date: Wed, 24 Apr 2019 09:39:50 -0700 Subject: [PATCH] Move platform/default/fingerprint.h into platform/fingerprint.h. PiperOrigin-RevId: 245060405 --- .../core/platform/default/fingerprint.h | 37 ----------------- tensorflow/core/platform/fingerprint.h | 41 ++++++++++++++----- 2 files changed, 30 insertions(+), 48 deletions(-) delete mode 100644 tensorflow/core/platform/default/fingerprint.h diff --git a/tensorflow/core/platform/default/fingerprint.h b/tensorflow/core/platform/default/fingerprint.h deleted file mode 100644 index f901befc16bafd..00000000000000 --- a/tensorflow/core/platform/default/fingerprint.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright 2016 The TensorFlow Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -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 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ - -#ifndef TENSORFLOW_CORE_PLATFORM_DEFAULT_FINGERPRINT_H_ -#define TENSORFLOW_CORE_PLATFORM_DEFAULT_FINGERPRINT_H_ - -#include - -#include "tensorflow/core/lib/core/stringpiece.h" - -namespace tensorflow { - -inline uint64 Fingerprint64(StringPiece s) { - return ::util::Fingerprint64(s.data(), s.size()); -} - -inline Fprint128 Fingerprint128(StringPiece s) { - const auto fingerprint = ::util::Fingerprint128(s.data(), s.size()); - return {::util::Uint128Low64(fingerprint), - ::util::Uint128High64(fingerprint)}; -} - -} // namespace tensorflow - -#endif // TENSORFLOW_CORE_PLATFORM_DEFAULT_FINGERPRINT_H_ diff --git a/tensorflow/core/platform/fingerprint.h b/tensorflow/core/platform/fingerprint.h index 720dc4c3d6b066..d460514acccfd0 100644 --- a/tensorflow/core/platform/fingerprint.h +++ b/tensorflow/core/platform/fingerprint.h @@ -19,6 +19,16 @@ limitations under the License. #include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/platform/types.h" +// The following line is used by copybara to set or unset the USE_OSS_FARMHASH +// preprocessor symbol as needed. Please do not remove. +#define USE_OSS_FARMHASH + +#ifdef USE_OSS_FARMHASH +#include +#else +#include "util/hash/farmhash_fingerprint.h" +#endif + namespace tensorflow { struct Fprint128 { @@ -37,13 +47,6 @@ struct Fprint128Hasher { } }; -// This is a portable fingerprint interface for strings that will never change. -// However, it is not suitable for cryptography. -uint64 Fingerprint64(StringPiece s); - -// 128-bit variant of Fingerprint64 above (same properties and caveats apply). -Fprint128 Fingerprint128(StringPiece s); - namespace internal { // Mixes some of the bits that got propagated to the high bits back into the // low bits. @@ -72,12 +75,28 @@ inline uint64 FingerprintCat64(const uint64 fp1, const uint64 fp2) { return result; } -} // namespace tensorflow +// This is a portable fingerprint interface for strings that will never change. +// However, it is not suitable for cryptography. +inline uint64 Fingerprint64(StringPiece s) { +#ifdef USE_OSS_FARMHASH + return ::util::Fingerprint64(s.data(), s.size()); +#else + return farmhash::Fingerprint64(s.data(), s.size()); +#endif +} -#if defined(PLATFORM_GOOGLE) || defined(PLATFORM_GOOGLE_ANDROID) -#include "tensorflow/core/platform/google/fingerprint.h" +// 128-bit variant of Fingerprint64 above (same properties and caveats apply). +inline Fprint128 Fingerprint128(StringPiece s) { +#ifdef USE_OSS_FARMHASH + const auto fingerprint = ::util::Fingerprint128(s.data(), s.size()); + return {::util::Uint128Low64(fingerprint), + ::util::Uint128High64(fingerprint)}; #else -#include "tensorflow/core/platform/default/fingerprint.h" + const auto fingerprint = farmhash::Fingerprint128(s.data(), s.size()); + return {absl::Uint128Low64(fingerprint), absl::Uint128High64(fingerprint)}; #endif +} + +} // namespace tensorflow #endif // TENSORFLOW_CORE_PLATFORM_FINGERPRINT_H_