Skip to content

Instantly share code, notes, and snippets.

@klauspost
klauspost / lib.rs
Created March 29, 2025 11:18
MinLZ Machine Converted (Grok) Rust block decode/encode.
use std::error::Error;
use std::fmt;
#[derive(Debug, PartialEq, Eq)]
pub enum MinLzError {
BlockTooLarge,
CorruptInput,
}
impl fmt::Display for MinLzError {
@klauspost
klauspost / dec-main.c
Last active March 29, 2025 11:27
MinLZ C block en/decoder - machine converted + tweaks.
#include "unminlz.h" // MinLZ header
#include <stdio.h> // For file operations
#include <stdint.h> // For fixed-width integer types
#include <stdlib.h> // For memory allocation
#define MAX_BLOCK_SIZE (8 << 20) // 8MB, maximum block size for decoding
int main(int argc, char* argv[]) {
// Check if the correct number of arguments is provided
if (argc != 3) {
package main
import (
"bytes"
"fmt"
"os"
"sync"
"time"
"unsafe"
)
@klauspost
klauspost / main.go
Last active August 10, 2023 07:49
Simple dict builder
package main
import (
"encoding/binary"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
package floats
import (
"fmt"
"math"
"math/bits"
"github.com/klauspost/compress/fse"
)

NG byte aligned compression

Intro

This is trying to combine the lessons learned from LZ4, Snappy, S2 and friends.

  • LZ4: Allow matches > 65536. More efficient long matches. More efficient short offsets.
  • Snappy: Improve the max match length. More efficient longer match offsets.
  • S2: More efficient repeat storage, relative offsets. Add 24 bits copy lengths.
@klauspost
klauspost / rngbuffer.go
Created February 27, 2023 13:08
Buffered Intn.
type rngBuffer struct {
bitsLeft int
buffer [32]byte
}
// Intn returns, as an int, a non-negative random number in the half-open interval [0,n).
// It panics if n <= 0.
func (r *rngBuffer) Intn(n int) int {
if n <= 0 {
panic("invalid argument to Intn")
package main_test
import (
"crypto/sha1"
"math/rand"
"testing"
"github.com/zeebo/xxh3"
)
@klauspost
klauspost / main.go
Created October 20, 2022 14:38
css-reorder-experiment
package main
import (
"bytes"
"fmt"
"math"
"os"
"github.com/klauspost/compress/gzip"
"github.com/klauspost/compress/zstd"
//go:build ignore
// +build ignore
package main
// Adapted from : https://gist.github.com/arnehormann/65421048f56ac108f6b5
import (
"bufio"
"bytes"