uint64_t get_nick_hash(const char *gbk_nick) { char nick[MAX_NICK_LENGTH]; uint64_t hash = 0; snprintf(nick, sizeof(nick), "%s", gbk_nick); toUpperSafe(nick); hash = hashString64(nick); return hash; }
/** * 获取64位的hash值 * @param szText数据 * @param eType数据类型 * @return 返回64位哈希后的值 **/ static uint64_t get_hash(const char* szText, enum field_types eType,uint32_t len) { uint64_t nKeyHash; const char *szValue = szText; int bNegative = 0; if(eType == HI_TYPE_STRING){ return hashString64(szText,len); } if (szText[0] == '-') { //可能是负数,我们必须保证整数转化成u_n64_t类型的值大于负数转换后的值 szValue = &szText[1]; bNegative = 1; } if (eType == HI_TYPE_FLOAT|| eType == HI_TYPE_DOUBLE) { //float, ft_property类型的字段 int bPoint = 0; const char *ptr = szValue; if (!ISNUM(*ptr++)) //第一位必须是数字 return 0; while (*ptr) { if (!ISNUM(*ptr)) { if (!bPoint&&((*ptr)=='.'||(*ptr)==':')&&ISNUM(*(ptr+1))) { bPoint = 1; ptr++; continue; } return 0xFFFFFFFFFFFFFFFFLL; } ptr ++; } const char *szLeft = szValue; const char *szRight = strchr(szValue, '.'); //float类型的字段 if (szRight == NULL) szRight = strchr(szValue, ':'); //属性字段 nKeyHash = atoi(szLeft); nKeyHash <<= 32; if (szRight != NULL && *szRight != '\0') { szRight++; if (*szRight != '\0') { nKeyHash |= atoi(szRight); } } } else { //integer, long或time类型的字段 nKeyHash = atoll(szValue); } if (bNegative) nKeyHash = ~nKeyHash & 0x7FFFFFFFFFFFFFFFLL; else nKeyHash |= 0x8000000000000000LL; return nKeyHash; }