| // Copyright 2016 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef COBALT_SRC_ALGORITHMS_RAPPOR_RAPPOR_CONFIG_VALIDATOR_H_ |
| #define COBALT_SRC_ALGORITHMS_RAPPOR_RAPPOR_CONFIG_VALIDATOR_H_ |
| |
| #include <map> |
| #include <string> |
| #include <utility> |
| #include <vector> |
| |
| #include "src/algorithms/rappor/rappor_config.h" |
| #include "src/pb/observation.pb.h" |
| |
| namespace cobalt::rappor { |
| |
| class RapporConfigValidator { |
| public: |
| // Constructor for Basic RAPPOR |
| explicit RapporConfigValidator(const BasicRapporConfig& config); |
| |
| ~RapporConfigValidator() = default; |
| |
| [[nodiscard]] Prob0Becomes1 prob_0_becomes_1() const { return prob_0_becomes_1_; } |
| |
| [[nodiscard]] Prob1Stays1 prob_1_stays_1() const { return prob_1_stays_1_; } |
| |
| [[nodiscard]] bool valid() const { return valid_; } |
| |
| [[nodiscard]] uint32_t num_bits() const { return num_bits_; } |
| |
| // Returns the bit-index of |category| or -1 if |category| is not one of the |
| // basic RAPPOR categories. |
| int bit_index(const ValuePart& category); |
| |
| // Gives access to the vector of Categories if this object was initialized |
| // with a BasicRapporConfig. |
| std::vector<ValuePart>& categories() { return categories_; } |
| |
| private: |
| friend class RapporConfigValidatorTest_TestMinPower2Above_Test; |
| |
| // Returns the least power of 2 greater than or equal to x. |
| static uint32_t MinPower2Above(uint16_t x); |
| |
| bool valid_; |
| Prob0Becomes1 prob_0_becomes_1_; |
| Prob1Stays1 prob_1_stays_1_; |
| uint32_t num_bits_; |
| |
| // Used only in Basic RAPPOR. |categories_| is the list of all |
| // categories. The keys to |category_to_bit_index_| are serialized |
| // ValueParts. |
| std::map<std::string, size_t> category_to_bit_index_; |
| std::vector<ValuePart> categories_; |
| }; |
| |
| } // namespace cobalt::rappor |
| |
| #endif // COBALT_SRC_ALGORITHMS_RAPPOR_RAPPOR_CONFIG_VALIDATOR_H_ |