aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclyne <clyne@bitgloo.com>2020-12-27 19:40:29 -0500
committerGitHub <noreply@github.com>2020-12-27 19:40:29 -0500
commit31737473267922223cc96fe27303bb3b0593b610 (patch)
treeefd7d1c4d8ab68d4e9adfb7dba223d5f7ba8b65f
parent4a81241a82a26c1695150ab661db568993e7fef6 (diff)
Update readme for new features
-rw-r--r--README.md20
1 files changed, 10 insertions, 10 deletions
diff --git a/README.md b/README.md
index b834d1c..242c403 100644
--- a/README.md
+++ b/README.md
@@ -1,20 +1,18 @@
# consteval-huffman
-Allows for long string or data constants to be compressed at compile-time, with a small decoder routine for decompression at run-time.
+Allows for long strings of text or data to be compressed at compile-time, with an efficient decoder routine for decompression at run-time. The decoder conforms to `std::forward_iterator`, allowing for use in ranged-for or standard algorithms.
-Compression is achieved using [Huffman coding](https://en.wikipedia.org/wiki/Huffman_coding), which works by creating short (measured in bits) codes for frequently-occuring characters.
+Compression is achieved using [Huffman coding](https://en.wikipedia.org/wiki/Huffman_coding), which works by creating short codes (measured in bits) for frequently-occuring characters. This works best on larger pieces of data, or more so data that is limited in its range of values (e.g. written text).
## 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)).
+A ~3.5kB string of JSON can be compressed down ~2.5kB ([see it on Godbolt](https://godbolt.org/z/1MzG1v)).
**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 larger blocks of text or data, as a decoding tree must be stored with the compressed data that requires three bytes per unique data byte.
+A ~40 line comment-including sample of Lisp can be reduced from 1,662 bytes to 1,244 (418 bytes saved) ([Godbolt](https://godbolt.org/z/jcnKza)).
## How to Use
@@ -23,15 +21,17 @@ Compression will work best on larger blocks of text or data, as a decoding tree
constexpr static const char some_data_raw[] = /* insert text here */;
-constinit static const auto some_data = consteval_huffman<some_data_raw>();
+// Creates an object with the compressed data
+// If data is not smaller after compression, huffman_compress will keep the data uncompressed
+constinit static const auto some_data = huffman_compress<some_data_raw>();
// Or, with a set data length:
-// ... some_data = consteval_huffman<some_data_raw, 1500>();
+// ... some_data = huffman_compress<some_data_raw, 1500>();
int main()
{
// Decompress and print out the data
- for (auto decode = some_data.get_decoder(); decode; ++decode)
- putchar(*decode);
+ for (auto c : some_data)
+ putchar(c);
}
```