tree: f2c18de8de98fe4ca5b03f1d5ac1a1ea040304dc [path history] [tgz]
  1. accounting/
  2. algorithms/
  3. base/
  4. docs/
  5. postgres/
  6. proto/
  7. testing/
  8. .bazelrc
  9. .bazelversion
  10. BUILD
  11. cc_accounting_deps.bzl
  12. cc_differential_privacy_deps.bzl
  13. README.md
  14. WORKSPACE.bazel
cc/README.md

Differential Privacy library in C++

This is the C++ implementation of the differential privacy library. For general details and key definitions, see the top-level documentation. This document describes C++-specific aspects.

How to Use

Full documentation on how to use the library is in the cpp/docs subdirectory. Here's a minimal example showing how to compute the count of some data:

#include "algorithms/count.h"

// Epsilon is a configurable parameter. A lower value means more privacy but
// less accuracy.
int64_t count(const std::vector<double>& values, double epsilon) {
  // Construct the Count object to run on double inputs.
  std::unique_ptr<differential_privacy::Count<double>> count =
     differential_privacy::Count<double>::Builder().SetEpsilon(epsilon)
                                                   .Build()
                                                   .ValueOrDie();

  // Compute the count and get the result.
  absl::StatusOr<differential_privacy::Output> result =
     count->Result(values.begin(), values.end());
  if (!result.ok()) {
    return 0;
  }

  // GetValue can be used to extract the value from an Output protobuf. For
  // count, this is always an int64_t value.
  return differential_privacy::GetValue<int64_t>(result.ValueOrDie());
}

We also include the following example code: