Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <list>
  4. #include <string>
  5. #include <utility>
  6. #include <functional>
  7. #include <math.h>
  8.  
  9. using namespace std;
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. int main() {
  17. int n = 29;
  18. vector<int*> buckets(n, NULL);
  19.  
  20. auto hp = [=](int k) {return k % n;};
  21. auto hp2 = [=](int k) {return 1 + k % (n-1);};
  22. /*auto h = [=](int k, int i) {
  23. return (hp(k) + i) % n;
  24. };*/
  25. /*int c1 = 0;
  26. int c2 = 1;
  27. auto h = [=](int k, int i) {
  28. return (hp(k) + c1*i + c2*i*i) % n;
  29. };*/
  30. auto h = [=](int k, int i) {
  31. return (hp(k) + i*hp2(k)) % n;
  32. };
  33.  
  34. vector <int> nums = {6, 34, 67, 92, 96, 8, 53, 5, 3, 2};
  35. for (auto k : nums) {
  36. for (int i = 0; i < n; ++i) {
  37. auto index = h(k, i);
  38. cout << index << " ";
  39. if (buckets[index] == nullptr) {
  40. buckets[index] = new int;
  41. (*buckets[index]) = k;
  42. break;
  43. }
  44. }
  45. cout << endl;
  46. }
  47.  
  48.  
  49. getchar();
  50. getchar();
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement