58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"middleout-compression/middleout"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
// Use clusterSize=8, maxFractal=3 for optimized compression
|
|
compressor := middleout.NewMOSCCompressor(0.1, 8, 3)
|
|
data := []byte(strings.Repeat("abcd", 1000)) // 4000 bytes
|
|
|
|
compressed, err := compressor.Compress(data)
|
|
if err != nil {
|
|
fmt.Println("Compression error:", err)
|
|
return
|
|
}
|
|
fmt.Printf("Original size: %d bytes\n", len(data))
|
|
fmt.Printf("Compressed size: %d bytes\n", len(compressed))
|
|
fmt.Printf("Compression ratio: %.2f%%\n", (float64(len(compressed))/float64(len(data))*100))
|
|
|
|
decompressed, err := compressor.Decompress(compressed)
|
|
if err != nil {
|
|
fmt.Println("Decompression error:", err)
|
|
return
|
|
}
|
|
fmt.Printf("Decompressed data length: %d bytes\n", len(decompressed))
|
|
|
|
if string(decompressed) == string(data) {
|
|
fmt.Println("Success: Decompressed data matches original!")
|
|
} else {
|
|
fmt.Println("Failure: Decompressed data does not match original.")
|
|
logLen := len(decompressed)
|
|
if logLen > 100 {
|
|
logLen = 100
|
|
}
|
|
fmt.Printf("Decompressed first %d bytes: %v\n", logLen, decompressed[:logLen])
|
|
// Log first mismatch
|
|
for i := 0; i < len(decompressed) && i < len(data); i++ {
|
|
if decompressed[i] != data[i] {
|
|
start := i - 5
|
|
if start < 0 {
|
|
start = 0
|
|
}
|
|
end := i + 5
|
|
if end > len(decompressed) {
|
|
end = len(decompressed)
|
|
}
|
|
if end > len(data) {
|
|
end = len(data)
|
|
}
|
|
fmt.Printf("First mismatch at position %d: got %d, want %d; surrounding got %v, want %v\n", i, decompressed[i], data[i], decompressed[start:end], data[start:end])
|
|
break
|
|
}
|
|
}
|
|
}
|
|
} |