Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "hashtable.h"
- #include <string.h>
- #include <sstream>
- #include <stdio.h>
- #define VMAX 100
- using namespace std;
- unsigned int customHash(string key) {
- unsigned int hkey = 0;
- for (unsigned int i = 0; i < key.length(); i++)
- hkey = (hkey * 31 + key[i]) % VMAX;
- return hkey;
- }
- int main() {
- Hashtable< string, string> myHashtable = Hashtable< string, string>( VMAX, customHash);
- string inputLine;
- //char *command, *key, *value;
- //string command, key, value;
- char command[10], key[100], value[10000];
- while(1) {
- getline( cin, inputLine); /* put "me" "there" */
- command[0] = '\0';
- key[0] = '\0';
- value[0] = '\0';
- sscanf( inputLine.c_str(), "%s %s %[^\t\n]", command, key, value);
- for( unsigned int i=1; i < strlen(key); i++) {
- key[i-1] = key[i];
- }
- key[ strlen(key)-2] = '\0';
- for( unsigned int i=1; i < strlen(value); i++) {
- value[i-1] = value[i];
- }
- value[ strlen(value)-2] = '\0';
- //cout << command << endl << key << endl << value << endl;
- if( strcmp( command, "put") == 0) {
- string keyString( key);
- string valueString( value);
- if( myHashtable.has_key( keyString)) {
- myHashtable.put( keyString, valueString);
- cout << keyString << " - modificat cu succes!" << endl;
- }
- else {
- myHashtable.put( keyString, valueString);
- cout << keyString << " - adăugat cu succes!" << endl;
- }
- }
- if( strcmp( command, "get") == 0) {
- string keyString( key);
- if( myHashtable.has_key( keyString)) {
- cout << keyString << " - " << myHashtable.get( keyString) << endl;
- }
- else {
- cout << keyString << " - cuvânt inexistent!" << endl;
- }
- }
- if( strcmp( command, "quit") == 0) {
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement