google / private-join-and-compute

Apache License 2.0
792 stars 138 forks source link

Wrapper library with simple interface #6

Closed mortendahl closed 3 years ago

mortendahl commented 5 years ago

This PR adds a small wrapper on top of the existing code to make it easier to use as an external library in other projects. In particular, the dependencies are reduced to standard libraries as illustrated in the included demo:

#include <iostream>
#include <memory>
#include <string>
#include <vector>

#include "private_join_and_compute.h"

int main(int argc, char** argv) {
  std::vector<std::string> elements { "a", "b", "c" };
  std::vector<int64_t> values { 1, 2, 3 };

  ::private_join_and_compute::ClientSession session;
  ::private_join_and_compute::ClientResult result;

  int res = session.Run(1536, "0.0.0.0:10501",
      std::move(elements),
      std::move(values),
      &result);

  if (res == 0) {
    std::cout << "Client: Done, "
              << "size: " << result.intersection_size << ", "
              << "sum: " << result.intersection_sum
              << std::endl;
  }
}

One open question is whether absl::Notifcation is the best synchronization mechanism, not least since it's currently causing some trouble when using the library in a TensorFlow custom-op; as a work-around I've switched to using WaitForNotificationWithTimeout in a loop.