ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Huffman.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------------- File Huffman.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
34/*--------------------------------------------------------------------------*/
35/*----------------------------- DEFINITIONS --------------------------------*/
36/*--------------------------------------------------------------------------*/
37
38#ifndef __ADS_Huffman
39 #define __ADS_Huffman
40/* self-identification: #endif constant */
41
42/*--------------------------------------------------------------------------*/
43/*------------------------------ INCLUDES ----------------------------------*/
44/*--------------------------------------------------------------------------*/
45
46#include "ADS/Contract.h"
48
49#include <algorithm>
50#include <cstddef>
51#include <map>
52#include <stdexcept>
53#include <string>
54#include <vector>
55
56/*--------------------------------------------------------------------------*/
57/*--------------------------- NAMESPACE ------------------------------------*/
58/*--------------------------------------------------------------------------*/
59
60namespace ADS
61{
62
88template< class C , class F >
89std::map< C , std::string > huffman( const std::map< C , F > & freq );
90
93template< class C >
94std::string encode( const std::basic_string< C > & text ,
95 const std::map< C , std::string > & code );
96
115template< class C >
116std::basic_string< C > decode( const std::string & bits ,
117 const std::map< C , std::string > & code );
118
119/*--------------------------------------------------------------------------*/
120
121} // end( namespace ADS )
122
123/*--------------------------------------------------------------------------*/
124/*-------------------------- IMPLEMENTATION --------------------------------*/
125/*--------------------------------------------------------------------------*/
126
127#include "ADS/string/impl/Huffman.tpp"
128
129/*--------------------------------------------------------------------------*/
130
131#endif /* Huffman.h included */
132
133/*--------------------------------------------------------------------------*/
134/*--------------------------- End File Huffman.h ---------------------------*/
135/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The PRIORITYQUEUE [see PriorityQueue.h] on a heap.
std::string encode(const std::basic_string< C > &text, const std::map< C, std::string > &code)
the text encoded by the codes, the code of each character in turn
std::basic_string< C > decode(const std::string &bits, const std::map< C, std::string > &code)
the bits decoded by the codes, a prefix code
std::map< C, std::string > huffman(const std::map< C, F > &freq)
the codes of Huffman of the characters with the given frequencies, at least one; a single character g...
Definition ADT.h:96