Summary:
folly::StringPieceHash has a large comment explaining why not to use it, but it's not marked as deprecated.
It's also conveniently named StringPieceHash and not StringPieceHashDEPRECATED so new uses appear from time to time.
Let's nuke the default before it does more damage.
Reviewed By: yfeldblum
Differential Revision:
D3967239
fbshipit-source-id:
04b0564fdf2a70f1195ef2afdff092bc63cde975
#include <initializer_list>
#include <memory>
#include <unordered_map>
#include <initializer_list>
#include <memory>
#include <unordered_map>
+#include <utility>
+
+#include <folly/Hash.h>
#include <folly/Range.h>
#include <folly/experimental/StringKeyedCommon.h>
#include <folly/Range.h>
#include <folly/experimental/StringKeyedCommon.h>
* It uses kind of hack: string pointed by StringPiece is copied when
* StringPiece is inserted into map
*/
* It uses kind of hack: string pointed by StringPiece is copied when
* StringPiece is inserted into map
*/
-template <class Value,
- class Hash = StringPieceHash,
- class Eq = std::equal_to<StringPiece>,
- class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
+template <
+ class Value,
+ class Hash = Hash,
+ class Eq = std::equal_to<StringPiece>,
+ class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
class StringKeyedUnorderedMap
: private std::unordered_map<StringPiece, Value, Hash, Eq, Alloc> {
class StringKeyedUnorderedMap
: private std::unordered_map<StringPiece, Value, Hash, Eq, Alloc> {
using Base = std::unordered_map<StringPiece, Value, Hash, Eq, Alloc>;
public:
using Base = std::unordered_map<StringPiece, Value, Hash, Eq, Alloc>;
public:
#include <initializer_list>
#include <memory>
#include <unordered_set>
#include <initializer_list>
#include <memory>
#include <unordered_set>
+#include <utility>
+
+#include <folly/Hash.h>
#include <folly/Range.h>
#include <folly/experimental/StringKeyedCommon.h>
#include <folly/Range.h>
#include <folly/experimental/StringKeyedCommon.h>
* It uses kind of hack: string pointed by StringPiece is copied when
* StringPiece is inserted into set
*/
* It uses kind of hack: string pointed by StringPiece is copied when
* StringPiece is inserted into set
*/
-template <class Hasher = StringPieceHash,
- class Eq = std::equal_to<StringPiece>,
- class Alloc = std::allocator<folly::StringPiece>>
+template <
+ class Hasher = Hash,
+ class Eq = std::equal_to<StringPiece>,
+ class Alloc = std::allocator<folly::StringPiece>>
class BasicStringKeyedUnorderedSet
: private std::unordered_set<StringPiece, Hasher, Eq, Alloc> {
using Base = std::unordered_set<StringPiece, Hasher, Eq, Alloc>;
class BasicStringKeyedUnorderedSet
: private std::unordered_set<StringPiece, Hasher, Eq, Alloc> {
using Base = std::unordered_set<StringPiece, Hasher, Eq, Alloc>;
#include <glog/logging.h>
#include <glog/logging.h>
#include <folly/Range.h>
#include <folly/portability/GFlags.h>
#include <folly/portability/GTest.h>
#include <folly/Range.h>
#include <folly/portability/GFlags.h>
#include <folly/portability/GTest.h>
typedef MemoryLeakCheckerAllocator<
std::allocator<std::pair<const StringPiece, int>>> ValueLeakChecker;
typedef MemoryLeakCheckerAllocator<
std::allocator<std::pair<const StringPiece, int>>> ValueLeakChecker;
-typedef StringKeyedUnorderedMap<int, folly::StringPieceHash,
- std::equal_to<StringPiece>, ValueLeakChecker>
- LeakCheckedUnorderedMap;
+typedef StringKeyedUnorderedMap<
+ int,
+ folly::Hash,
+ std::equal_to<StringPiece>,
+ ValueLeakChecker>
+ LeakCheckedUnorderedMap;
-typedef StringKeyedSetBase<std::less<StringPiece>, ValueLeakChecker> LeakCheckedSet;
+typedef StringKeyedSetBase<std::less<StringPiece>, ValueLeakChecker>
+ LeakCheckedSet;
-typedef StringKeyedMap<int, std::less<StringPiece>,
- ValueLeakChecker> LeakCheckedMap;
+typedef StringKeyedMap<int, std::less<StringPiece>, ValueLeakChecker>
+ LeakCheckedMap;
using LeakCheckedUnorderedSet = BasicStringKeyedUnorderedSet<
using LeakCheckedUnorderedSet = BasicStringKeyedUnorderedSet<
- folly::StringPieceHash,
- std::equal_to<folly::StringPiece>,
- ValueLeakChecker>;
+ folly::Hash,
+ std::equal_to<folly::StringPiece>,
+ ValueLeakChecker>;
TEST(StringKeyedUnorderedMapTest, sanity) {
LeakCheckedUnorderedMap map;
TEST(StringKeyedUnorderedMapTest, sanity) {
LeakCheckedUnorderedMap map;