我正在编写可用于生产的C语言,其中我需要非常快地找到字符数组中字符的频率.我正在try 删除Assert调用,以在强制转换期间判断正值.我的断言是冗余代码还是必需的?
char input[] = "Hello World";
int inputLength = sizeof(input)/ sizeof(char);
int *frequencies = calloc(256, sizeof(int));
for(int i = 0; i < inputLength-1; i++)
{
int value = (int) input[i];
assert(value > -1);//Is this line redundant?
frequencies[value] += 1;
}
printf("(%d)", inputLength);
PrintFrequencies(frequencies);
free(frequencies);