Commit 36d9f66d authored by Kamal Khodabhai's avatar Kamal Khodabhai

Update server.cpp

parent e9e6839e
......@@ -58,12 +58,41 @@ void getConfig() {
int getHash(string key) {
int hash = 0;
for(auto c : key) {
hash = (hash + c) % mod;
int len = key.length();
for (int i = 0; i < len; i++) {
hash = hash + ((hash) << 5) + key[i] + (key[i] << 7);
}
return hash;
return (((hash) ^ (hash >> 16)) & 0xffff) % mod;
}
// int getHash(string key){
// unsigned char obuf[41];
// char finalHash[41];
// string keyHash = "";
// int i;
// /* convert string to an unsigned char array because SHA1 takes unsigned char array as parameter */
// unsigned char unsigned_key[key.length()+1];
// for(i=0;i<key.length();i++){
// unsigned_key[i] = key[i];
// }
// unsigned_key[i] = '\0';
// SHA1(unsigned_key,sizeof(unsigned_key),obuf);
// for (i = 0; i < M/8; i++) {
// sprintf(finalHash,"%d",obuf[i]);
// keyHash += finalHash;
// }
// int hash = stoll(keyHash) % mod;
// return hash;
// }
class CallData {
public:
CallData(KeyValueServices::AsyncService *service, ServerCompletionQueue *cq, RequestType reqType) : service(service), cq(cq), getResponder(&context), putResponder(&context), delResponder(&context), status(CREATE), reqType(reqType) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment