abseil-cpp/absl/random/internal/explicit_seed_seq.h
Go to the documentation of this file.
1 // Copyright 2017 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 
15 #ifndef ABSL_RANDOM_INTERNAL_EXPLICIT_SEED_SEQ_H_
16 #define ABSL_RANDOM_INTERNAL_EXPLICIT_SEED_SEQ_H_
17 
18 #include <algorithm>
19 #include <cstddef>
20 #include <cstdint>
21 #include <initializer_list>
22 #include <iterator>
23 #include <vector>
24 
25 #include "absl/base/config.h"
26 #include "absl/base/internal/endian.h"
27 
28 namespace absl {
30 namespace random_internal {
31 
32 // This class conforms to the C++ Standard "Seed Sequence" concept
33 // [rand.req.seedseq].
34 //
35 // An "ExplicitSeedSeq" is meant to provide a conformant interface for
36 // forwarding pre-computed seed material to the constructor of a class
37 // conforming to the "Uniform Random Bit Generator" concept. This class makes no
38 // attempt to mutate the state provided by its constructor, and returns it
39 // directly via ExplicitSeedSeq::generate().
40 //
41 // If this class is asked to generate more seed material than was provided to
42 // the constructor, then the remaining bytes will be filled with deterministic,
43 // nonrandom data.
45  public:
47 
49 
50  // Copy and move both allowed.
51  ExplicitSeedSeq(const ExplicitSeedSeq& other) = default;
52  ExplicitSeedSeq& operator=(const ExplicitSeedSeq& other) = default;
53  ExplicitSeedSeq(ExplicitSeedSeq&& other) = default;
54  ExplicitSeedSeq& operator=(ExplicitSeedSeq&& other) = default;
55 
56  template <typename Iterator>
58  for (auto it = begin; it != end; it++) {
59  state_.push_back(*it & 0xffffffff);
60  }
61  }
62 
63  template <typename T>
64  ExplicitSeedSeq(std::initializer_list<T> il)
65  : ExplicitSeedSeq(il.begin(), il.end()) {}
66 
67  size_t size() const { return state_.size(); }
68 
69  template <typename OutIterator>
70  void param(OutIterator out) const {
72  }
73 
74  template <typename OutIterator>
75  void generate(OutIterator begin, OutIterator end) {
76  for (size_t index = 0; begin != end; begin++) {
77  *begin = state_.empty() ? 0 : state_[index++];
78  if (index >= state_.size()) {
79  index = 0;
80  }
81  }
82  }
83 
84  protected:
85  std::vector<uint32_t> state_;
86 };
87 
88 } // namespace random_internal
90 } // namespace absl
91 
92 #endif // ABSL_RANDOM_INTERNAL_EXPLICIT_SEED_SEQ_H_
absl::random_internal::ExplicitSeedSeq::operator=
ExplicitSeedSeq & operator=(const ExplicitSeedSeq &other)=default
regen-readme.it
it
Definition: regen-readme.py:15
absl::random_internal::ExplicitSeedSeq::result_type
uint32_t result_type
Definition: abseil-cpp/absl/random/internal/explicit_seed_seq.h:46
absl::random_internal::ExplicitSeedSeq::state_
std::vector< uint32_t > state_
Definition: abseil-cpp/absl/random/internal/explicit_seed_seq.h:85
begin
char * begin
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1007
copy
static int copy(grpc_slice_buffer *input, grpc_slice_buffer *output)
Definition: message_compress.cc:145
absl::random_internal::ExplicitSeedSeq
Definition: abseil-cpp/absl/random/internal/explicit_seed_seq.h:44
absl::random_internal::ExplicitSeedSeq::generate
void generate(OutIterator begin, OutIterator end)
Definition: abseil-cpp/absl/random/internal/explicit_seed_seq.h:75
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
absl::random_internal::ExplicitSeedSeq::ExplicitSeedSeq
ExplicitSeedSeq()
Definition: abseil-cpp/absl/random/internal/explicit_seed_seq.h:48
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
absl::random_internal::ExplicitSeedSeq::ExplicitSeedSeq
ExplicitSeedSeq(std::initializer_list< T > il)
Definition: abseil-cpp/absl/random/internal/explicit_seed_seq.h:64
absl::inlined_vector_internal::Iterator
Pointer< A > Iterator
Definition: abseil-cpp/absl/container/internal/inlined_vector.h:64
absl::random_internal::ExplicitSeedSeq::size
size_t size() const
Definition: abseil-cpp/absl/random/internal/explicit_seed_seq.h:67
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
absl::out
char * out
Definition: abseil-cpp/absl/synchronization/mutex.h:1048
absl::random_internal::ExplicitSeedSeq::ExplicitSeedSeq
ExplicitSeedSeq(Iterator begin, Iterator end)
Definition: abseil-cpp/absl/random/internal/explicit_seed_seq.h:57
absl::random_internal::ExplicitSeedSeq::param
void param(OutIterator out) const
Definition: abseil-cpp/absl/random/internal/explicit_seed_seq.h:70


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:20