hash_generator_testing.cc
Go to the documentation of this file.
00001 // Copyright 2018 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #include "absl/container/internal/hash_generator_testing.h"
00016 
00017 #include <deque>
00018 
00019 namespace absl {
00020 namespace container_internal {
00021 namespace hash_internal {
00022 namespace {
00023 
00024 class RandomDeviceSeedSeq {
00025  public:
00026   using result_type = typename std::random_device::result_type;
00027 
00028   template <class Iterator>
00029   void generate(Iterator start, Iterator end) {
00030     while (start != end) {
00031       *start = gen_();
00032       ++start;
00033     }
00034   }
00035 
00036  private:
00037   std::random_device gen_;
00038 };
00039 
00040 }  // namespace
00041 
00042 std::mt19937_64* GetSharedRng() {
00043   RandomDeviceSeedSeq seed_seq;
00044   static auto* rng = new std::mt19937_64(seed_seq);
00045   return rng;
00046 }
00047 
00048 std::string Generator<std::string>::operator()() const {
00049   // NOLINTNEXTLINE(runtime/int)
00050   std::uniform_int_distribution<short> chars(0x20, 0x7E);
00051   std::string res;
00052   res.resize(32);
00053   std::generate(res.begin(), res.end(),
00054                 [&]() { return chars(*GetSharedRng()); });
00055   return res;
00056 }
00057 
00058 absl::string_view Generator<absl::string_view>::operator()() const {
00059   static auto* arena = new std::deque<std::string>();
00060   // NOLINTNEXTLINE(runtime/int)
00061   std::uniform_int_distribution<short> chars(0x20, 0x7E);
00062   arena->emplace_back();
00063   auto& res = arena->back();
00064   res.resize(32);
00065   std::generate(res.begin(), res.end(),
00066                 [&]() { return chars(*GetSharedRng()); });
00067   return res;
00068 }
00069 
00070 }  // namespace hash_internal
00071 }  // namespace container_internal
00072 }  // namespace absl


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:14