Commit 594f484b authored by Giuseppe Ottaviano's avatar Giuseppe Ottaviano Committed by Facebook Github Bot

Move F14 fallbacks to separate headers

Summary:
Having the fallbacks in the public header files makes searching for classes/methods cumbersome, and some people have mistakenly assumed that F14 classes inherit from `unordered_*` because they landed on the wrong line.

In addition, when the fallback implementation is used, any compilation errors will come from the `*Fallback.h` files, making it clear that the main implementation is not being selected.

Reviewed By: yfeldblum

Differential Revision: D19926873

fbshipit-source-id: 492b0c252f33c0cbbf3c22dae38fa0bd63825f72
parent 0266f281
......@@ -27,7 +27,10 @@
* @author Xiao Shi <xshi@fb.com>
*/
#include <cstddef>
#include <initializer_list>
#include <stdexcept>
#include <tuple>
#include <folly/Range.h>
#include <folly/Traits.h>
......@@ -1291,162 +1294,8 @@ class F14FastMap : public std::conditional_t<
#else // !if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
//////// Compatibility for unsupported platforms (not x86_64 and not aarch64)
#include <folly/container/detail/F14MapFallback.h>
#include <string>
#include <unordered_map>
namespace folly {
namespace f14 {
namespace detail {
template <typename K, typename M, typename H, typename E, typename A>
class F14BasicMap : public std::unordered_map<K, M, H, E, A> {
using Super = std::unordered_map<K, M, H, E, A>;
public:
using typename Super::pointer;
using typename Super::value_type;
F14BasicMap() = default;
using Super::Super;
//// PUBLIC - F14 Extensions
bool containsEqualValue(value_type const& value) const {
auto slot = this->bucket(value.first);
auto e = this->end(slot);
for (auto b = this->begin(slot); b != e; ++b) {
if (b->first == value.first) {
return b->second == value.second;
}
}
return false;
}
// exact for libstdc++, approximate for others
std::size_t getAllocatedMemorySize() const {
std::size_t rv = 0;
visitAllocationClasses(
[&](std::size_t bytes, std::size_t n) { rv += bytes * n; });
return rv;
}
// exact for libstdc++, approximate for others
template <typename V>
void visitAllocationClasses(V&& visitor) const {
auto bc = this->bucket_count();
if (bc > 1) {
visitor(bc * sizeof(pointer), 1);
}
if (this->size() > 0) {
visitor(sizeof(StdNodeReplica<K, value_type, H>), this->size());
}
}
template <typename V>
void visitContiguousRanges(V&& visitor) const {
for (value_type const& entry : *this) {
value_type const* b = std::addressof(entry);
visitor(b, b + 1);
}
}
};
} // namespace detail
} // namespace f14
template <
typename Key,
typename Mapped,
typename Hasher,
typename KeyEqual,
typename Alloc>
class F14ValueMap
: public f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14ValueMap() = default;
using Super::Super;
F14ValueMap& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
template <
typename Key,
typename Mapped,
typename Hasher,
typename KeyEqual,
typename Alloc>
class F14NodeMap
: public f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14NodeMap() = default;
using Super::Super;
F14NodeMap& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
template <
typename Key,
typename Mapped,
typename Hasher,
typename KeyEqual,
typename Alloc>
class F14VectorMap
: public f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14VectorMap() = default;
using Super::Super;
F14VectorMap& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
template <
typename Key,
typename Mapped,
typename Hasher,
typename KeyEqual,
typename Alloc>
class F14FastMap
: public f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14FastMap() = default;
using Super::Super;
F14FastMap& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
} // namespace folly
#endif // if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE else
namespace folly {
......
......@@ -27,6 +27,8 @@
* @author Xiao Shi <xshi@fb.com>
*/
#include <cstddef>
#include <initializer_list>
#include <tuple>
#include <folly/lang/SafeAssert.h>
......@@ -1015,141 +1017,7 @@ class F14FastSet
#else // !if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
//////// Compatibility for unsupported platforms (not x86_64 and not aarch64)
#include <unordered_set>
namespace folly {
namespace f14 {
namespace detail {
template <typename K, typename H, typename E, typename A>
class F14BasicSet : public std::unordered_set<K, H, E, A> {
using Super = std::unordered_set<K, H, E, A>;
public:
using typename Super::pointer;
using typename Super::value_type;
F14BasicSet() = default;
using Super::Super;
//// PUBLIC - F14 Extensions
bool containsEqualValue(value_type const& value) const {
auto slot = this->bucket(value);
auto e = this->end(slot);
for (auto b = this->begin(slot); b != e; ++b) {
if (*b == value) {
return true;
}
}
return false;
}
// exact for libstdc++, approximate for others
std::size_t getAllocatedMemorySize() const {
std::size_t rv = 0;
visitAllocationClasses(
[&](std::size_t bytes, std::size_t n) { rv += bytes * n; });
return rv;
}
// exact for libstdc++, approximate for others
template <typename V>
void visitAllocationClasses(V&& visitor) const {
auto bc = this->bucket_count();
if (bc > 1) {
visitor(bc * sizeof(pointer), 1);
}
if (this->size() > 0) {
visitor(sizeof(StdNodeReplica<K, value_type, H>), this->size());
}
}
template <typename V>
void visitContiguousRanges(V&& visitor) const {
for (value_type const& entry : *this) {
value_type const* b = std::addressof(entry);
visitor(b, b + 1);
}
}
};
} // namespace detail
} // namespace f14
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14NodeSet
: public f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14NodeSet() = default;
using Super::Super;
F14NodeSet& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14ValueSet
: public f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14ValueSet() : Super() {}
using Super::Super;
F14ValueSet& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14VectorSet
: public f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14VectorSet() = default;
using Super::Super;
F14VectorSet& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14FastSet
: public f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14FastSet() = default;
using Super::Super;
F14FastSet& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
} // namespace folly
#include <folly/container/detail/F14SetFallback.h>
#endif // if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE else
......
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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.
*/
#pragma once
/**
* This file is intended to be included only by F14Map.h. It contains fallback
* implementations of F14Map types for platforms that do not support the
* required SIMD instructions, based on std::unordered_map.
*/
#include <unordered_map>
namespace folly {
namespace f14 {
namespace detail {
template <typename K, typename M, typename H, typename E, typename A>
class F14BasicMap : public std::unordered_map<K, M, H, E, A> {
using Super = std::unordered_map<K, M, H, E, A>;
public:
using typename Super::pointer;
using typename Super::value_type;
F14BasicMap() = default;
using Super::Super;
//// PUBLIC - F14 Extensions
bool containsEqualValue(value_type const& value) const {
auto slot = this->bucket(value.first);
auto e = this->end(slot);
for (auto b = this->begin(slot); b != e; ++b) {
if (b->first == value.first) {
return b->second == value.second;
}
}
return false;
}
// exact for libstdc++, approximate for others
std::size_t getAllocatedMemorySize() const {
std::size_t rv = 0;
visitAllocationClasses(
[&](std::size_t bytes, std::size_t n) { rv += bytes * n; });
return rv;
}
// exact for libstdc++, approximate for others
template <typename V>
void visitAllocationClasses(V&& visitor) const {
auto bc = this->bucket_count();
if (bc > 1) {
visitor(bc * sizeof(pointer), 1);
}
if (this->size() > 0) {
visitor(sizeof(StdNodeReplica<K, value_type, H>), this->size());
}
}
template <typename V>
void visitContiguousRanges(V&& visitor) const {
for (value_type const& entry : *this) {
value_type const* b = std::addressof(entry);
visitor(b, b + 1);
}
}
};
} // namespace detail
} // namespace f14
template <
typename Key,
typename Mapped,
typename Hasher,
typename KeyEqual,
typename Alloc>
class F14ValueMap
: public f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14ValueMap() = default;
using Super::Super;
F14ValueMap& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
template <
typename Key,
typename Mapped,
typename Hasher,
typename KeyEqual,
typename Alloc>
class F14NodeMap
: public f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14NodeMap() = default;
using Super::Super;
F14NodeMap& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
template <
typename Key,
typename Mapped,
typename Hasher,
typename KeyEqual,
typename Alloc>
class F14VectorMap
: public f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14VectorMap() = default;
using Super::Super;
F14VectorMap& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
template <
typename Key,
typename Mapped,
typename Hasher,
typename KeyEqual,
typename Alloc>
class F14FastMap
: public f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicMap<Key, Mapped, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14FastMap() = default;
using Super::Super;
F14FastMap& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
} // namespace folly
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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.
*/
#pragma once
/**
* This file is intended to be included only by F14Set.h. It contains fallback
* implementations of F14Set types for platforms that do not support the
* required SIMD instructions, based on std::unordered_set.
*/
#include <unordered_set>
namespace folly {
namespace f14 {
namespace detail {
template <typename K, typename H, typename E, typename A>
class F14BasicSet : public std::unordered_set<K, H, E, A> {
using Super = std::unordered_set<K, H, E, A>;
public:
using typename Super::pointer;
using typename Super::value_type;
F14BasicSet() = default;
using Super::Super;
//// PUBLIC - F14 Extensions
bool containsEqualValue(value_type const& value) const {
auto slot = this->bucket(value);
auto e = this->end(slot);
for (auto b = this->begin(slot); b != e; ++b) {
if (*b == value) {
return true;
}
}
return false;
}
// exact for libstdc++, approximate for others
std::size_t getAllocatedMemorySize() const {
std::size_t rv = 0;
visitAllocationClasses(
[&](std::size_t bytes, std::size_t n) { rv += bytes * n; });
return rv;
}
// exact for libstdc++, approximate for others
template <typename V>
void visitAllocationClasses(V&& visitor) const {
auto bc = this->bucket_count();
if (bc > 1) {
visitor(bc * sizeof(pointer), 1);
}
if (this->size() > 0) {
visitor(sizeof(StdNodeReplica<K, value_type, H>), this->size());
}
}
template <typename V>
void visitContiguousRanges(V&& visitor) const {
for (value_type const& entry : *this) {
value_type const* b = std::addressof(entry);
visitor(b, b + 1);
}
}
};
} // namespace detail
} // namespace f14
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14NodeSet
: public f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14NodeSet() = default;
using Super::Super;
F14NodeSet& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14ValueSet
: public f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14ValueSet() : Super() {}
using Super::Super;
F14ValueSet& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14VectorSet
: public f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14VectorSet() = default;
using Super::Super;
F14VectorSet& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
template <typename Key, typename Hasher, typename KeyEqual, typename Alloc>
class F14FastSet
: public f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc> {
using Super = f14::detail::F14BasicSet<Key, Hasher, KeyEqual, Alloc>;
public:
using typename Super::value_type;
F14FastSet() = default;
using Super::Super;
F14FastSet& operator=(std::initializer_list<value_type> ilist) {
Super::operator=(ilist);
return *this;
}
};
} // namespace folly
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment