heap.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef __HEAP_HPP__
  2. #define __HEAP_HPP__
  3. #include "types.hpp"
  4. #include "mpcio.hpp"
  5. #include "coroutine.hpp"
  6. #include "options.hpp"
  7. #include "mpcops.hpp"
  8. class MinHeap {
  9. private:
  10. Duoram < RegAS > oram;
  11. size_t MAX_SIZE;
  12. size_t num_items;
  13. public:
  14. MinHeap(int player_num, size_t size) : oram(player_num, size) {};
  15. // The extractmin protocol returns the minimum element (the root), removes it
  16. // and restores the heap property
  17. // and takes in a boolean parameter to decide if the basic or the optimized version needs to be run
  18. RegAS extract_min(MPCIO &mpcio, MPCTIO tio, yield_t & yield, int is_optimized);
  19. // Intializes the heap array with 0x7fffffffffffff
  20. void init(MPCTIO tio, yield_t & yield);
  21. // This function simply inits a heap with values 1,2,...,n
  22. // We use this function only to set up our heap
  23. // to do timing experiments on insert and extractmins
  24. void init(MPCTIO tio, yield_t & yield, size_t n);
  25. // The Basic Insert Protocol
  26. // Takes in the additive share of the value to be inserted
  27. // And adds the the value into the heap while keeping the heap property intact
  28. int insert(MPCTIO tio, yield_t & yield, RegAS val);
  29. // The Optimized Insert Protocol
  30. // Takes in the additive share of the value to be inserted
  31. // And adds the the value into the heap while keeping the heap property intact
  32. void insert_optimized(MPCTIO tio, yield_t & yield, RegAS val);
  33. // Note: This function is intended for testing purposes only.
  34. // The purpose of this function is to verify that the heap property is satisfied.
  35. void verify_heap_property(MPCTIO tio, yield_t & yield);
  36. // Basic restore heap property at a secret shared index
  37. RegXS restore_heap_property(MPCIO &mpcio, MPCTIO tio, yield_t & yield, RegXS index);
  38. // Optimized restore heap property at a secret shared index
  39. std::pair<RegXS, RegBS> restore_heap_property_optimized(MPCTIO tio, yield_t & yield, RegXS index, size_t layer, typename Duoram<RegAS>::template OblivIndex<RegXS,3> oidx);
  40. // Restore heap property at an index in clear
  41. std::pair<RegXS, RegBS> restore_heap_property_at_explicit_index(MPCTIO tio, yield_t & yield, size_t index);
  42. // Prints the current heap
  43. void print_heap(MPCTIO tio, yield_t & yield);
  44. };
  45. void Heap(MPCIO &mpcio, const PRACOptions &opts, char **args);
  46. #endif