A C implementation of Huffman coding for text file compression. This project provides a complete solution for encoding and decoding text using Huffman's algorithm, featuring a custom hashmap implementation and priority queue for efficient data management.
- Text file compression using Huffman coding algorithm
- Custom hashmap implementation for frequency counting and code storage
- Priority queue for efficient Huffman tree construction
- Support for ASCII characters, spaces, and newlines
- Visual representation of the Huffman tree building process
- Encoding and decoding capabilities
.
├── ColaDePrioridad/ # Priority Queue implementation
│ ├── priority.c
│ └── priority.h
├── Encode/ # Encoding/Decoding implementation
│ ├── Encoding.c
│ └── Encoding.h
├── hashmap/ # Custom hashmap implementation
│ ├── map.c
│ └── map.h
├── huffmanT/ # Huffman tree implementation
│ ├── huffmanTree.c
│ └── huffmanTree.h
├── .gitignore # Git ignore file
├── main # Compiled executable
├── main.c # Main program logic and UI
├── README.md # Project documentation
├── test.txt # Sample input file
└── TODO.md # Project tasks and todos
- Standard C libraries:
- stdio.h
- stdlib.h
- string.h
- Compile the project:
gcc main.c -o huffman
- Run the program:
./huffman
- The program will:
- Read the input from
test.txt
- Display character frequencies
- Show the Huffman tree construction process
- Generate Huffman codes for each character
- Encode the input text
- Decode the encoded text back to its original form
- Read the input from
-
Hashmap (
hashmap/map.c
)- Custom implementation for storing character frequencies and codes
- Collision handling through chaining
- Dynamic bucket allocation
-
Priority Queue (
ColaDePrioridad/priority.c
)- Min-heap implementation for Huffman tree construction
- Maintains nodes sorted by frequency
- Supports custom data types
-
Huffman Tree (
huffmanT/huffmanTree.c
)- Binary tree structure for code generation
- Supports character storage and frequency information
- Includes tree traversal for code generation
create_freq_map
: Generates frequency map from input texthuffman_create_tree
: Constructs Huffman tree from priority queueencode_file_with_huffman
: Encodes text file using generated Huffman codesdecode_text_with_huffman
: Decodes Huffman-encoded text
The program provides detailed output including:
- Frequency map of characters
- Priority queue ordering
- Huffman tree construction steps
- Generated Huffman codes
- Encoded binary string
- Decoded text verification
The implementation includes proper memory management with:
- Dynamic allocation for all data structures
- Proper cleanup of allocated memory
- Memory leak prevention
- Currently supports ASCII characters only
- Input file must be named
test.txt
- Encoded output is represented as a binary string (not compressed binary file)