Roll external/abseil_cpp/ 8f739d18b..917bfee46 (2 commits) (#5887)
[KhronosGroup/SPIRV-Tools.git] / source / fuzz / counter_overflow_id_source.h
blob852bbd0709a87de110384a13924039f1bf464d78
1 // Copyright (c) 2020 Google LLC
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 // http://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.
15 #ifndef SOURCE_FUZZ_COUNTER_OVERFLOW_ID_SOURCE_H_
16 #define SOURCE_FUZZ_COUNTER_OVERFLOW_ID_SOURCE_H_
18 #include "source/fuzz/overflow_id_source.h"
20 namespace spvtools {
21 namespace fuzz {
23 // A source of overflow ids that uses a counter to provide successive ids from
24 // a given starting value.
25 class CounterOverflowIdSource : public OverflowIdSource {
26 public:
27 // |first_available_id| is the starting value for the counter.
28 explicit CounterOverflowIdSource(uint32_t first_available_id);
30 // Always returns true.
31 bool HasOverflowIds() const override;
33 // Returns the current counter value and increments the counter.
34 // TODO(https://github.com/KhronosGroup/SPIRV-Tools/issues/2541) We should
35 // account for the case where the maximum allowed id is reached.
36 uint32_t GetNextOverflowId() override;
38 const std::unordered_set<uint32_t>& GetIssuedOverflowIds() const override;
40 private:
41 uint32_t next_available_id_;
43 std::unordered_set<uint32_t> issued_ids_;
46 } // namespace fuzz
47 } // namespace spvtools
49 #endif // SOURCE_FUZZ_OVERFLOW_ID_SOURCE_COUNTER_H_