heap.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // Basic restore heap property at a secret shared index
  14. RegXS restore_heap_property(MPCIO &mpcio, MPCTIO tio, yield_t & yield, RegXS index);
  15. // Optimized restore heap property at a secret shared index
  16. 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);
  17. // Restore heap property at an index in clear
  18. std::pair<RegXS, RegBS> restore_heap_property_at_explicit_index(MPCTIO tio, yield_t & yield, size_t index);
  19. public:
  20. MinHeap(int player_num, size_t size) : oram(player_num, size) {};
  21. // The extractmin protocol returns the minimum element (the root), removes it
  22. // and restores the heap property
  23. // and takes in a boolean parameter to decide if the basic or the optimized version needs to be run
  24. RegAS extract_min(MPCIO &mpcio, MPCTIO tio, yield_t & yield, int is_optimized);
  25. // Intializes the heap array with 0x7fffffffffffff
  26. void init(MPCTIO tio, yield_t & yield);
  27. // This function simply inits a heap with values 100,200,...,100*n
  28. // We use this function only to set up our heap
  29. // to do timing experiments on insert and extractmins
  30. void init(MPCTIO tio, yield_t & yield, size_t n);
  31. // The Basic Insert Protocol
  32. // Takes in the additive share of the value to be inserted
  33. // And adds the the value into the heap while keeping the heap property intact
  34. void insert(MPCTIO tio, yield_t & yield, RegAS val);
  35. // The Optimized Insert Protocol
  36. // Takes in the additive share of the value to be inserted
  37. // And adds the the value into the heap while keeping the heap property intact
  38. void insert_optimized(MPCTIO tio, yield_t & yield, RegAS val);
  39. // Note: This function is intended for testing purposes only.
  40. // The purpose of this function is to verify that the heap property is satisfied.
  41. void verify_heap_property(MPCTIO tio, yield_t & yield);
  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