Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * @Summary: Calculate Weights (Count each byte in file)
- * @Returns: Array of Weights
- * @Param :
- * FILE *fp : The file
- * int *total: The Number of different bytes in the file (Number of entries in Weight-Array)
- */
- uint32_t*
- huffman_calc_weight(FILE *fp, int *total) {
- uint8_t buffer[512];
- int i;
- int real_buffer_size;
- uint32_t *Weights;
- Weights = (uint32_t*)calloc(sizeof(uint32_t), 256);
- if (fp != NULL) {
- fseek(fp, 0, SEEK_SET);
- while (!feof(fp)) {
- if ((real_buffer_size = fread(buffer, 1, sizeof(buffer), fp)) != 0) {
- for (i = 0; i < real_buffer_size; i++) {
- Weights[buffer[i]]++;
- }
- *total += real_buffer_size;
- }
- }
- fseek(fp, 0, SEEK_SET);
- }
- return Weights;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement