X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FFingerprint.h;h=9cf0f5073c1bf35686c4abd0eb77e9d86872172f;hb=bdd9360c598d80d524de6780cd5be65af56d98fd;hp=a0c474564ab20708ee48b2a97f8bc3471b848f4b;hpb=22afce906d7e98d95f8c45c3301072d9fd891d41;p=folly.git diff --git a/folly/Fingerprint.h b/folly/Fingerprint.h index a0c47456..9cf0f507 100644 --- a/folly/Fingerprint.h +++ b/folly/Fingerprint.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 Facebook, Inc. + * Copyright 2012-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,22 +42,46 @@ * @author Tudor Bosman (tudorb@facebook.com) */ -#ifndef FOLLY_FINGERPRINT_H_ -#define FOLLY_FINGERPRINT_H_ +#pragma once #include -#include "folly/Range.h" +#include namespace folly { namespace detail { + template struct FingerprintTable { - static const uint64_t poly[1 + (BITS-1)/64]; - static const uint64_t table[8][256][1 + (BITS-1)/64]; + static const uint64_t poly[1 + (BITS - 1) / 64]; + static const uint64_t table[8][256][1 + (BITS - 1) / 64]; }; -} // namespace detail + +template +const uint64_t FingerprintTable::poly[1 + (BITS - 1) / 64] = {}; +template +const uint64_t FingerprintTable::table[8][256][1 + (BITS - 1) / 64] = {}; + +#ifndef _MSC_VER +// MSVC 2015 can't handle these extern specialization declarations, +// but they aren't needed for things to work right, so we just don't +// declare them in the header for MSVC. + +#define FOLLY_DECLARE_FINGERPRINT_TABLES(BITS) \ + template <> \ + const uint64_t FingerprintTable::poly[1 + (BITS - 1) / 64]; \ + template <> \ + const uint64_t FingerprintTable::table[8][256][1 + (BITS - 1) / 64] + +FOLLY_DECLARE_FINGERPRINT_TABLES(64); +FOLLY_DECLARE_FINGERPRINT_TABLES(96); +FOLLY_DECLARE_FINGERPRINT_TABLES(128); + +#undef FOLLY_DECLARE_FINGERPRINT_TABLES +#endif + +} // namespace detail /** * Compute the Rabin fingerprint. @@ -74,9 +98,10 @@ class Fingerprint { public: Fingerprint() { // Use a non-zero starting value. We'll use (1 << (BITS-1)) - fp_[0] = 1UL << 63; - for (int i = 1; i < size(); i++) + fp_[0] = 1ULL << 63; + for (int i = 1; i < size(); i++) { fp_[i] = 0; + } } Fingerprint& update8(uint8_t v) { @@ -260,7 +285,4 @@ inline uint64_t Fingerprint<128>::shlor64(uint64_t v) { return out; } -} // namespace folly - -#endif /* FOLLY_FINGERPRINT_H_ */ - +} // namespace folly