Initial import of libdpf.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
commit
e4e666f459
4563 changed files with 1690372 additions and 0 deletions
14
examples/input_types/bitstring.cpp
Normal file
14
examples/input_types/bitstring.cpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include <iostream>
|
||||
#include "dpf.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace dpf::literals;
|
||||
using bits = dpf::bitstring<8>;
|
||||
bits x = 10101001_bitstring;
|
||||
std::cout << (x == bits(0b10101001)) << " " << x.to_string() << "\n";
|
||||
auto [k0, k1] = dpf::make_dpf(x, dpf::bit::one);
|
||||
auto y0 = dpf::eval_point(k0, x);
|
||||
auto y1 = dpf::eval_point(k1, x);
|
||||
std::cout << (static_cast<dpf::bit>(y0) + static_cast<dpf::bit>(y1)) << "\n";
|
||||
}
|
||||
43
examples/input_types/custom.cpp
Normal file
43
examples/input_types/custom.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include "dpf.hpp"
|
||||
|
||||
// Minimal 16-bit input. See test/tests/helpers/custom_input_type.hpp for a
|
||||
// type that also supports interval evaluation.
|
||||
struct input_type
|
||||
{
|
||||
std::uint16_t i{};
|
||||
input_type() = default;
|
||||
explicit constexpr input_type(std::uint16_t v) : i{v} {}
|
||||
input_type operator&(input_type rhs) const { return input_type{static_cast<std::uint16_t>(i & rhs.i)}; }
|
||||
input_type operator&(std::uint64_t rhs) const { return input_type{static_cast<std::uint16_t>(i & rhs)}; }
|
||||
input_type operator>>(std::size_t n) const { return input_type{static_cast<std::uint16_t>(i >> n)}; }
|
||||
input_type & operator>>=(int) { i = static_cast<std::uint16_t>(i >> 1); return *this; }
|
||||
explicit operator bool() const { return i != 0; }
|
||||
};
|
||||
|
||||
namespace dpf::utils
|
||||
{
|
||||
template <> struct bitlength_of<input_type> : std::integral_constant<std::size_t, 16> {};
|
||||
template <> struct msb_of<input_type>
|
||||
{
|
||||
static constexpr input_type value{std::uint16_t{0x8000}};
|
||||
};
|
||||
template <> struct mod_pow_2<input_type>
|
||||
{
|
||||
std::size_t operator()(input_type val, std::size_t n) const noexcept
|
||||
{
|
||||
if (n == 0) return 0;
|
||||
const auto mask = n >= 16 ? 0xffffu : (1u << n) - 1u;
|
||||
return val.i & mask;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
auto [k0, k1] = dpf::make_dpf(input_type{7}, dpf::bit::one);
|
||||
auto y0 = dpf::eval_point(k0, input_type{7});
|
||||
auto y1 = dpf::eval_point(k1, input_type{7});
|
||||
std::cout << (static_cast<dpf::bit>(y0) + static_cast<dpf::bit>(y1)) << "\n";
|
||||
}
|
||||
11
examples/input_types/extended_types.cpp
Normal file
11
examples/input_types/extended_types.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include <iostream>
|
||||
#include "dpf.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
simde_uint128 x = 42;
|
||||
auto [k0, k1] = dpf::make_dpf(x, dpf::bit::one);
|
||||
auto y0 = dpf::eval_point(k0, x);
|
||||
auto y1 = dpf::eval_point(k1, x);
|
||||
std::cout << (static_cast<dpf::bit>(y0) + static_cast<dpf::bit>(y1)) << "\n";
|
||||
}
|
||||
25
examples/input_types/integral_types.cpp
Normal file
25
examples/input_types/integral_types.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include "dpf.hpp"
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
using value_type = int;
|
||||
|
||||
std::vector<value_type> values = {12, 34, 56, 78};
|
||||
|
||||
auto [dpf0, dpf1] = dpf::make_dpf(value_type{56});
|
||||
|
||||
int i=0;
|
||||
value_type res0{};
|
||||
auto [buf0, iter0] = dpf::eval_sequence(dpf0, std::begin(values), std::end(values));
|
||||
for (auto b : iter0) { if (b) res0 ^= values[i]; i++; }
|
||||
|
||||
i=0;
|
||||
value_type res1{};
|
||||
auto [buf1, iter1] = dpf::eval_sequence(dpf1, std::begin(values), std::end(values));
|
||||
for (auto b : iter1) { if (b) res1 ^= values[i]; i++; }
|
||||
|
||||
std::cout << (res0 ^ res1) << "\n";
|
||||
std::cout << values[2] << "\n";
|
||||
}
|
||||
28
examples/input_types/keyword.cpp
Normal file
28
examples/input_types/keyword.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include "dpf.hpp"
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
using keyword_type = dpf::keyword<3, dpf::alphabets::lowercase_alpha>;
|
||||
using value_type = int;
|
||||
|
||||
std::vector<keyword_type> keys = {"cat", "dog", "bat", "pig"};
|
||||
std::vector<value_type> values = {12, 34, 56, 78};
|
||||
|
||||
auto [dpf0, dpf1] = dpf::make_dpf(keyword_type{"bat"});
|
||||
// auto [dpf0, dpf1] = dpf::make_dpf(keyword_type{"rat"}); // key does not exist; result will be 0
|
||||
|
||||
int i=0;
|
||||
value_type res0{};
|
||||
auto [buf0, iter0] = dpf::eval_sequence(dpf0, std::begin(keys), std::end(keys));
|
||||
for (auto b : iter0) { if (b) res0 ^= values[i]; i++; }
|
||||
|
||||
i=0;
|
||||
value_type res1{};
|
||||
auto [buf1, iter1] = dpf::eval_sequence(dpf1, std::begin(keys), std::end(keys));
|
||||
for (auto b : iter1) { if (b) res1 ^= values[i]; i++; }
|
||||
|
||||
std::cout << (res0 ^ res1) << "\n";
|
||||
std::cout << values[2] << "\n";
|
||||
}
|
||||
32
examples/input_types/keyword_int_map.cpp
Normal file
32
examples/input_types/keyword_int_map.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
#include "dpf.hpp"
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
static constexpr char lc[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
using keyword_type = dpf::keyword<3, lc>;
|
||||
using value_type = int;
|
||||
|
||||
std::map<keyword_type, value_type> database{{"cat", 12},
|
||||
{"bat", 34},
|
||||
{"dog", 56},
|
||||
{"pig", 78}};
|
||||
|
||||
keyword_type x = "bat";
|
||||
std::cout << x << std::endl;
|
||||
auto [dpf0, dpf1] = dpf::make_dpf(x);
|
||||
|
||||
value_type share0{}, share1{};
|
||||
auto path0 = dpf::make_basic_path_memoizer(dpf0);
|
||||
auto path1 = dpf::make_basic_path_memoizer(dpf1);
|
||||
for (auto & [key, value] : database)
|
||||
{
|
||||
if (dpf::eval_point(dpf0, key, path0)) {share0 ^= value; std::cout << value << std::endl;}
|
||||
if (dpf::eval_point(dpf1, key, path1)) share1 ^= value;
|
||||
}
|
||||
|
||||
std::cout << share0 << share1 << "\n";
|
||||
std::cout << std::string(x) << "(" << x << ")->" << (share0 ^ share1) << "\n";
|
||||
}
|
||||
26
examples/input_types/modint.cpp
Normal file
26
examples/input_types/modint.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include "dpf.hpp"
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
dpf::modint<10> a(2048); // 2048 % 2^10 = 0
|
||||
dpf::modint<10> b(1026); // 1026 % 2^10 = 2
|
||||
std::cout << a + b << std::endl; // = 2
|
||||
|
||||
dpf::modint<10> c(2051); // 2051 % 2^10 = 3
|
||||
dpf::modint<10> d(1026); // 1026 % 2^10 = 2
|
||||
std::cout << c - d << std::endl; // = 1
|
||||
|
||||
dpf::modint<10> e(2050); // 2050 % 2^10 = 2
|
||||
dpf::modint<10> f(1026); // 1026 % 2^10 = 2
|
||||
std::cout << e * f << std::endl; // = 4
|
||||
|
||||
dpf::modint<10> g(2052); // 2052 % 2^10 = 4
|
||||
dpf::modint<10> h(1026); // 1026 % 2^10 = 2
|
||||
std::cout << g / h << std::endl; // = 2
|
||||
|
||||
dpf::modint<10> i(2048); // 2048 % 2^10 = 0
|
||||
dpf::modint<10> j(1024); // 1024 % 2^10 = 0
|
||||
std::cout << (i == j) << std::endl; // = 1
|
||||
}
|
||||
13
examples/input_types/xor_wrapper.cpp
Normal file
13
examples/input_types/xor_wrapper.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <iostream>
|
||||
#include "dpf.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
using x8 = dpf::xor_wrapper<std::uint8_t>;
|
||||
x8 x{0x3c};
|
||||
auto [k0, k1] = dpf::make_dpf(x, dpf::bit::one);
|
||||
auto y0 = dpf::eval_point(k0, x);
|
||||
auto y1 = dpf::eval_point(k1, x);
|
||||
std::cout << (static_cast<dpf::bit>(y0) + static_cast<dpf::bit>(y1)) << "\n";
|
||||
std::cout << ((++x8{1}) == x8{0}) << "\n";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue