heap.hpp 3.0 KB

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