Skip to content

Instantly share code, notes, and snippets.

@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"
//go:build amd64 && !appengine && !noasm && gc
// +build amd64,!appengine,!noasm,gc
// This file contains the specialisation of Decoder.Decompress4X
// that uses an asm implementation of its main loop.
package huff0
import (
"errors"
"fmt"
//go:build amd64 && !appengine && !noasm && gc
// +build amd64,!appengine,!noasm,gc
// This file contains the specialisation of Decoder.Decompress4X
// that uses an asm implementation of its main loop.
package huff0
import (
"errors"
"fmt"
package main
//go:generate go run gen.go -out decompress_amd64_avo.s -stubs delme.go -pkg=huff0
import (
"flag"
"io/ioutil"
"os"
"path/filepath"
"strconv"