X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FAtomicHashArray-inl.h;h=4333e5a0eb03135c05ded6ad1488a617e410100f;hb=9fef1cd9f2684c7c86ec9f051a0042ab48c690fb;hp=35a1927c53017de04822a04e9665252e94b1c9a2;hpb=4e5cb0efba9454e3abb2dd203116ed8e9a056468;p=folly.git diff --git a/folly/AtomicHashArray-inl.h b/folly/AtomicHashArray-inl.h index 35a1927c..4333e5a0 100644 --- a/folly/AtomicHashArray-inl.h +++ b/folly/AtomicHashArray-inl.h @@ -1,5 +1,5 @@ /* - * Copyright 2015 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,18 +20,24 @@ #include -#include #include +#include namespace folly { // AtomicHashArray private constructor -- -template +template < + class KeyT, + class ValueT, + class HashFcn, + class EqualFcn, + class Allocator, + class ProbeFcn, + class KeyConvertFcn> AtomicHashArray:: AtomicHashArray(size_t capacity, KeyT emptyKey, KeyT lockedKey, - KeyT erasedKey, double _maxLoadFactor, size_t cacheSize) + KeyT erasedKey, double _maxLoadFactor, uint32_t cacheSize) : capacity_(capacity), maxEntries_(size_t(_maxLoadFactor * capacity_ + 0.5)), kEmptyKey_(emptyKey), kLockedKey_(lockedKey), kErasedKey_(erasedKey), @@ -46,8 +52,14 @@ AtomicHashArray(size_t capacity, KeyT emptyKey, KeyT lockedKey, * of key and returns true, or if key does not exist returns false and * ret.index is set to capacity_. */ -template +template < + class KeyT, + class ValueT, + class HashFcn, + class EqualFcn, + class Allocator, + class ProbeFcn, + class KeyConvertFcn> template typename AtomicHashArray::SimpleRetT @@ -88,13 +100,20 @@ findInternal(const LookupKeyT key_in) { * this will be the previously inserted value, and if the map is full it is * default. */ -template -template +template < + class KeyT, + class ValueT, + class HashFcn, + class EqualFcn, + class Allocator, + class ProbeFcn, + class KeyConvertFcn> +template < + typename LookupKeyT, + typename LookupHashFcn, + typename LookupEqualFcn, + typename LookupKeyToKeyFcn, + typename... ArgTs> typename AtomicHashArray::SimpleRetT AtomicHashArraysecond) ValueT(std::forward(vCtorArgs)...); + // A const mapped_type is only constant once constructed, so cast + // away any const for the placement new here. + using mapped = typename std::remove_const::type; + new (const_cast(&cell->second)) + ValueT(std::forward(vCtorArgs)...); unlockCell(cell, key_new); // Sets the new key } catch (...) { // Transition back to empty key---requires handling @@ -218,8 +241,14 @@ insertInternal(LookupKeyT key_in, ArgTs&&... vCtorArgs) { * erased key will never be reused. If there's an associated value, we won't * touch it either. */ -template +template < + class KeyT, + class ValueT, + class HashFcn, + class EqualFcn, + class Allocator, + class ProbeFcn, + class KeyConvertFcn> size_t AtomicHashArray:: erase(KeyT key_in) { @@ -267,8 +296,14 @@ erase(KeyT key_in) { } } -template +template < + class KeyT, + class ValueT, + class HashFcn, + class EqualFcn, + class Allocator, + class ProbeFcn, + class KeyConvertFcn> typename AtomicHashArray::SmartPtr AtomicHashArray +template < + class KeyT, + class ValueT, + class HashFcn, + class EqualFcn, + class Allocator, + class ProbeFcn, + class KeyConvertFcn> void AtomicHashArray:: destroy(AtomicHashArray* p) { @@ -330,8 +371,14 @@ destroy(AtomicHashArray* p) { } // clear -- clears all keys and values in the map and resets all counters -template +template < + class KeyT, + class ValueT, + class HashFcn, + class EqualFcn, + class Allocator, + class ProbeFcn, + class KeyConvertFcn> void AtomicHashArray:: clear() { @@ -351,8 +398,14 @@ clear() { // Iterator implementation -template +template < + class KeyT, + class ValueT, + class HashFcn, + class EqualFcn, + class Allocator, + class ProbeFcn, + class KeyConvertFcn> template struct AtomicHashArray:: @@ -361,18 +414,17 @@ struct AtomicHashArray { - explicit aha_iterator() : aha_(0) {} + explicit aha_iterator() : aha_(nullptr) {} // Conversion ctor for interoperability between const_iterator and // iterator. The enable_if<> magic keeps us well-behaved for // is_convertible<> (v. the iterator_facade documentation). - template - aha_iterator(const aha_iterator& o, - typename std::enable_if< - std::is_convertible::value >::type* = 0) - : aha_(o.aha_) - , offset_(o.offset_) - {} + template + aha_iterator( + const aha_iterator& o, + typename std::enable_if< + std::is_convertible::value>::type* = nullptr) + : aha_(o.aha_), offset_(o.offset_) {} explicit aha_iterator(ContT* array, size_t offset) : aha_(array)