[privacy] Remove deprecated *Double and *AsDouble decoding method names
Completes the renaming of some privacy decoding methods.
Now the method names are as they were before fxb/95956,
but numeric values are decoded as doubles rather than
ints.
Bug: 95956
Change-Id: Idc69011d60fa34ac526c3aff25540a5791b76af4
Reviewed-on: https://fuchsia-review.googlesource.com/c/cobalt/+/673202
Fuchsia-Auto-Submit: Laura Peskin <pesk@google.com>
Reviewed-by: Alexandre Zani <azani@google.com>
Commit-Queue: Alexandre Zani <azani@google.com>
diff --git a/src/algorithms/privacy/numeric_encoding.cc b/src/algorithms/privacy/numeric_encoding.cc
index ef35589..61fd085 100644
--- a/src/algorithms/privacy/numeric_encoding.cc
+++ b/src/algorithms/privacy/numeric_encoding.cc
@@ -49,10 +49,6 @@
}
double CountFromIndex(uint64_t index, uint64_t max_count, uint64_t num_index_points) {
- return CountAsDoubleFromIndex(index, max_count, num_index_points);
-}
-
-double CountAsDoubleFromIndex(uint64_t index, uint64_t max_count, uint64_t num_index_points) {
return DoubleFromIndex(index - num_index_points, 0, static_cast<double>(max_count),
num_index_points);
}
@@ -60,14 +56,6 @@
// TODO(fxbug.dev/85571): NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
void HistogramBucketAndCountFromIndex(uint64_t index, uint64_t max_count, uint64_t num_index_points,
uint32_t* bucket_index, double* bucket_count) {
- return HistogramBucketAndCountAsDoubleFromIndex(index, max_count, num_index_points, bucket_index,
- bucket_count);
-}
-
-// TODO(fxbug.dev/85571): NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
-void HistogramBucketAndCountAsDoubleFromIndex(uint64_t index, uint64_t max_count,
- uint64_t num_index_points, uint32_t* bucket_index,
- double* bucket_count) {
*bucket_index = static_cast<uint32_t>(index / num_index_points);
uint64_t numeric_index = index - (*bucket_index * num_index_points);
*bucket_count =
diff --git a/src/algorithms/privacy/numeric_encoding.h b/src/algorithms/privacy/numeric_encoding.h
index 5403093..33fcc8d 100644
--- a/src/algorithms/privacy/numeric_encoding.h
+++ b/src/algorithms/privacy/numeric_encoding.h
@@ -45,27 +45,11 @@
// count.
double CountFromIndex(uint64_t index, uint64_t max_count, uint64_t num_index_points);
-// DEPRECATED: Rename to CountFromIndex() is in progress.
-// TODO(fxbug.dev/95956): Remove once users have switched to the new name.
-//
-// Decodes an |index| that was encoded with CountToIndex, as a double representing an approximate
-// count.
-double CountAsDoubleFromIndex(uint64_t index, uint64_t max_count, uint64_t num_index_points);
-
// Decodes an |index| that was encoded with HistogramBucketAndCountToIndex, decoding the count value
// as a double.
void HistogramBucketAndCountFromIndex(uint64_t index, uint64_t max_count, uint64_t num_index_points,
uint32_t* bucket_index, double* bucket_count);
-// DEPRECATED: Rename to HistogramBucketAndCountFromIndex() is in progress.
-// TODO(fxbug.dev/95956): Remove once users have switched to the new name.
-//
-// Decodes an |index| that was encoded with HistogramBucketAndCountToIndex, decoding the count value
-// as a double.
-void HistogramBucketAndCountAsDoubleFromIndex(uint64_t index, uint64_t max_count,
- uint64_t num_index_points, uint32_t* bucket_index,
- double* bucket_count);
-
// ValueAndEventVectorIndicesToIndex uniquely maps a |value_index|, |event_vector_index| pair to a
// single index.
//
diff --git a/src/algorithms/privacy/numeric_encoding_test.cc b/src/algorithms/privacy/numeric_encoding_test.cc
index cc926dc..c09a078 100644
--- a/src/algorithms/privacy/numeric_encoding_test.cc
+++ b/src/algorithms/privacy/numeric_encoding_test.cc
@@ -141,28 +141,6 @@
}
}
-// TODO(fxbug.dev/95956): Remove once users have switched to the new name.
-TEST(NumericEncodingTest, CountAsDoubleFromIndex) {
- // The approximate counts are all integers.
- uint64_t max_count = 10u;
- uint64_t num_index_points = 6u;
- double expected = 0.0;
-
- for (uint64_t index = num_index_points; index < 2 * num_index_points; index++) {
- EXPECT_THAT(CountAsDoubleFromIndex(index, max_count, num_index_points), DoubleEq(expected));
- expected += 2.0;
- }
-
- // The approximate counts are not all integers.
- num_index_points = 5u;
- expected = 0.0;
-
- for (uint64_t index = num_index_points; index < 2 * num_index_points; index++) {
- EXPECT_THAT(CountAsDoubleFromIndex(index, max_count, num_index_points), DoubleEq(expected));
- expected += 2.5;
- }
-}
-
TEST(NumericEncodingTest, HistogramBucketAndCountFromIndex) {
// The approximate counts are all integers.
uint64_t max_count = 10u;
@@ -210,54 +188,6 @@
}
}
-// TODO(fxbug.dev/95956): Remove once users have switched to the new name.
-TEST(NumericEncodingTest, HistogramBucketAndCountAsDoubleFromIndex) {
- // The approximate counts are all integers.
- uint64_t max_count = 10u;
- uint64_t num_index_points = 6u;
- uint64_t num_buckets = 10u;
-
- double expected_bucket_count = 0.0;
- uint64_t expected_bucket_index = 0u;
-
- for (uint64_t index = 0u; index < num_index_points * num_buckets; ++index) {
- double bucket_count;
- uint32_t bucket_index;
-
- HistogramBucketAndCountAsDoubleFromIndex(index, max_count, num_index_points, &bucket_index,
- &bucket_count);
- EXPECT_EQ(bucket_index, expected_bucket_index);
- EXPECT_THAT(bucket_count, DoubleEq(expected_bucket_count));
-
- expected_bucket_count += 2.0;
- if (expected_bucket_count > static_cast<double>(max_count)) {
- expected_bucket_count = 0.0;
- ++expected_bucket_index;
- }
- }
-
- // The approximate counts are not all integers.
- num_index_points = 5u;
- expected_bucket_count = 0.0;
- expected_bucket_index = 0u;
-
- for (uint64_t index = 0u; index < num_index_points * num_buckets; ++index) {
- double bucket_count;
- uint32_t bucket_index;
-
- HistogramBucketAndCountAsDoubleFromIndex(index, max_count, num_index_points, &bucket_index,
- &bucket_count);
- EXPECT_EQ(bucket_index, expected_bucket_index);
- EXPECT_THAT(bucket_count, DoubleEq(expected_bucket_count));
-
- expected_bucket_count += 2.5;
- if (expected_bucket_count > static_cast<double>(max_count)) {
- expected_bucket_count = 0.0;
- ++expected_bucket_index;
- }
- }
-}
-
TEST(NumericEncodingTest, ValueAndEventVectorIndicesToIndex) {
uint64_t num_index_points = 6;
uint64_t max_event_vector_index = 9;
diff --git a/src/lib/privacy/private_index_decoding.cc b/src/lib/privacy/private_index_decoding.cc
index 039801d..147a739 100644
--- a/src/lib/privacy/private_index_decoding.cc
+++ b/src/lib/privacy/private_index_decoding.cc
@@ -78,20 +78,6 @@
// TODO(fxbug.dev/85571): NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
int64_t min_value, int64_t max_value, uint64_t max_count, uint64_t num_index_points,
std::vector<uint32_t>* event_vector, SumOrCount* sum_or_count) {
- SumOrCountDouble sum_or_count_double;
- CB_RETURN_IF_ERROR(DecodePrivateIndexAsSumOrCountDouble(index, metric_dimensions, min_value,
- max_value, max_count, num_index_points,
- event_vector, &sum_or_count_double));
- CB_ASSIGN_OR_RETURN(*sum_or_count, SumOrCount::FromSumOrCountDouble(sum_or_count_double));
- return Status::OkStatus();
-}
-
-cobalt::Status DecodePrivateIndexAsSumOrCountDouble(
- uint64_t index,
- const google::protobuf::RepeatedPtrField<MetricDefinition::MetricDimension>& metric_dimensions,
- // TODO(fxbug.dev/85571): NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
- int64_t min_value, int64_t max_value, uint64_t max_count, uint64_t num_index_points,
- std::vector<uint32_t>* event_vector, SumOrCountDouble* sum_or_count) {
uint64_t event_vector_index = 0;
uint64_t value_index = 0;
ValueAndEventVectorIndicesFromIndex(index, logger::GetNumEventVectors(metric_dimensions) - 1,
@@ -107,8 +93,8 @@
!validate_value_index.ok()) {
return validate_value_index;
}
- (*sum_or_count).type = SumOrCountDouble::COUNT;
- (*sum_or_count).count = CountAsDoubleFromIndex(value_index, max_count, num_index_points);
+ (*sum_or_count).type = SumOrCount::COUNT;
+ (*sum_or_count).count = CountFromIndex(value_index, max_count, num_index_points);
return Status::OkStatus();
}
@@ -116,7 +102,7 @@
!validate_value_index.ok()) {
return validate_value_index;
}
- (*sum_or_count).type = SumOrCountDouble::SUM;
+ (*sum_or_count).type = SumOrCount::SUM;
(*sum_or_count).sum = DoubleFromIndex(value_index, static_cast<double>(min_value),
static_cast<double>(max_value), num_index_points);
return Status::OkStatus();
@@ -152,17 +138,6 @@
// TODO(fxbug.dev/85571): NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
uint32_t max_bucket_index, uint64_t max_count, uint64_t num_index_points,
std::vector<uint32_t>* event_vector, uint32_t* bucket_index, double* bucket_count) {
- return DecodePrivateIndexAsHistogramBucketIndexAndCountDouble(
- index, metric_dimensions, max_bucket_index, max_count, num_index_points, event_vector,
- bucket_index, bucket_count);
-}
-
-Status DecodePrivateIndexAsHistogramBucketIndexAndCountDouble(
- uint64_t index,
- const google::protobuf::RepeatedPtrField<MetricDefinition::MetricDimension>& metric_dimensions,
- // TODO(fxbug.dev/85571): NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
- uint32_t max_bucket_index, uint64_t max_count, uint64_t num_index_points,
- std::vector<uint32_t>* event_vector, uint32_t* bucket_index, double* bucket_count) {
uint64_t event_vector_index = 0;
uint64_t value_index = 0;
ValueAndEventVectorIndicesFromIndex(index, logger::GetNumEventVectors(metric_dimensions) - 1,
@@ -173,8 +148,8 @@
return decode_event_vector_index;
}
- HistogramBucketAndCountAsDoubleFromIndex(value_index, max_count, num_index_points, bucket_index,
- bucket_count);
+ HistogramBucketAndCountFromIndex(value_index, max_count, num_index_points, bucket_index,
+ bucket_count);
if (Status validate_bucket_index =
ValidateIndexAsHistogramBucketIndex(*bucket_index, max_bucket_index);
!validate_bucket_index.ok()) {
diff --git a/src/lib/privacy/private_index_decoding.h b/src/lib/privacy/private_index_decoding.h
index f449f35..f021c3c 100644
--- a/src/lib/privacy/private_index_decoding.h
+++ b/src/lib/privacy/private_index_decoding.h
@@ -8,24 +8,10 @@
#include <google/protobuf/repeated_field.h>
#include "src/public/lib/status.h"
-#include "src/public/lib/statusor/statusor.h"
#include "src/registry/metric_definition.pb.h"
namespace cobalt {
-// DEPRECATED: Rename to SumOrCount is in progress.
-// TODO(fxbug.dev/95956): Remove once users have switched to the new name.
-//
-// A value which represents either a sum or a count, as a double. Used when decoding observations
-// for FleetwideMeans reports.
-struct SumOrCountDouble {
- enum SumOrCountType { SUM, COUNT };
- SumOrCountType type;
-
- double sum = 0.0;
- double count = 0.0;
-};
-
// A value which represents either an approximate sum or an approximate count, as a double. Used
// when decoding observations for FleetwideMeans reports.
struct SumOrCount {
@@ -34,29 +20,6 @@
double sum = 0;
double count = 0;
-
- // TODO(fxbug.dev/95956): Remove once all users have switched to SumOrCount.
- static lib::statusor::StatusOr<SumOrCount> FromSumOrCountDouble(
- SumOrCountDouble sum_or_count_double) {
- SumOrCount sum_or_count;
-
- switch (sum_or_count_double.type) {
- case SumOrCountDouble::SumOrCountType::SUM: {
- sum_or_count.type = SumOrCount::SumOrCountType::SUM;
- break;
- }
- case SumOrCountDouble::SumOrCountType::COUNT: {
- sum_or_count.type = SumOrCount::SumOrCountType::COUNT;
- break;
- }
- default:
- return Status(StatusCode::INVALID_ARGUMENT, "input SumOrCountDouble has invalid type");
- }
-
- sum_or_count.sum = sum_or_count_double.sum;
- sum_or_count.count = sum_or_count_double.count;
- return sum_or_count;
- }
};
// Populates |event_vector| with the event vector which corresponds to |index| according to the
@@ -92,24 +55,6 @@
int64_t min_value, int64_t max_value, uint64_t max_count, uint64_t num_index_points,
std::vector<uint32_t>* event_vector, SumOrCount* sum_or_count);
-// DEPRECATED: Rename to DecodePrivateIndexAsSumOrCount() is in progress.
-// TODO(fxbug.dev/95956): Remove once users have switched to the new name.
-//
-// Populates |event_vector| and |sum_or_count| with the event vector and SumAndCount which
-// correspond to |index| according to |metric_dimensions|, |min_value|, |max_value|, |max_count| and
-// |num_index_points|, or returns an error status if |index| does not represent a valid
-// (event_vector, sum) or (event_vector, count) pair.
-//
-// After a successful call, |sum_or_count| will be a SumOrCountDouble struct whose |type| field is
-// set to either SUM or COUNT. If the |type| is SUM, then the |sum| field is populated with a double
-// representing a sum; if the |type| is COUNT, then the |count| field is populated with an double
-// representing a count.
-Status DecodePrivateIndexAsSumOrCountDouble(
- uint64_t index,
- const google::protobuf::RepeatedPtrField<MetricDefinition::MetricDimension>& metric_dimensions,
- int64_t min_value, int64_t max_value, uint64_t max_count, uint64_t num_index_points,
- std::vector<uint32_t>* event_vector, SumOrCountDouble* sum_or_count);
-
// Populates |event_vector| and |bucket_index| with the event vector and histogram bucket index
// which correspond to |index| according to |metric_dimensions| and |max_bucket_index|, or returns
// an error status if |index| does not represent a valid (event_vector, bucket_index) pair.
@@ -129,20 +74,6 @@
uint32_t max_bucket_index, uint64_t max_count, uint64_t num_index_points,
std::vector<uint32_t>* event_vector, uint32_t* bucket_index, double* bucket_count);
-// DEPRECATED: Rename to DecodePrivateIndexAsHistogramBucketIndexAndCount() is in progress.
-// TODO(fxbug.dev/95956): Remove once users have switched to the new name.
-//
-// Populates |event_vector|, |bucket_index|, and |bucket_count| with the event vector, histogram
-// bucket index, and bucket count which correspond to |index| according to |metric_dimensions|,
-// |max_bucket_index|, |max_count|, and |num_index_points|, or else returns an error status if
-// |index| does not represent a valid (event_vector, bucket_index, bucket_count) tuple.
-// The bucket count is decoded as a double, without rounding.
-Status DecodePrivateIndexAsHistogramBucketIndexAndCountDouble(
- uint64_t index,
- const google::protobuf::RepeatedPtrField<MetricDefinition::MetricDimension>& metric_dimensions,
- uint32_t max_bucket_index, uint64_t max_count, uint64_t num_index_points,
- std::vector<uint32_t>* event_vector, uint32_t* bucket_index, double* bucket_count);
-
} // namespace cobalt
#endif // COBALT_SRC_LIB_PRIVACY_PRIVATE_INDEX_DECODING_H_
diff --git a/src/lib/privacy/private_index_decoding_test.cc b/src/lib/privacy/private_index_decoding_test.cc
index 9781bdd..88c96dd 100644
--- a/src/lib/privacy/private_index_decoding_test.cc
+++ b/src/lib/privacy/private_index_decoding_test.cc
@@ -179,63 +179,6 @@
EXPECT_FALSE(status.ok());
}
-// TODO(fxbug.dev/95956): Remove once users have switched to the new name.
-TEST_F(PrivateIndexDecodingTest, DecodeAsSumOrCountDoubleValidSum) {
- std::vector<uint32_t> event_vector;
- SumOrCountDouble sum_or_count;
- // Check that the minimum private index that corresponds to a sum is decoded correctly.
- Status status =
- DecodePrivateIndexAsSumOrCountDouble(0, metric_dimensions_, kMinValue, kMaxValue, kMaxCount,
- kNumIndexPoints, &event_vector, &sum_or_count);
- ASSERT_TRUE(status.ok());
- EXPECT_EQ(event_vector, std::vector<uint32_t>({0, 0, 0}));
- EXPECT_EQ(sum_or_count.type, SumOrCountDouble::SUM);
- EXPECT_THAT(sum_or_count.sum, DoubleEq(static_cast<double>(kMinValue)));
-
- // Check that the maximum private index that corresponds to a sum is decoded correctly.
- status = DecodePrivateIndexAsSumOrCountDouble(MaxIndexForNumericValue(), metric_dimensions_,
- kMinValue, kMaxValue, kMaxCount, kNumIndexPoints,
- &event_vector, &sum_or_count);
- ASSERT_TRUE(status.ok());
- EXPECT_EQ(event_vector, std::vector<uint32_t>({2, 300, 10}));
- EXPECT_EQ(sum_or_count.type, SumOrCountDouble::SUM);
- EXPECT_THAT(sum_or_count.sum, DoubleEq(static_cast<double>(kMaxValue)));
-}
-
-// TODO(fxbug.dev/95956): Remove once users have switched to the new name.
-TEST_F(PrivateIndexDecodingTest, DecodeAsSumOrCountDoubleValidCount) {
- std::vector<uint32_t> event_vector;
- SumOrCountDouble sum_or_count;
- // Check that the minimum private index that corresponds to a count is decoded correctly.
- Status status = DecodePrivateIndexAsSumOrCountDouble(
- MinIndexForCount(), metric_dimensions_, kMinValue, kMaxValue, kMaxCount, kNumIndexPoints,
- &event_vector, &sum_or_count);
- ASSERT_TRUE(status.ok());
- EXPECT_EQ(event_vector, std::vector<uint32_t>({0, 0, 0}));
- EXPECT_EQ(sum_or_count.type, SumOrCountDouble::COUNT);
- EXPECT_THAT(sum_or_count.count, DoubleEq(0.0));
-
- // Check that the maximum private index that corresponds to a count is decoded correctly.
- status = DecodePrivateIndexAsSumOrCountDouble(MaxIndexForCount(), metric_dimensions_, kMinValue,
- kMaxValue, kMaxCount, kNumIndexPoints,
- &event_vector, &sum_or_count);
- ASSERT_TRUE(status.ok());
- EXPECT_EQ(event_vector, std::vector<uint32_t>({2, 300, 10}));
- EXPECT_EQ(sum_or_count.type, SumOrCountDouble::COUNT);
- EXPECT_THAT(sum_or_count.count, DoubleEq(static_cast<double>(kMaxCount)));
-}
-
-// TODO(fxbug.dev/95956): Remove once users have switched to the new name.
-TEST_F(PrivateIndexDecodingTest, DecodeAsSumOrCountDoubleInvalid) {
- std::vector<uint32_t> event_vector;
- SumOrCountDouble sum_or_count;
-
- Status status = DecodePrivateIndexAsSumOrCountDouble(
- MaxIndexForCount() + 1, metric_dimensions_, kMinValue, kMaxValue, kMaxCount, kNumIndexPoints,
- &event_vector, &sum_or_count);
- EXPECT_FALSE(status.ok());
-}
-
TEST_F(PrivateIndexDecodingTest, DecodeAsHistogramBucketIndexValid) {
std::vector<uint32_t> event_vector;
uint32_t bucket_index;
@@ -299,40 +242,4 @@
ASSERT_FALSE(status.ok());
}
-// TODO(fxbug.dev/95956): Remove once users have switched to the new name.
-TEST_F(PrivateIndexDecodingTest, DecodeAsHistogramBucketIndexAndCountDoubleValid) {
- std::vector<uint32_t> event_vector;
- uint32_t bucket_index;
- double bucket_count;
- // Check that the minimum private index is decoded correctly.
- Status status = DecodePrivateIndexAsHistogramBucketIndexAndCountDouble(
- 0, metric_dimensions_, kMaxBucketIndex, kMaxCount, kNumIndexPoints, &event_vector,
- &bucket_index, &bucket_count);
- ASSERT_TRUE(status.ok());
- EXPECT_EQ(event_vector, std::vector<uint32_t>({0, 0, 0}));
- EXPECT_EQ(bucket_index, 0u);
- EXPECT_THAT(bucket_count, DoubleEq(0.0));
-
- // Check that the maximum private index is decoded correctly.
- status = DecodePrivateIndexAsHistogramBucketIndexAndCountDouble(
- MaxIndexForHistogramBucketAndCount(), metric_dimensions_, kMaxBucketIndex, kMaxCount,
- kNumIndexPoints, &event_vector, &bucket_index, &bucket_count);
- ASSERT_TRUE(status.ok());
- EXPECT_EQ(event_vector, std::vector<uint32_t>({2, 300, 10}));
- EXPECT_EQ(bucket_index, kMaxBucketIndex);
- EXPECT_THAT(bucket_count, DoubleEq(static_cast<double>(kMaxCount)));
-}
-
-// TODO(fxbug.dev/95956): Remove once users have switched to the new name.
-TEST_F(PrivateIndexDecodingTest, DecodeAsHistogramBucketIndexAndCountDoubleInvalid) {
- std::vector<uint32_t> event_vector;
- uint32_t bucket_index;
- double bucket_count;
-
- Status status = DecodePrivateIndexAsHistogramBucketIndexAndCountDouble(
- MaxIndexForHistogramBucketAndCount() + 1, metric_dimensions_, kMaxBucketIndex, kMaxCount,
- kNumIndexPoints, &event_vector, &bucket_index, &bucket_count);
- ASSERT_FALSE(status.ok());
-}
-
} // namespace cobalt