Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <unordered_map>
  5. #include <std_lib_facilities.h>
  6.  
  7.  
  8. struct hash_MyObject {
  9. size_t operator()(const MyObject &object) const {
  10. return std::hash<int>()(object.key) ^ std::hash<std::string>()(object.value);
  11. }
  12. };
  13.  
  14.  
  15. struct MyObject {
  16. public :
  17. int key;
  18. std::string value;
  19.  
  20. MyObject(int key, std::string value) {
  21. this->key = key;
  22. this->value = value;
  23. }
  24.  
  25. bool operator==(const MyObject &object) {
  26. return (key == object.key && value == object.value);
  27. }
  28. };
  29.  
  30.  
  31.  
  32. void createHashtable() {
  33.  
  34. }
  35.  
  36. int hashedKey(int key) {
  37. int hashedkey = key % 10;
  38. return hashedkey;
  39. }
  40.  
  41.  
  42.  
  43. void parse(std::string stringIN) {
  44. int size=10;
  45. int key;
  46. std::string value_string;
  47.  
  48. std::unordered_map<MyObject, int, hash_MyObject> hashMap;
  49.  
  50.  
  51. if (stringIN == "size") {
  52. std::cin >> stringIN;
  53. try {
  54. size = stoi(stringIN);
  55. }
  56. catch(...){
  57. std::cout << "fail to convert value (size)" << std::endl;
  58. }
  59. }
  60. if (stringIN == "add") {
  61. std::cin >> stringIN;
  62. try {
  63. key = stoi(stringIN);
  64. }
  65. catch (...) {
  66. std::cout << "fail to convert value (key)" << std::endl;
  67. }
  68. std::cin >> stringIN; //key
  69. value_string = stringIN;
  70.  
  71. MyObject * object = new MyObject(key, value_string);
  72.  
  73. hashMap.emplace(object, hashedKey(key));
  74. }
  75. if (stringIN == "print") {
  76. std::cout << hashMap.size() << std::endl;
  77. }
  78. if (stringIN == "delete") {
  79. std::cin >> stringIN; //key
  80. std::cout << "DELETING..." << std::endl;
  81. //DELETING ALGORITHM HERE
  82.  
  83. }
  84. if (stringIN == "stop") {
  85. std::cout << "END OF BLOCK" << std::endl;
  86. }
  87. else {
  88. //
  89. }
  90.  
  91. };
  92.  
  93.  
  94. int main() {
  95.  
  96. std::string downloadedString;
  97. int number_of_blocks = 0;
  98.  
  99. std::cin >> downloadedString;
  100. try {
  101. number_of_blocks = stoi(downloadedString);
  102. }
  103. catch (...) {
  104. std::cout << "fail to convert value (number_of_blocks)" << std::endl;
  105. }
  106.  
  107. for (int i = 0; i < number_of_blocks; i++) {
  108. while (downloadedString != "stop") {
  109. std::cin >> downloadedString;
  110. parse(downloadedString);
  111.  
  112. }
  113. }
  114.  
  115.  
  116. return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement