c_cpp Ç语言创建0〜48的8个索引
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp Ç语言创建0〜48的8个索引相关的知识,希望对你有一定的参考价值。
int
java_hashCode(const char *str)
{
int hash = 0;
for (int i = 0; i < strlen(str); i++) {
hash = 31 * hash + str[i];
}
return hash;
}
char *
concat(const char *s1, const char *s2)
{
const size_t len1 = strlen(s1);
const size_t len2 = strlen(s2);
char *result = malloc(len1+len2+1);
memcpy(result, s1, len1);
memcpy(result+len1, s2, len2+1);
return result;
}
struct IndexsResult
getSha1KeyIndexs(const char *product,
const char *version,
const char *deviceID,
const char *timeStamp)
{
struct IndexsResult result = {{0}};
char *temp = malloc(strlen(product) + 1);
strcpy(temp, product);
char *temp1 = concat(temp, version);
char *temp2 = concat(temp1, deviceID);
char *data = concat(temp2, timeStamp);
int hash = java_hashCode(data);
hash = hash & 0x7FFFFFFF;
free(temp);
free(temp1);
free(temp2);
free(data);
for(int i=0; i<8; i++) {
int index = (int)(hash / (int)pow(10, i)) % 48;
result.indexs[i] = index;
}
return result;
}
以上是关于c_cpp Ç语言创建0〜48的8个索引的主要内容,如果未能解决你的问题,请参考以下文章
c_cpp Ç代码断言打印
c_cpp Ç发送HTTP
c_cpp Ç发送HTTP
c_cpp Ç链表操作
c_cpp 199.cpp
c_cpp 199-2.cpp