Skip to content

Instantly share code, notes, and snippets.

@ebresafegaga
Created April 25, 2021 12:33
Show Gist options
  • Save ebresafegaga/9a8b6b902a633ec697c4249f48d6901c to your computer and use it in GitHub Desktop.
Save ebresafegaga/9a8b6b902a633ec697c4249f48d6901c to your computer and use it in GitHub Desktop.
Probably buggy implementation of Lempel-Lev-Welch compression algorithm
#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