heap.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. };
  16. void set_num_items (size_t n) {num_items = n;}
  17. // The extractmin protocol returns the minimum element (the root), removes it
  18. // and restores the heap property
  19. // and takes in a boolean parameter to decide if the basic or the optimized version needs to be run
  20. RegAS extract_min(MPCIO &mpcio, MPCTIO tio, yield_t & yield, int is_optimized);
  21. // Intializes the heap array with 0x7fffffffffffff
  22. void init(MPCTIO tio, yield_t & yield);
  23. // This function simply inits a heap with values 1,2,...,n
  24. // We use this function only to setup our heap
  25. // to do timing experiments on insert and extractmins
  26. void init(MPCTIO tio, yield_t & yield, size_t which_init);
  27. // The Basic Insert Protocol
  28. // Takes in the additive share of the value to be inserted
  29. // And adds the the value into the heap while keeping the heap property intact
  30. int insert(MPCTIO tio, yield_t & yield, RegAS val);
  31. // The Optimized 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_optimized(MPCTIO tio, yield_t & yield, RegAS val);
  35. // Note: This function is intended for testing purposes only.
  36. // The purpose of this function is to verify that the heap property is satisfied.
  37. void verify_heap_property(MPCTIO tio, yield_t & yield);
  38. // Basic restore heap property at a secret shared index
  39. RegXS restore_heap_property(MPCIO &mpcio, MPCTIO tio, yield_t & yield, RegXS index);
  40. // Optimized restore heap property at a secret shared index
  41. 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);
  42. // Restore heap property at an index in clear
  43. std::pair<RegXS, RegBS> restore_heap_property_at_explicit_index(MPCTIO tio, yield_t & yield, size_t index);
  44. // Prints the current heap
  45. void print_heap(MPCTIO tio, yield_t & yield);
  46. };
  47. void Heap(MPCIO &mpcio,
  48. const PRACOptions &opts, char **args, int argc);
  49. #endif