Advertisement
bueddl

Untitled

May 24th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1.  
  2. /*
  3. * @Summary: Calculate Weights (Count each byte in file)
  4. * @Returns: Array of Weights
  5. * @Param  :
  6. *       FILE    *fp   : The file
  7. *       int     *total: The Number of different bytes in the file (Number of entries in Weight-Array)
  8. */
  9. uint32_t*
  10.     huffman_calc_weight(FILE *fp, int *total) {
  11.     uint8_t buffer[512];
  12.     int i;
  13.     int real_buffer_size;
  14.     uint32_t *Weights;
  15.  
  16.     Weights = (uint32_t*)calloc(sizeof(uint32_t), 256);
  17.  
  18.     if (fp != NULL) {
  19.         fseek(fp, 0, SEEK_SET);
  20.         while (!feof(fp)) {
  21.             if ((real_buffer_size = fread(buffer, 1, sizeof(buffer), fp)) != 0) {
  22.  
  23.                 for (i = 0; i < real_buffer_size; i++) {
  24.                     Weights[buffer[i]]++;
  25.                 }
  26.  
  27.                 *total += real_buffer_size;
  28.             }
  29.         }
  30.         fseek(fp, 0, SEEK_SET);
  31.     }
  32.  
  33.     return Weights;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement