heap.hpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. // Takes in as an input the XOR shares of the index at which
  15. // the heap property has to be restored
  16. // Returns the XOR shares of the index of the smaller child
  17. RegXS restore_heap_property(MPCIO &mpcio, MPCTIO tio, yield_t & yield, RegXS index);
  18. // Optimized restore heap property at a secret shared index
  19. // Takes in as an input the XOR shares of the index at which
  20. // the heap property has to be restored
  21. // Returns the XOR shares of the index of the smaller child and
  22. // comparison between the left and right child
  23. 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);
  24. // Restore heap property at an index in clear
  25. // Takes in as an input the index (in clear) at which
  26. // the heap property has to be restored
  27. // Returns the XOR shares of the index of the smaller child and
  28. // comparison between the left and right child
  29. std::pair<RegXS, RegBS> restore_heap_property_at_explicit_index(MPCTIO tio, yield_t & yield, size_t index);
  30. public:
  31. MinHeap(int player_num, size_t size) : oram(player_num, size) {};
  32. // The extractmin protocol returns the minimum element (the root), removes it
  33. // and restores the heap property
  34. // and takes in a boolean parameter to decide if the basic or the optimized version needs to be run
  35. // return value is the share of the minimum value (the root)
  36. RegAS extract_min(MPCIO &mpcio, MPCTIO tio, yield_t & yield, int is_optimized);
  37. // Intializes the heap array with 0x7fffffffffffff
  38. void init(MPCTIO tio, yield_t & yield);
  39. // This function simply inits a heap with values 100,200,...,100*n
  40. // We use this function only to set up our heap
  41. // to do timing experiments on insert and extractmins
  42. void init(MPCTIO tio, yield_t & yield, size_t n);
  43. // The Basic Insert Protocol
  44. // Takes in the additive share of the value to be inserted
  45. // And adds the the value into the heap while keeping the heap property intact
  46. void insert(MPCTIO tio, yield_t & yield, RegAS val);
  47. // The Optimized Insert Protocol
  48. // Takes in the additive share of the value to be inserted
  49. // And adds the the value into the heap while keeping the heap property intact
  50. void insert_optimized(MPCTIO tio, yield_t & yield, RegAS val);
  51. // Note: This function is intended for testing purposes only.
  52. // The purpose of this function is to verify that the heap property is satisfied.
  53. void verify_heap_property(MPCTIO tio, yield_t & yield);
  54. // Prints the current heap
  55. void print_heap(MPCTIO tio, yield_t & yield);
  56. };
  57. void Heap(MPCIO &mpcio, const PRACOptions &opts, char **args);
  58. #endif