Add test fixture.
This commit is contained in:
parent
af6fad72eb
commit
d6d4319e21
37 changed files with 421 additions and 279 deletions
|
@ -6,6 +6,7 @@
|
|||
#include "HuffmanFixedCodes.h"
|
||||
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
|
||||
class PrefixCodeGenerator
|
||||
|
@ -21,11 +22,11 @@ public:
|
|||
|
||||
class HuffmanEncoder : public PrefixCodeGenerator
|
||||
{
|
||||
using DataStream = std::vector<unsigned char>;
|
||||
using CountPair = std::pair<unsigned char, unsigned>;
|
||||
using CountPair = std::pair<unsigned, unsigned>;
|
||||
using Hit = std::tuple<unsigned, unsigned, unsigned char>;
|
||||
|
||||
public:
|
||||
void encode(const DataStream& stream);
|
||||
void encode(const std::vector<unsigned>& counts);
|
||||
void encode(const std::unordered_map<unsigned char, unsigned>& counts);
|
||||
|
||||
uint32_t getLengthValue(unsigned length);
|
||||
|
@ -38,18 +39,19 @@ public:
|
|||
|
||||
std::optional<PrefixCode> getEndOfStreamValue() const override;
|
||||
|
||||
void initializeTrees();
|
||||
void initializeTrees(const std::vector<Hit>& hits);
|
||||
|
||||
void setUseFixedCode(bool useFixed);
|
||||
|
||||
private:
|
||||
void initializeLiteralLengthTable();
|
||||
void initializeLiteralLengthTable(const std::vector<Hit>& hits);
|
||||
|
||||
void dumpTree(const RawTree<CountPair>& tree) const;
|
||||
void dumpNode(RawNode<CountPair>* node, unsigned depth) const;
|
||||
|
||||
bool mUseFixedCode{false};
|
||||
bool mTableIsInitialized{false};
|
||||
|
||||
std::vector<unsigned char> mSymbolMapping;
|
||||
HuffmanCodeLengthTable mLiteralLengthTable;
|
||||
HuffmanCodeLengthTable mDistanceTable;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue