Add some bit utils and initial l77 encoder.

This commit is contained in:
James Grogan 2022-11-22 17:37:06 +00:00
parent ff962a6b16
commit 318b481ccc
12 changed files with 508 additions and 117 deletions

View file

@ -10,6 +10,7 @@ target_include_directories(test_utils PUBLIC
list(APPEND TestFiles
audio/TestAudioWriter.cpp
audio/TestMidiReader.cpp
core/TestByteUtils.cpp
core/TestBinaryStream.cpp
core/TestTomlReader.cpp
compiler/TestLexer.cpp

View file

@ -2,6 +2,7 @@
#include "HuffmanEncoder.h"
#include "RunLengthEncoder.h"
#include "Lz77Encoder.h"
void test_run_length_encoder()
{
@ -34,13 +35,30 @@ void test_huffman_encoder()
HuffmanEncoder encoder;
encoder.encode(counts);
}
void test_lz77_encoder()
{
std::string test_data = "sir sid eastman easily teases sea sick seals";
//std::string test_data = "sir sid eastman";
Lz77Encoder encoder;
auto encoded = encoder.encode(test_data);
std::cout << "Encoded: " << encoded << std::endl;
//auto decoded = encoder.decode(encoded);
//std::cout << "Decoded: " << decoded << std::endl;
}
int main()
{
test_huffman_encoder();
//test_huffman_encoder();
//test_run_length_encoder();
test_lz77_encoder();
return 0;
}

View file

@ -0,0 +1,18 @@
#include "ByteUtils.h"
#include <iostream>
int main()
{
auto byte = ByteUtils::getFromString("00110101");
std::cout << "Value is " << static_cast<unsigned>(byte) << std::endl;
auto string_rep = ByteUtils::toString(byte);
std::cout << "String rep is " << string_rep << std::endl;
auto slice = ByteUtils::getMBitsAtN(byte, 3, 3);
std::cout << "Slice is " << ByteUtils::toString(slice) << std::endl;
return 0;
}

View file

@ -5,17 +5,17 @@
int main()
{
const auto data_loc = std::filesystem::path(__FILE__) / "../../data";
const auto sample_toml_file = data_loc / "sample_toml.toml";
const auto data_loc = std::filesystem::path(__FILE__) / "../../data";
const auto sample_toml_file = data_loc / "sample_toml.toml";
auto reader = TomlReader();
reader.read(sample_toml_file);
auto reader = TomlReader();
reader.read(sample_toml_file);
auto themes_table = reader.getContent()->getTable("themes");
for (const auto& items : themes_table->getKeyValuePairs())
{
std::cout << "Got entry with key: " << items.first << " and val " << items.second << std::endl;
}
auto themes_table = reader.getContent()->getTable("themes");
for (const auto& items : themes_table->getKeyValuePairs())
{
std::cout << "Got entry with key: " << items.first << " and val " << items.second << std::endl;
}
return 0;
}
return 0;
}