Created
April 25, 2021 12:33
-
-
Save ebresafegaga/9a8b6b902a633ec697c4249f48d6901c to your computer and use it in GitHub Desktop.
Probably buggy implementation of Lempel-Lev-Welch compression algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define (compress uncompressed) | |
(let ([table (for*/hash ([i (in-range 256)] | |
[str (in-value (string (integer->char i)))]) | |
(values str i))]) | |
(for*/fold ([w ""] | |
[size 256] | |
[result null] | |
[tbl table] #:result `(,result . ,table)) | |
([c (in-string uncompressed)] | |
[wc (in-value (begin (displayln "hey") (string-append w (string c))))]) | |
(if (hash-has-key? tbl wc) | |
(values wc | |
size | |
result | |
tbl) | |
(values (string c) | |
(add1 size) | |
(hash-ref tbl w) | |
(hash-set tbl wc size)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment