递归哈希码?

Jen*_*nny -1 c recursion hash

这应该返回451,845,518,507,当我通过"冰",但它返回873,952,427可以有人告诉我为什么?(MAX_STR_SIZE = 501)

unsigned long hash_code(const char *str){
  char temp[MAX_STR_SIZE]="";
  unsigned long multiplied;
  if(str == NULL){
    return SUCCESS;
  }
  else if(strlen(str)==0 || str==""){
    return SUCCESS;
  }
  else{

      strncpy(temp,str, strlen(str)-1);
      temp[strlen(str)-1]=0;


      multiplied = (hash_code(temp)*65599 + (int) str[strlen(str)-1]);
      return multiplied;
  }
}
Run Code Online (Sandbox Code Playgroud)

chu*_*ica 5

unsigned long您的计算机上只有32位.需要更广泛的类型451,845,518,507

451,845,518,507 mod pow(2,32) --> 873,952,427
Run Code Online (Sandbox Code Playgroud)