/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
using namespace std;
int FMHash(char * obj, int CaseInsensitive);
int main()
{
cout<<FMHash("Hello World", 0);
cout<<FMHash("HelloWorld", 0);
return 0;
}
int FMHash(char * obj, int CaseInsensitive)
{
//prime
int hash1 = 42, hash2 = hash1, i = 0;
for(; *obj != '\0'; ++obj, ++i)
{
char ch = CaseInsensitive ? std::tolower(*obj) : *obj;
if (std::isspace(ch))
{
++hash2;
}else{
hash1 += ch * (1 + i - hash2);
}
}
return hash1 + hash2 - i;
}