Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <unordered_map>
- #include <std_lib_facilities.h>
- struct hash_MyObject {
- size_t operator()(const MyObject &object) const {
- return std::hash<int>()(object.key) ^ std::hash<std::string>()(object.value);
- }
- };
- struct MyObject {
- public :
- int key;
- std::string value;
- MyObject(int key, std::string value) {
- this->key = key;
- this->value = value;
- }
- bool operator==(const MyObject &object) {
- return (key == object.key && value == object.value);
- }
- };
- void createHashtable() {
- }
- int hashedKey(int key) {
- int hashedkey = key % 10;
- return hashedkey;
- }
- void parse(std::string stringIN) {
- int size=10;
- int key;
- std::string value_string;
- std::unordered_map<MyObject, int, hash_MyObject> hashMap;
- if (stringIN == "size") {
- std::cin >> stringIN;
- try {
- size = stoi(stringIN);
- }
- catch(...){
- std::cout << "fail to convert value (size)" << std::endl;
- }
- }
- if (stringIN == "add") {
- std::cin >> stringIN;
- try {
- key = stoi(stringIN);
- }
- catch (...) {
- std::cout << "fail to convert value (key)" << std::endl;
- }
- std::cin >> stringIN; //key
- value_string = stringIN;
- MyObject * object = new MyObject(key, value_string);
- hashMap.emplace(object, hashedKey(key));
- }
- if (stringIN == "print") {
- std::cout << hashMap.size() << std::endl;
- }
- if (stringIN == "delete") {
- std::cin >> stringIN; //key
- std::cout << "DELETING..." << std::endl;
- //DELETING ALGORITHM HERE
- }
- if (stringIN == "stop") {
- std::cout << "END OF BLOCK" << std::endl;
- }
- else {
- //
- }
- };
- int main() {
- std::string downloadedString;
- int number_of_blocks = 0;
- std::cin >> downloadedString;
- try {
- number_of_blocks = stoi(downloadedString);
- }
- catch (...) {
- std::cout << "fail to convert value (number_of_blocks)" << std::endl;
- }
- for (int i = 0; i < number_of_blocks; i++) {
- while (downloadedString != "stop") {
- std::cin >> downloadedString;
- parse(downloadedString);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement