diff options
author | Evan Brown <ezb@google.com> | 2023-09-15 09:05:25 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-09-15 09:06:19 -0700 |
commit | 49be2e68de5b063bce5d0757078c62906a2674ea (patch) | |
tree | 00680ea209b60588f6f7c249fcdc2c7746a9c195 /absl/container/internal/raw_hash_set_test.cc | |
parent | e68f1412e2cebdd5af106721007335ca45d51f83 (diff) | |
download | abseil-49be2e68de5b063bce5d0757078c62906a2674ea.tar.gz abseil-49be2e68de5b063bce5d0757078c62906a2674ea.tar.bz2 abseil-49be2e68de5b063bce5d0757078c62906a2674ea.zip |
Move CountingAllocator into test_allocator.h and add some other allocators that can be shared between different container tests.
PiperOrigin-RevId: 565693736
Change-Id: I59af987e30da03a805ce59ff0fb7eeae3fc08293
Diffstat (limited to 'absl/container/internal/raw_hash_set_test.cc')
-rw-r--r-- | absl/container/internal/raw_hash_set_test.cc | 29 |
1 files changed, 1 insertions, 28 deletions
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 55c6f62e..7588120a 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc @@ -48,6 +48,7 @@ #include "absl/container/internal/hash_function_defaults.h" #include "absl/container/internal/hash_policy_testing.h" #include "absl/container/internal/hashtable_debug.h" +#include "absl/container/internal/test_allocator.h" #include "absl/log/log.h" #include "absl/strings/string_view.h" @@ -441,34 +442,6 @@ struct CustomAllocIntTable using Base::Base; }; -// Tries to allocate memory at the minimum alignment even when the default -// allocator uses a higher alignment. -template <typename T> -struct MinimumAlignmentAlloc : std::allocator<T> { - MinimumAlignmentAlloc() = default; - - template <typename U> - explicit MinimumAlignmentAlloc(const MinimumAlignmentAlloc<U>& /*other*/) {} - - template <class U> - struct rebind { - using other = MinimumAlignmentAlloc<U>; - }; - - T* allocate(size_t n) { - T* ptr = std::allocator<T>::allocate(n + 1); - char* cptr = reinterpret_cast<char*>(ptr); - cptr += alignof(T); - return reinterpret_cast<T*>(cptr); - } - - void deallocate(T* ptr, size_t n) { - char* cptr = reinterpret_cast<char*>(ptr); - cptr -= alignof(T); - std::allocator<T>::deallocate(reinterpret_cast<T*>(cptr), n + 1); - } -}; - struct MinimumAlignmentUint8Table : raw_hash_set<Uint8Policy, container_internal::hash_default_hash<uint8_t>, std::equal_to<uint8_t>, MinimumAlignmentAlloc<uint8_t>> { |