Skip to content

Commit

Permalink
Export of internal Abseil changes.
Browse files Browse the repository at this point in the history
--
6fdf24a197b964f9bacbebd0ceca305aef1654fc by Shaindel Schwartz <[email protected]>:

Internal change

PiperOrigin-RevId: 231627312

--
65f7faf52bff01384171efb85fee159378dedf70 by CJ Johnson <[email protected]>:

Relocates the definitions of the InputIterator-accepting parts of the InlinedVector API into the top-level. The removed functions had no other callers so there was no reason to keep the layer of indirection in the form of the function call.

PiperOrigin-RevId: 231527459

--
30e105b749b5ecc50fdaf26c7da589617efce425 by CJ Johnson <[email protected]>:

Relocates closing brace for absl namespace in InlinedVector to the correct end location

PiperOrigin-RevId: 231477871

--
063c1e8b9d1f032662c46d574e20ecc357b87d0c by Eric Fiselier <[email protected]>:

Cleanup std::hash probing metafunctions.

Previously there were two different ways to probe for
std::hash. One in hash.h and another in type_traits.h,
and they were both implemented differently, and neither
correctly worked around bad STL implementations.

This patch unifies the implementations into a single IsHashable trait.
It also:

* Correctly checks for old libc++ versions where this won't work.
* Avoids undefined behavior which resulted from calling std::is_constructible
  incomplete types.
* Unifies the feature test macro used in the headers and the tests.

Additionally it also slightly changes the behavior of when absl::variant
is hashable. Previously we disable hashing when std::hash<T>()(key) was
formed but when std::hash<T> couldn't be destructed. This seems wrong. If a
user provides a evil specialization of std::hash, then it's OK for variant's
hash to blow up.

PiperOrigin-RevId: 231468345

--
05d75dd4b07c893de9b104731644d0d207b01253 by Abseil Team <[email protected]>:

Import of CCTZ from GitHub.

PiperOrigin-RevId: 231397518

--
a0ee9032f9e04039f3410ed17fcf45ae1a3868f5 by CJ Johnson <[email protected]>:

Remove unused EnableIfAtLeastInputIterator from InlinedVector

PiperOrigin-RevId: 231348903

--
4dcd4e9a6780a81d7a6974c7bf22a037e6482b49 by Abseil Team <[email protected]>:

Remove unnecessary register keyword from absl/base/internal/endian.h.

PiperOrigin-RevId: 231316570

--
c8584836caa3a10f90a8604a85d4b831310b72ee by Abseil Team <[email protected]>:

Fix hashtablez_sampler compilation on older Android NDK builds

PiperOrigin-RevId: 231283542
GitOrigin-RevId: 6fdf24a197b964f9bacbebd0ceca305aef1654fc
Change-Id: I185b12fb8347e3ad0ffcb2cbb83a53450e5eb938
  • Loading branch information
Abseil Team authored and ahedberg committed Jan 30, 2019
1 parent 540e253 commit a4cb1c8
Show file tree
Hide file tree
Showing 13 changed files with 435 additions and 118 deletions.
2 changes: 1 addition & 1 deletion absl/base/internal/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ inline uint64_t gbswap_64(uint64_t host_int) {
if (__builtin_constant_p(host_int)) {
return __bswap_constant_64(host_int);
} else {
register uint64_t result;
uint64_t result;
__asm__("bswap %0" : "=r"(result) : "0"(host_int));
return result;
}
Expand Down
1 change: 0 additions & 1 deletion absl/base/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
// This code is compiled directly on many platforms, including client
// platforms like Windows, Mac, and embedded systems. Before making
// any changes here, make sure that you're not breaking any platforms.
//

#ifndef ABSL_BASE_MACROS_H_
#define ABSL_BASE_MACROS_H_
Expand Down
62 changes: 15 additions & 47 deletions absl/container/inlined_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,11 @@ class InlinedVector {
return static_cast<typename A::size_type>(N);
}

template <typename Iterator>
using IsAtLeastInputIterator = std::is_convertible<
typename std::iterator_traits<Iterator>::iterator_category,
std::input_iterator_tag>;

template <typename Iterator>
using IsAtLeastForwardIterator = std::is_convertible<
typename std::iterator_traits<Iterator>::iterator_category,
std::forward_iterator_tag>;

template <typename Iterator>
using EnableIfAtLeastInputIterator =
absl::enable_if_t<IsAtLeastInputIterator<Iterator>::value>;

template <typename Iterator>
using EnableIfAtLeastForwardIterator =
absl::enable_if_t<IsAtLeastForwardIterator<Iterator>::value>;
Expand Down Expand Up @@ -163,7 +154,7 @@ class InlinedVector {
InlinedVector(InputIterator first, InputIterator last,
const allocator_type& alloc = allocator_type())
: allocator_and_tag_(alloc) {
AppendInputRange(first, last);
std::copy(first, last, std::back_inserter(*this));
}

// Creates a copy of `other` using `other`'s allocator.
Expand Down Expand Up @@ -534,7 +525,13 @@ class InlinedVector {
template <typename InputIterator,
DisableIfAtLeastForwardIterator<InputIterator>* = nullptr>
void assign(InputIterator first, InputIterator last) {
AssignInputRange(first, last);
size_type assign_index = 0;
for (; (assign_index < size()) && (first != last);
static_cast<void>(++assign_index), static_cast<void>(++first)) {
*(data() + assign_index) = *first;
}
erase(data() + assign_index, data() + size());
std::copy(first, last, std::back_inserter(*this));
}

// `InlinedVector::resize()`
Expand Down Expand Up @@ -630,7 +627,12 @@ class InlinedVector {
template <typename InputIterator,
DisableIfAtLeastForwardIterator<InputIterator>* = nullptr>
iterator insert(const_iterator pos, InputIterator first, InputIterator last) {
return InsertWithInputRange(pos, first, last);
size_type initial_insert_index = std::distance(cbegin(), pos);
for (size_type insert_index = initial_insert_index; first != last;
static_cast<void>(++insert_index), static_cast<void>(++first)) {
insert(data() + insert_index, *first);
}
return iterator(data() + initial_insert_index);
}

// `InlinedVector::emplace()`
Expand Down Expand Up @@ -1131,20 +1133,6 @@ class InlinedVector {
}
}

template <typename InputIterator>
void AssignInputRange(InputIterator first, InputIterator last) {
static_assert(IsAtLeastInputIterator<InputIterator>::value, "");

// Optimized to avoid reallocation.
// Prefer reassignment to copy construction for elements.
iterator out = begin();
for (; first != last && out != end(); ++first, ++out) {
*out = *first;
}
erase(out, end());
std::copy(first, last, std::back_inserter(*this));
}

template <typename ForwardIterator>
void AppendForwardRange(ForwardIterator first, ForwardIterator last) {
static_assert(IsAtLeastForwardIterator<ForwardIterator>::value, "");
Expand All @@ -1160,13 +1148,6 @@ class InlinedVector {
}
}

template <typename InputIterator>
void AppendInputRange(InputIterator first, InputIterator last) {
static_assert(IsAtLeastInputIterator<InputIterator>::value, "");

std::copy(first, last, std::back_inserter(*this));
}

iterator InsertWithCount(const_iterator position, size_type n,
const_reference v) {
assert(position >= begin() && position <= end());
Expand Down Expand Up @@ -1198,18 +1179,6 @@ class InlinedVector {
return it_pair.first;
}

template <typename InputIterator>
iterator InsertWithInputRange(const_iterator position, InputIterator first,
InputIterator last) {
static_assert(IsAtLeastInputIterator<InputIterator>::value, "");
assert(position >= begin() && position <= end());

size_type index = position - cbegin();
size_type i = index;
while (first != last) insert(begin() + i++, *first++);
return begin() + index;
}

void SwapImpl(InlinedVector& other) {
using std::swap; // Augment ADL with `std::swap`.

Expand Down Expand Up @@ -1393,13 +1362,12 @@ auto AbslHashValue(H h, const InlinedVector<TheT, TheN, TheA>& v) -> H {
auto n = v.size();
return H::combine(H::combine_contiguous(std::move(h), p, n), n);
}
} // namespace absl

// -----------------------------------------------------------------------------
// Implementation of InlinedVector
//
// Do not depend on any below implementation details!
// -----------------------------------------------------------------------------

} // namespace absl

#endif // ABSL_CONTAINER_INLINED_VECTOR_H_
2 changes: 1 addition & 1 deletion absl/container/internal/hashtablez_sampler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int64_t GetGeometricVariable(int64_t mean) {
// under piii debug for some binaries.
double q = static_cast<uint32_t>(rng >> (prng_mod_power - 26)) + 1.0;
// Put the computed p-value through the CDF of a geometric.
double interval = (std::log2(q) - 26) * (-std::log(2.0) * mean);
double interval = (log2(q) - 26) * (-std::log(2.0) * mean);

// Very large values of interval overflow int64_t. If we happen to
// hit such improbable condition, we simply cheat and clamp interval
Expand Down
Loading

0 comments on commit a4cb1c8

Please sign in to comment.