c++ implementation of arXiv:1305.1878