直方图生成功能 [英] Histogram generating function

查看:79
本文介绍了直方图生成功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被指派对其他人编写的C程序进行一些更改...我想首先了解它才能正确地对其进行处理...我遇到了一个函数,该函数可以根据给定的值生成ASCII值的直方图一长串数据。

i was assigned to make some changes to a C program written by someone else...i want to understand it first to work on it properly...i came upon a function that generates the histogram of ASCII values from a given long string of data. it is something like this.

//load the symbols the old data
  for(int k = 0;k < 256;++k)
  {
    sym[k].Symbol = k;
    sym[k].Count  = 0;
  }

  //Creating the probability distribution for each of the source symbols.
  for(int k = size;k;--k)
  {
    sym[*in ++].Count ++;
  }

其中 in是包含要作为字符的字符数组(字符串)算了。 sym是一个结构变量。我不太明白这是怎么回事。谁能告诉我第二个循环如何生成字符串中1到255(ASCII)符号的计数?

here 'in' is the char array (string) containing the characters to be counted. sym is a struct variable. i can't quite understand how this works. can anyone tell me how how the second loop generated the count of the symbols 1 to 255 (ASCII) in the string?

推荐答案

for(int k = 0; k < size; k++)
  {
    sym[in[k]].Count++;
  }

这基本上就是第二个循环所要做的。

This is basically what that second loop is doing.

他们只是取消引用,然后一步步移至下一个ascii值,并为该ascii值增加计数器。

They just dereference and then move to the next ascii value in one step, and increment the counter for that ascii value.

这篇关于直方图生成功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆