Skip to content

Commit

Permalink
refactor: lzssv2 -> lzss
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabaie committed Nov 13, 2023
1 parent cb95d21 commit 36e35a2
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 15 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lzss_v2
package lzss

import (
"math"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"fmt"
"github.com/consensys/gnark/std/compress"
"github.com/consensys/gnark/std/compress/lzss_v2"
"github.com/consensys/gnark/std/compress/lzss"
)

// executable to generate the constraints for the circuit and store it
Expand All @@ -14,7 +14,7 @@ func check(e error) {
}

func main() {
cs, err := lzss_v2.BenchCompressionE2ECompilation(nil, "../../test_cases/large")
cs, err := lzss.BenchCompressionE2ECompilation(nil, "../../test_cases/large")
check(err)

fmt.Println(cs.GetNbConstraints(), "constraints")
Expand Down
21 changes: 15 additions & 6 deletions std/compress/lzss_v2/compress.go → std/compress/lzss/compress.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package lzss_v2
package lzss

import (
"bytes"
"fmt"
"math/bits"

"github.com/consensys/gnark/std/compress/lzss_v2/suffixarray"
"github.com/consensys/gnark/std/compress/lzss/suffixarray"
"github.com/icza/bitio"
)

Expand All @@ -22,8 +22,17 @@ type Compressor struct {
dictSa [maxDictSize]int32 // suffix array space.
}

type CompressionMode uint8

const (
BestCompression CompressionMode = 1
GoodCompression CompressionMode = 2
GoodSnarkDecompression CompressionMode = 4
BestSnarkDecompression CompressionMode = 8
)

// NewCompressor returns a new compressor with the given dictionary
func NewCompressor(dict []byte) (*Compressor, error) {
func NewCompressor(dict []byte, compressionMode CompressionMode) (*Compressor, error) {
dict = augmentDict(dict)
if len(dict) > maxDictSize {
return nil, fmt.Errorf("dict size must be <= %d", maxDictSize)
Expand All @@ -40,8 +49,8 @@ func augmentDict(dict []byte) []byte {
return append(dict, symbolDict, symbolShort, symbolLong)
}

func initDictBackref(dict []byte) backrefType {
addrNbBits := uint8(bits.Len(uint(len(dict))))
func (compressor *Compressor) initDictBackref() backrefType {
addrNbBits := uint8(bits.Len(uint(len(compressor.dictData))))
return newBackRefType(symbolDict, (addrNbBits+forceDivisibleBy-1)/forceDivisibleBy*forceDivisibleBy, 8, true)
}

Expand All @@ -59,7 +68,7 @@ func (compressor *Compressor) Compress(d []byte) (c []byte, err error) {
// build the index
compressor.inputIndex = suffixarray.New(d, compressor.inputSa[:len(d)])

dictBackRefType := initDictBackref(compressor.dictData)
dictBackRefType := compressor.initDictBackref()

bDict := backref{bType: dictBackRefType, length: -1, offset: -1}
bShort := backref{bType: shortBackRefType, length: -1, offset: -1}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lzss_v2
package lzss

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lzss_v2
package lzss

import (
"bytes"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lzss_v2
package lzss

import (
"github.com/consensys/gnark-crypto/ecc"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lzss_v2
package lzss

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lzss_v2
package lzss

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lzss_v2
package lzss

import (
"fmt"
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 36e35a2

Please sign in to comment.