From d2249cbbfac61e4e9a8af28a2e10c65353f7e761 Mon Sep 17 00:00:00 2001 From: clyne Date: Mon, 3 Aug 2020 21:19:08 -0400 Subject: [PATCH] Update README.md --- README.md | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cfc63c4..cd59891 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,37 @@ # consteval-huffman -Compile-time Huffman coding compression using C++20 + +Allows for long string or data constants to be compressed at compile-time, with a small decoder routine for decompression at run-time. + +Compression is achieved using Huffman coding, which works by creating codes for frequently-occuring characters. + +## Use cases + +**1. Text configurations (e.g. JSON)** + +A ~3.5kB string of JSON can be compressed down ~2.5kB ([see it on Godbolt](https://godbolt.org/z/P6a9Kr)). + +**2. Scripts (e.g. Lisp)** + +A ~40 line commented sample of Lisp can be reduced from 1,662 bytes to 1,244 (418 bytes saved) ([on Godbolt](https://godbolt.org/z/c64Pzz)). + +Compression will work best on not-small blocks of text or data. This is because a decoding tree must be stored with the compressed data, requiring three bytes per value. + +## How to Use + +```cpp +#include "consteval_huffman.hpp" + +constexpr static const char some_data_raw[] = /* insert text here */; + +constinit static const auto some_data = consteval_huffman(); + +// Or, with a set data length: +// ... some_data = consteval_huffman(); + +int main() +{ + // Decompress and print out the data + for (auto decode = some_data.get_decoder(); decode; ++decode) + putchar(*decode); +} +```