Commit 74f760d6 authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

switch vectorized and fallback implementation order

Summary:
It's common for people reading the F14 code to
see the fallback implementation without noticing the #if
!FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE at the top, which leads them to
incorrect conclusions about the code. This diff flips the order in the
file to reduce confusion.

Reviewed By: shixiao

Differential Revision: D15571969

fbshipit-source-id: 10d2aa29da3f1b8dd48af490a53f1f845f103fa8
parent 11c136c8
......@@ -38,156 +38,7 @@
#include <folly/container/detail/F14Policy.h>
#include <folly/container/detail/F14Table.h>
#if !FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
//////// Compatibility for unsupported platforms (not x86_64 and not aarch64)
#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
// 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
#else // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
//////// Common case for supported platforms
......@@ -1458,7 +1309,156 @@ bool operator!=(
}
} // namespace folly
#endif // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
#else // !if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
//////// Compatibility for unsupported platforms (not x86_64 and not aarch64)
#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
// 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 {
......
......@@ -35,135 +35,7 @@
#include <folly/container/detail/F14Policy.h>
#include <folly/container/detail/F14Table.h>
#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
// 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
#else // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
//////// Common case for supported platforms
......@@ -1197,7 +1069,135 @@ bool operator!=(
}
} // namespace folly
#endif // FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
#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
// 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
#endif // if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE else
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