hash_generator_testing.cc
Go to the documentation of this file.
1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <deque>
18 
19 namespace absl {
20 namespace container_internal {
21 namespace hash_internal {
22 namespace {
23 
24 class RandomDeviceSeedSeq {
25  public:
26  using result_type = typename std::random_device::result_type;
27 
28  template <class Iterator>
29  void generate(Iterator start, Iterator end) {
30  while (start != end) {
31  *start = gen_();
32  ++start;
33  }
34  }
35 
36  private:
37  std::random_device gen_;
38 };
39 
40 } // namespace
41 
42 std::mt19937_64* GetSharedRng() {
43  RandomDeviceSeedSeq seed_seq;
44  static auto* rng = new std::mt19937_64(seed_seq);
45  return rng;
46 }
47 
49  // NOLINTNEXTLINE(runtime/int)
50  std::uniform_int_distribution<short> chars(0x20, 0x7E);
51  std::string res;
52  res.resize(32);
53  std::generate(res.begin(), res.end(),
54  [&]() { return chars(*GetSharedRng()); });
55  return res;
56 }
57 
59  static auto* arena = new std::deque<std::string>();
60  // NOLINTNEXTLINE(runtime/int)
61  std::uniform_int_distribution<short> chars(0x20, 0x7E);
62  arena->emplace_back();
63  auto& res = arena->back();
64  res.resize(32);
65  std::generate(res.begin(), res.end(),
66  [&]() { return chars(*GetSharedRng()); });
67  return res;
68 }
69 
70 } // namespace hash_internal
71 } // namespace container_internal
72 } // namespace absl
char * end
Definition: algorithm.h:29
std::random_device gen_
LowLevelAlloc::Arena * arena


abseil_cpp
Author(s):
autogenerated on Mon Feb 28 2022 21:31:18