https://github.com/aldrinmathew/digit_power_compression
Compress a 64-bit integer to a byte-pair sequence based on the power of numbers
https://github.com/aldrinmathew/digit_power_compression
compression compression-algorithm mathematics
Last synced: 8 months ago
JSON representation
Compress a 64-bit integer to a byte-pair sequence based on the power of numbers
- Host: GitHub
- URL: https://github.com/aldrinmathew/digit_power_compression
- Owner: aldrinmathew
- Created: 2025-03-22T17:16:36.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-22T18:26:57.000Z (about 1 year ago)
- Last Synced: 2025-09-19T08:05:00.691Z (9 months ago)
- Topics: compression, compression-algorithm, mathematics
- Language: Rust
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
### Digit-Power compression
Take a number, say `7290125`. It is stored as an unsigned 64-bit integer. We want to represent this number as a byte-pair sequence.
The idea of this algorithm is to use a pair of bytes to calculate part of the digits.
In the byte-pair, `(a, b)`, both a and b can have values from `0` to `255`. The idea is to translate the byte-pair as an exponent expression. Basically part of the digits of the original number is the same as the digits in `a ^ b`
In the above number, `729 = 27 ^ 2` and `125 = 5 ^ 3`. But what about the `0` in the middle? Well, if there are `0` values in the middle that have not been encoded yet, then we use the byte pair `(0, n)`. Basically it means the digit `0` is repeaing `n` times.
So the result is `7290125 = (27, 2) (0, 1) (5, 3)`
Remember that this is a byte-pair sequence, so the 64-bit unsigned integer has been represented as 3 pairs of bytes, so a 75% reduction in size in the case of `7290125`.
This simple explanation is theoretical. Not all numbers can result in reduction like this. This program calculates the compression factor for a range of numbers. For numbers above a certain threshold, there is no compression at all, in fact there could be an increase in size.