blob: 7bb264413478fb29583bb0247a176455e76c83f0 [file] [log] [blame]
// 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 {
namespace rappor {
class RapporConfigValidator {
public:
// Constructor for Basic RAPPOR
explicit RapporConfigValidator(const BasicRapporConfig& config);
~RapporConfigValidator() = default;
float prob_0_becomes_1() { return prob_0_becomes_1_; }
float prob_1_stays_1() { return prob_1_stays_1_; }
bool valid() { return valid_; }
uint32_t num_bits() { 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_;
float prob_0_becomes_1_;
float 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 rappor
} // namespace cobalt
#endif // COBALT_SRC_ALGORITHMS_RAPPOR_RAPPOR_CONFIG_VALIDATOR_H_