tree: e40dbb5811ec0d653d01cdb8930ed95968ecdad3 [path history] [tgz]
  1. accounting/
  2. algorithms/
  3. base/
  4. docs/
  5. postgres/
  6. proto/
  7. testing/
  8. .bazelrc
  9. .bazelversion
  10. BUILD
  11. CMakeLists.txt
  12. MODULE.bazel
  13. README.md
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 Build

Bazel

Build the C++ differential privacy library and dependencies using bazelisk (... is a part of the command and not a placeholder):

cd cc
bazelisk build ...

CMake

Note: CMake build is experimental. It was tested on Ubuntu 22.04.

Before building, we need to install dependencies via the following command:

sudo apt install -y cmake protobuf-compiler libssl-dev

To build the library, we need to follow the following steps:

mkdir build
cd build
cmake ..
make -j

To run unit tests:

cd cc
ctest

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: