id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
8,300 | klauspost/compress | huff0/compress.go | huffSort | func (s *Scratch) huffSort() {
type rankPos struct {
base uint32
current uint32
}
// Clear nodes
nodes := s.nodes[:huffNodesLen+1]
s.nodes = nodes
nodes = nodes[1 : huffNodesLen+1]
// Sort into buckets based on length of symbol count.
var rank [32]rankPos
for _, v := range s.count[:s.symbolLen] {
r := highBit32(v+1) & 31
rank[r].base++
}
for n := 30; n > 0; n-- {
rank[n-1].base += rank[n].base
}
for n := range rank[:] {
rank[n].current = rank[n].base
}
for n, c := range s.count[:s.symbolLen] {
r := (highBit32(c+1) + 1) & 31
pos := rank[r].current
rank[r].current++
prev := nodes[(pos-1)&huffNodesMask]
for pos > rank[r].base && c > prev.count {
nodes[pos&huffNodesMask] = prev
pos--
prev = nodes[(pos-1)&huffNodesMask]
}
nodes[pos&huffNodesMask] = nodeElt{count: c, symbol: byte(n)}
}
return
} | go | func (s *Scratch) huffSort() {
type rankPos struct {
base uint32
current uint32
}
// Clear nodes
nodes := s.nodes[:huffNodesLen+1]
s.nodes = nodes
nodes = nodes[1 : huffNodesLen+1]
// Sort into buckets based on length of symbol count.
var rank [32]rankPos
for _, v := range s.count[:s.symbolLen] {
r := highBit32(v+1) & 31
rank[r].base++
}
for n := 30; n > 0; n-- {
rank[n-1].base += rank[n].base
}
for n := range rank[:] {
rank[n].current = rank[n].base
}
for n, c := range s.count[:s.symbolLen] {
r := (highBit32(c+1) + 1) & 31
pos := rank[r].current
rank[r].current++
prev := nodes[(pos-1)&huffNodesMask]
for pos > rank[r].base && c > prev.count {
nodes[pos&huffNodesMask] = prev
pos--
prev = nodes[(pos-1)&huffNodesMask]
}
nodes[pos&huffNodesMask] = nodeElt{count: c, symbol: byte(n)}
}
return
} | [
"func",
"(",
"s",
"*",
"Scratch",
")",
"huffSort",
"(",
")",
"{",
"type",
"rankPos",
"struct",
"{",
"base",
"uint32",
"\n",
"current",
"uint32",
"\n",
"}",
"\n\n",
"// Clear nodes",
"nodes",
":=",
"s",
".",
"nodes",
"[",
":",
"huffNodesLen",
"+",
"1",
... | // huffSort will sort symbols, decreasing order. | [
"huffSort",
"will",
"sort",
"symbols",
"decreasing",
"order",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/huff0/compress.go#L455-L491 |
8,301 | klauspost/compress | zlib/writer.go | NewWriter | func NewWriter(w io.Writer) *Writer {
z, _ := NewWriterLevelDict(w, DefaultCompression, nil)
return z
} | go | func NewWriter(w io.Writer) *Writer {
z, _ := NewWriterLevelDict(w, DefaultCompression, nil)
return z
} | [
"func",
"NewWriter",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"Writer",
"{",
"z",
",",
"_",
":=",
"NewWriterLevelDict",
"(",
"w",
",",
"DefaultCompression",
",",
"nil",
")",
"\n",
"return",
"z",
"\n",
"}"
] | // NewWriter creates a new Writer.
// Writes to the returned Writer are compressed and written to w.
//
// It is the caller's responsibility to call Close on the WriteCloser when done.
// Writes may be buffered and not flushed until Close. | [
"NewWriter",
"creates",
"a",
"new",
"Writer",
".",
"Writes",
"to",
"the",
"returned",
"Writer",
"are",
"compressed",
"and",
"written",
"to",
"w",
".",
"It",
"is",
"the",
"caller",
"s",
"responsibility",
"to",
"call",
"Close",
"on",
"the",
"WriteCloser",
"w... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zlib/writer.go#L45-L48 |
8,302 | klauspost/compress | zlib/writer.go | NewWriterLevel | func NewWriterLevel(w io.Writer, level int) (*Writer, error) {
return NewWriterLevelDict(w, level, nil)
} | go | func NewWriterLevel(w io.Writer, level int) (*Writer, error) {
return NewWriterLevelDict(w, level, nil)
} | [
"func",
"NewWriterLevel",
"(",
"w",
"io",
".",
"Writer",
",",
"level",
"int",
")",
"(",
"*",
"Writer",
",",
"error",
")",
"{",
"return",
"NewWriterLevelDict",
"(",
"w",
",",
"level",
",",
"nil",
")",
"\n",
"}"
] | // NewWriterLevel is like NewWriter but specifies the compression level instead
// of assuming DefaultCompression.
//
// The compression level can be DefaultCompression, NoCompression, HuffmanOnly
// or any integer value between BestSpeed and BestCompression inclusive.
// The error returned will be nil if the level is valid. | [
"NewWriterLevel",
"is",
"like",
"NewWriter",
"but",
"specifies",
"the",
"compression",
"level",
"instead",
"of",
"assuming",
"DefaultCompression",
".",
"The",
"compression",
"level",
"can",
"be",
"DefaultCompression",
"NoCompression",
"HuffmanOnly",
"or",
"any",
"inte... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zlib/writer.go#L56-L58 |
8,303 | klauspost/compress | zlib/writer.go | NewWriterLevelDict | func NewWriterLevelDict(w io.Writer, level int, dict []byte) (*Writer, error) {
if level < HuffmanOnly || level > BestCompression {
return nil, fmt.Errorf("zlib: invalid compression level: %d", level)
}
return &Writer{
w: w,
level: level,
dict: dict,
}, nil
} | go | func NewWriterLevelDict(w io.Writer, level int, dict []byte) (*Writer, error) {
if level < HuffmanOnly || level > BestCompression {
return nil, fmt.Errorf("zlib: invalid compression level: %d", level)
}
return &Writer{
w: w,
level: level,
dict: dict,
}, nil
} | [
"func",
"NewWriterLevelDict",
"(",
"w",
"io",
".",
"Writer",
",",
"level",
"int",
",",
"dict",
"[",
"]",
"byte",
")",
"(",
"*",
"Writer",
",",
"error",
")",
"{",
"if",
"level",
"<",
"HuffmanOnly",
"||",
"level",
">",
"BestCompression",
"{",
"return",
... | // NewWriterLevelDict is like NewWriterLevel but specifies a dictionary to
// compress with.
//
// The dictionary may be nil. If not, its contents should not be modified until
// the Writer is closed. | [
"NewWriterLevelDict",
"is",
"like",
"NewWriterLevel",
"but",
"specifies",
"a",
"dictionary",
"to",
"compress",
"with",
".",
"The",
"dictionary",
"may",
"be",
"nil",
".",
"If",
"not",
"its",
"contents",
"should",
"not",
"be",
"modified",
"until",
"the",
"Writer... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zlib/writer.go#L65-L74 |
8,304 | klauspost/compress | zlib/writer.go | Reset | func (z *Writer) Reset(w io.Writer) {
z.w = w
// z.level and z.dict left unchanged.
if z.compressor != nil {
z.compressor.Reset(w)
}
if z.digest != nil {
z.digest.Reset()
}
z.err = nil
z.scratch = [4]byte{}
z.wroteHeader = false
} | go | func (z *Writer) Reset(w io.Writer) {
z.w = w
// z.level and z.dict left unchanged.
if z.compressor != nil {
z.compressor.Reset(w)
}
if z.digest != nil {
z.digest.Reset()
}
z.err = nil
z.scratch = [4]byte{}
z.wroteHeader = false
} | [
"func",
"(",
"z",
"*",
"Writer",
")",
"Reset",
"(",
"w",
"io",
".",
"Writer",
")",
"{",
"z",
".",
"w",
"=",
"w",
"\n",
"// z.level and z.dict left unchanged.",
"if",
"z",
".",
"compressor",
"!=",
"nil",
"{",
"z",
".",
"compressor",
".",
"Reset",
"(",... | // Reset clears the state of the Writer z such that it is equivalent to its
// initial state from NewWriterLevel or NewWriterLevelDict, but instead writing
// to w. | [
"Reset",
"clears",
"the",
"state",
"of",
"the",
"Writer",
"z",
"such",
"that",
"it",
"is",
"equivalent",
"to",
"its",
"initial",
"state",
"from",
"NewWriterLevel",
"or",
"NewWriterLevelDict",
"but",
"instead",
"writing",
"to",
"w",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zlib/writer.go#L79-L91 |
8,305 | klauspost/compress | zlib/writer.go | writeHeader | func (z *Writer) writeHeader() (err error) {
z.wroteHeader = true
// ZLIB has a two-byte header (as documented in RFC 1950).
// The first four bits is the CINFO (compression info), which is 7 for the default deflate window size.
// The next four bits is the CM (compression method), which is 8 for deflate.
z.scratch[0] = 0x78
// The next two bits is the FLEVEL (compression level). The four values are:
// 0=fastest, 1=fast, 2=default, 3=best.
// The next bit, FDICT, is set if a dictionary is given.
// The final five FCHECK bits form a mod-31 checksum.
switch z.level {
case -2, 0, 1:
z.scratch[1] = 0 << 6
case 2, 3, 4, 5:
z.scratch[1] = 1 << 6
case 6, -1:
z.scratch[1] = 2 << 6
case 7, 8, 9:
z.scratch[1] = 3 << 6
default:
panic("unreachable")
}
if z.dict != nil {
z.scratch[1] |= 1 << 5
}
z.scratch[1] += uint8(31 - (uint16(z.scratch[0])<<8+uint16(z.scratch[1]))%31)
if _, err = z.w.Write(z.scratch[0:2]); err != nil {
return err
}
if z.dict != nil {
// The next four bytes are the Adler-32 checksum of the dictionary.
checksum := adler32.Checksum(z.dict)
z.scratch[0] = uint8(checksum >> 24)
z.scratch[1] = uint8(checksum >> 16)
z.scratch[2] = uint8(checksum >> 8)
z.scratch[3] = uint8(checksum >> 0)
if _, err = z.w.Write(z.scratch[0:4]); err != nil {
return err
}
}
if z.compressor == nil {
// Initialize deflater unless the Writer is being reused
// after a Reset call.
z.compressor, err = flate.NewWriterDict(z.w, z.level, z.dict)
if err != nil {
return err
}
z.digest = adler32.New()
}
return nil
} | go | func (z *Writer) writeHeader() (err error) {
z.wroteHeader = true
// ZLIB has a two-byte header (as documented in RFC 1950).
// The first four bits is the CINFO (compression info), which is 7 for the default deflate window size.
// The next four bits is the CM (compression method), which is 8 for deflate.
z.scratch[0] = 0x78
// The next two bits is the FLEVEL (compression level). The four values are:
// 0=fastest, 1=fast, 2=default, 3=best.
// The next bit, FDICT, is set if a dictionary is given.
// The final five FCHECK bits form a mod-31 checksum.
switch z.level {
case -2, 0, 1:
z.scratch[1] = 0 << 6
case 2, 3, 4, 5:
z.scratch[1] = 1 << 6
case 6, -1:
z.scratch[1] = 2 << 6
case 7, 8, 9:
z.scratch[1] = 3 << 6
default:
panic("unreachable")
}
if z.dict != nil {
z.scratch[1] |= 1 << 5
}
z.scratch[1] += uint8(31 - (uint16(z.scratch[0])<<8+uint16(z.scratch[1]))%31)
if _, err = z.w.Write(z.scratch[0:2]); err != nil {
return err
}
if z.dict != nil {
// The next four bytes are the Adler-32 checksum of the dictionary.
checksum := adler32.Checksum(z.dict)
z.scratch[0] = uint8(checksum >> 24)
z.scratch[1] = uint8(checksum >> 16)
z.scratch[2] = uint8(checksum >> 8)
z.scratch[3] = uint8(checksum >> 0)
if _, err = z.w.Write(z.scratch[0:4]); err != nil {
return err
}
}
if z.compressor == nil {
// Initialize deflater unless the Writer is being reused
// after a Reset call.
z.compressor, err = flate.NewWriterDict(z.w, z.level, z.dict)
if err != nil {
return err
}
z.digest = adler32.New()
}
return nil
} | [
"func",
"(",
"z",
"*",
"Writer",
")",
"writeHeader",
"(",
")",
"(",
"err",
"error",
")",
"{",
"z",
".",
"wroteHeader",
"=",
"true",
"\n",
"// ZLIB has a two-byte header (as documented in RFC 1950).",
"// The first four bits is the CINFO (compression info), which is 7 for th... | // writeHeader writes the ZLIB header. | [
"writeHeader",
"writes",
"the",
"ZLIB",
"header",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zlib/writer.go#L94-L144 |
8,306 | klauspost/compress | zlib/writer.go | Write | func (z *Writer) Write(p []byte) (n int, err error) {
if !z.wroteHeader {
z.err = z.writeHeader()
}
if z.err != nil {
return 0, z.err
}
if len(p) == 0 {
return 0, nil
}
n, err = z.compressor.Write(p)
if err != nil {
z.err = err
return
}
z.digest.Write(p)
return
} | go | func (z *Writer) Write(p []byte) (n int, err error) {
if !z.wroteHeader {
z.err = z.writeHeader()
}
if z.err != nil {
return 0, z.err
}
if len(p) == 0 {
return 0, nil
}
n, err = z.compressor.Write(p)
if err != nil {
z.err = err
return
}
z.digest.Write(p)
return
} | [
"func",
"(",
"z",
"*",
"Writer",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"if",
"!",
"z",
".",
"wroteHeader",
"{",
"z",
".",
"err",
"=",
"z",
".",
"writeHeader",
"(",
")",
"\n",
"}",
"\n... | // Write writes a compressed form of p to the underlying io.Writer. The
// compressed bytes are not necessarily flushed until the Writer is closed or
// explicitly flushed. | [
"Write",
"writes",
"a",
"compressed",
"form",
"of",
"p",
"to",
"the",
"underlying",
"io",
".",
"Writer",
".",
"The",
"compressed",
"bytes",
"are",
"not",
"necessarily",
"flushed",
"until",
"the",
"Writer",
"is",
"closed",
"or",
"explicitly",
"flushed",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zlib/writer.go#L149-L166 |
8,307 | klauspost/compress | zip/writer.go | NewWriter | func NewWriter(w io.Writer) *Writer {
return &Writer{cw: &countWriter{w: bufio.NewWriter(w)}}
} | go | func NewWriter(w io.Writer) *Writer {
return &Writer{cw: &countWriter{w: bufio.NewWriter(w)}}
} | [
"func",
"NewWriter",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"Writer",
"{",
"return",
"&",
"Writer",
"{",
"cw",
":",
"&",
"countWriter",
"{",
"w",
":",
"bufio",
".",
"NewWriter",
"(",
"w",
")",
"}",
"}",
"\n",
"}"
] | // NewWriter returns a new Writer writing a zip file to w. | [
"NewWriter",
"returns",
"a",
"new",
"Writer",
"writing",
"a",
"zip",
"file",
"to",
"w",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/writer.go#L33-L35 |
8,308 | klauspost/compress | zip/writer.go | SetOffset | func (w *Writer) SetOffset(n int64) {
if w.cw.count != 0 {
panic("zip: SetOffset called after data was written")
}
w.cw.count = n
} | go | func (w *Writer) SetOffset(n int64) {
if w.cw.count != 0 {
panic("zip: SetOffset called after data was written")
}
w.cw.count = n
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"SetOffset",
"(",
"n",
"int64",
")",
"{",
"if",
"w",
".",
"cw",
".",
"count",
"!=",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"w",
".",
"cw",
".",
"count",
"=",
"n",
"\n",
"}"
] | // SetOffset sets the offset of the beginning of the zip data within the
// underlying writer. It should be used when the zip data is appended to an
// existing file, such as a binary executable.
// It must be called before any data is written. | [
"SetOffset",
"sets",
"the",
"offset",
"of",
"the",
"beginning",
"of",
"the",
"zip",
"data",
"within",
"the",
"underlying",
"writer",
".",
"It",
"should",
"be",
"used",
"when",
"the",
"zip",
"data",
"is",
"appended",
"to",
"an",
"existing",
"file",
"such",
... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/writer.go#L41-L46 |
8,309 | klauspost/compress | zip/writer.go | Flush | func (w *Writer) Flush() error {
return w.cw.w.(*bufio.Writer).Flush()
} | go | func (w *Writer) Flush() error {
return w.cw.w.(*bufio.Writer).Flush()
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"Flush",
"(",
")",
"error",
"{",
"return",
"w",
".",
"cw",
".",
"w",
".",
"(",
"*",
"bufio",
".",
"Writer",
")",
".",
"Flush",
"(",
")",
"\n",
"}"
] | // Flush flushes any buffered data to the underlying writer.
// Calling Flush is not normally necessary; calling Close is sufficient. | [
"Flush",
"flushes",
"any",
"buffered",
"data",
"to",
"the",
"underlying",
"writer",
".",
"Calling",
"Flush",
"is",
"not",
"normally",
"necessary",
";",
"calling",
"Close",
"is",
"sufficient",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/writer.go#L50-L52 |
8,310 | klauspost/compress | zip/writer.go | RegisterCompressor | func (w *Writer) RegisterCompressor(method uint16, comp Compressor) {
if w.compressors == nil {
w.compressors = make(map[uint16]Compressor)
}
w.compressors[method] = comp
} | go | func (w *Writer) RegisterCompressor(method uint16, comp Compressor) {
if w.compressors == nil {
w.compressors = make(map[uint16]Compressor)
}
w.compressors[method] = comp
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"RegisterCompressor",
"(",
"method",
"uint16",
",",
"comp",
"Compressor",
")",
"{",
"if",
"w",
".",
"compressors",
"==",
"nil",
"{",
"w",
".",
"compressors",
"=",
"make",
"(",
"map",
"[",
"uint16",
"]",
"Compressor... | // RegisterCompressor registers or overrides a custom compressor for a specific
// method ID. If a compressor for a given method is not found, Writer will
// default to looking up the compressor at the package level. | [
"RegisterCompressor",
"registers",
"or",
"overrides",
"a",
"custom",
"compressor",
"for",
"a",
"specific",
"method",
"ID",
".",
"If",
"a",
"compressor",
"for",
"a",
"given",
"method",
"is",
"not",
"found",
"Writer",
"will",
"default",
"to",
"looking",
"up",
... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/writer.go#L276-L281 |
8,311 | klauspost/compress | huff0/huff0.go | estimateSize | func (c cTable) estimateSize(hist []uint32) int {
nbBits := uint32(7)
for i, v := range c[:len(hist)] {
nbBits += uint32(v.nBits) * hist[i]
}
return int(nbBits >> 3)
} | go | func (c cTable) estimateSize(hist []uint32) int {
nbBits := uint32(7)
for i, v := range c[:len(hist)] {
nbBits += uint32(v.nBits) * hist[i]
}
return int(nbBits >> 3)
} | [
"func",
"(",
"c",
"cTable",
")",
"estimateSize",
"(",
"hist",
"[",
"]",
"uint32",
")",
"int",
"{",
"nbBits",
":=",
"uint32",
"(",
"7",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"c",
"[",
":",
"len",
"(",
"hist",
")",
"]",
"{",
"nbBits",
... | // estimateSize returns the estimated size in bytes of the input represented in the
// histogram supplied. | [
"estimateSize",
"returns",
"the",
"estimated",
"size",
"in",
"bytes",
"of",
"the",
"input",
"represented",
"in",
"the",
"histogram",
"supplied",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/huff0/huff0.go#L217-L223 |
8,312 | klauspost/compress | huff0/huff0.go | minSize | func (s *Scratch) minSize(total int) int {
nbBits := float64(7)
fTotal := float64(total)
for _, v := range s.count[:s.symbolLen] {
n := float64(v)
if n > 0 {
nbBits += math.Log2(fTotal/n) * n
}
}
return int(nbBits) >> 3
} | go | func (s *Scratch) minSize(total int) int {
nbBits := float64(7)
fTotal := float64(total)
for _, v := range s.count[:s.symbolLen] {
n := float64(v)
if n > 0 {
nbBits += math.Log2(fTotal/n) * n
}
}
return int(nbBits) >> 3
} | [
"func",
"(",
"s",
"*",
"Scratch",
")",
"minSize",
"(",
"total",
"int",
")",
"int",
"{",
"nbBits",
":=",
"float64",
"(",
"7",
")",
"\n",
"fTotal",
":=",
"float64",
"(",
"total",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"s",
".",
"count",
... | // minSize returns the minimum possible size considering the shannon limit. | [
"minSize",
"returns",
"the",
"minimum",
"possible",
"size",
"considering",
"the",
"shannon",
"limit",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/huff0/huff0.go#L226-L236 |
8,313 | klauspost/compress | zstd/fse_decoder.go | decSymbolValue | func decSymbolValue(symb uint8, t []baseOffset) (decSymbol, error) {
if int(symb) >= len(t) {
return decSymbol{}, fmt.Errorf("rle symbol %d >= max %d", symb, len(t))
}
lu := t[symb]
return decSymbol{
addBits: lu.addBits,
baseline: lu.baseLine,
}, nil
} | go | func decSymbolValue(symb uint8, t []baseOffset) (decSymbol, error) {
if int(symb) >= len(t) {
return decSymbol{}, fmt.Errorf("rle symbol %d >= max %d", symb, len(t))
}
lu := t[symb]
return decSymbol{
addBits: lu.addBits,
baseline: lu.baseLine,
}, nil
} | [
"func",
"decSymbolValue",
"(",
"symb",
"uint8",
",",
"t",
"[",
"]",
"baseOffset",
")",
"(",
"decSymbol",
",",
"error",
")",
"{",
"if",
"int",
"(",
"symb",
")",
">=",
"len",
"(",
"t",
")",
"{",
"return",
"decSymbol",
"{",
"}",
",",
"fmt",
".",
"Er... | // decSymbolValue returns the transformed decSymbol for the given symbol. | [
"decSymbolValue",
"returns",
"the",
"transformed",
"decSymbol",
"for",
"the",
"given",
"symbol",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/fse_decoder.go#L186-L195 |
8,314 | klauspost/compress | zstd/fse_decoder.go | setRLE | func (s *fseDecoder) setRLE(symbol decSymbol) {
s.actualTableLog = 0
s.maxBits = 0
s.dt[0] = symbol
} | go | func (s *fseDecoder) setRLE(symbol decSymbol) {
s.actualTableLog = 0
s.maxBits = 0
s.dt[0] = symbol
} | [
"func",
"(",
"s",
"*",
"fseDecoder",
")",
"setRLE",
"(",
"symbol",
"decSymbol",
")",
"{",
"s",
".",
"actualTableLog",
"=",
"0",
"\n",
"s",
".",
"maxBits",
"=",
"0",
"\n",
"s",
".",
"dt",
"[",
"0",
"]",
"=",
"symbol",
"\n",
"}"
] | // setRLE will set the decoder til RLE mode. | [
"setRLE",
"will",
"set",
"the",
"decoder",
"til",
"RLE",
"mode",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/fse_decoder.go#L198-L202 |
8,315 | klauspost/compress | zstd/fse_decoder.go | transform | func (s *fseDecoder) transform(t []baseOffset) error {
tableSize := uint16(1 << s.actualTableLog)
s.maxBits = 0
for i, v := range s.dt[:tableSize] {
if int(v.addBits) >= len(t) {
return fmt.Errorf("invalid decoding table entry %d, symbol %d >= max (%d)", i, v.addBits, len(t))
}
lu := t[v.addBits]
if lu.addBits > s.maxBits {
s.maxBits = lu.addBits
}
s.dt[i&maxTableMask] = decSymbol{
newState: v.newState,
nbBits: v.nbBits,
addBits: lu.addBits,
baseline: lu.baseLine,
}
}
return nil
} | go | func (s *fseDecoder) transform(t []baseOffset) error {
tableSize := uint16(1 << s.actualTableLog)
s.maxBits = 0
for i, v := range s.dt[:tableSize] {
if int(v.addBits) >= len(t) {
return fmt.Errorf("invalid decoding table entry %d, symbol %d >= max (%d)", i, v.addBits, len(t))
}
lu := t[v.addBits]
if lu.addBits > s.maxBits {
s.maxBits = lu.addBits
}
s.dt[i&maxTableMask] = decSymbol{
newState: v.newState,
nbBits: v.nbBits,
addBits: lu.addBits,
baseline: lu.baseLine,
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"fseDecoder",
")",
"transform",
"(",
"t",
"[",
"]",
"baseOffset",
")",
"error",
"{",
"tableSize",
":=",
"uint16",
"(",
"1",
"<<",
"s",
".",
"actualTableLog",
")",
"\n",
"s",
".",
"maxBits",
"=",
"0",
"\n",
"for",
"i",
",",
... | // transform will transform the decoder table into a table usable for
// decoding without having to apply the transformation while decoding.
// The state will contain the base value and the number of bits to read. | [
"transform",
"will",
"transform",
"the",
"decoder",
"table",
"into",
"a",
"table",
"usable",
"for",
"decoding",
"without",
"having",
"to",
"apply",
"the",
"transformation",
"while",
"decoding",
".",
"The",
"state",
"will",
"contain",
"the",
"base",
"value",
"a... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/fse_decoder.go#L269-L288 |
8,316 | klauspost/compress | zstd/fse_decoder.go | init | func (s *fseState) init(br *bitReader, tableLog uint8, dt []decSymbol) {
s.dt = dt
br.fill()
s.state = dt[br.getBits(tableLog)]
} | go | func (s *fseState) init(br *bitReader, tableLog uint8, dt []decSymbol) {
s.dt = dt
br.fill()
s.state = dt[br.getBits(tableLog)]
} | [
"func",
"(",
"s",
"*",
"fseState",
")",
"init",
"(",
"br",
"*",
"bitReader",
",",
"tableLog",
"uint8",
",",
"dt",
"[",
"]",
"decSymbol",
")",
"{",
"s",
".",
"dt",
"=",
"dt",
"\n",
"br",
".",
"fill",
"(",
")",
"\n",
"s",
".",
"state",
"=",
"dt... | // Initialize and decodeAsync first state and symbol. | [
"Initialize",
"and",
"decodeAsync",
"first",
"state",
"and",
"symbol",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/fse_decoder.go#L297-L301 |
8,317 | klauspost/compress | zstd/fse_decoder.go | next | func (s *fseState) next(br *bitReader) {
lowBits := uint16(br.getBits(s.state.nbBits))
s.state = s.dt[s.state.newState+lowBits]
} | go | func (s *fseState) next(br *bitReader) {
lowBits := uint16(br.getBits(s.state.nbBits))
s.state = s.dt[s.state.newState+lowBits]
} | [
"func",
"(",
"s",
"*",
"fseState",
")",
"next",
"(",
"br",
"*",
"bitReader",
")",
"{",
"lowBits",
":=",
"uint16",
"(",
"br",
".",
"getBits",
"(",
"s",
".",
"state",
".",
"nbBits",
")",
")",
"\n",
"s",
".",
"state",
"=",
"s",
".",
"dt",
"[",
"... | // next returns the current symbol and sets the next state.
// At least tablelog bits must be available in the bit reader. | [
"next",
"returns",
"the",
"current",
"symbol",
"and",
"sets",
"the",
"next",
"state",
".",
"At",
"least",
"tablelog",
"bits",
"must",
"be",
"available",
"in",
"the",
"bit",
"reader",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/fse_decoder.go#L305-L308 |
8,318 | klauspost/compress | zstd/fse_decoder.go | final | func (s *fseState) final() (int, uint8) {
return int(s.state.baseline), s.state.addBits
} | go | func (s *fseState) final() (int, uint8) {
return int(s.state.baseline), s.state.addBits
} | [
"func",
"(",
"s",
"*",
"fseState",
")",
"final",
"(",
")",
"(",
"int",
",",
"uint8",
")",
"{",
"return",
"int",
"(",
"s",
".",
"state",
".",
"baseline",
")",
",",
"s",
".",
"state",
".",
"addBits",
"\n",
"}"
] | // final returns the current state symbol without decoding the next. | [
"final",
"returns",
"the",
"current",
"state",
"symbol",
"without",
"decoding",
"the",
"next",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/fse_decoder.go#L317-L319 |
8,319 | klauspost/compress | zlib/reader.go | NewReader | func NewReader(r io.Reader) (io.ReadCloser, error) {
return NewReaderDict(r, nil)
} | go | func NewReader(r io.Reader) (io.ReadCloser, error) {
return NewReaderDict(r, nil)
} | [
"func",
"NewReader",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"return",
"NewReaderDict",
"(",
"r",
",",
"nil",
")",
"\n",
"}"
] | // NewReader creates a new ReadCloser.
// Reads from the returned ReadCloser read and decompress data from r.
// If r does not implement io.ByteReader, the decompressor may read more
// data than necessary from r.
// It is the caller's responsibility to call Close on the ReadCloser when done.
//
// The ReadCloser returned by NewReader also implements Resetter. | [
"NewReader",
"creates",
"a",
"new",
"ReadCloser",
".",
"Reads",
"from",
"the",
"returned",
"ReadCloser",
"read",
"and",
"decompress",
"data",
"from",
"r",
".",
"If",
"r",
"does",
"not",
"implement",
"io",
".",
"ByteReader",
"the",
"decompressor",
"may",
"rea... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zlib/reader.go#L71-L73 |
8,320 | klauspost/compress | zlib/reader.go | NewReaderDict | func NewReaderDict(r io.Reader, dict []byte) (io.ReadCloser, error) {
z := new(reader)
err := z.Reset(r, dict)
if err != nil {
return nil, err
}
return z, nil
} | go | func NewReaderDict(r io.Reader, dict []byte) (io.ReadCloser, error) {
z := new(reader)
err := z.Reset(r, dict)
if err != nil {
return nil, err
}
return z, nil
} | [
"func",
"NewReaderDict",
"(",
"r",
"io",
".",
"Reader",
",",
"dict",
"[",
"]",
"byte",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"z",
":=",
"new",
"(",
"reader",
")",
"\n",
"err",
":=",
"z",
".",
"Reset",
"(",
"r",
",",
"dict",... | // NewReaderDict is like NewReader but uses a preset dictionary.
// NewReaderDict ignores the dictionary if the compressed data does not refer to it.
// If the compressed data refers to a different dictionary, NewReaderDict returns ErrDictionary.
//
// The ReadCloser returned by NewReaderDict also implements Resetter. | [
"NewReaderDict",
"is",
"like",
"NewReader",
"but",
"uses",
"a",
"preset",
"dictionary",
".",
"NewReaderDict",
"ignores",
"the",
"dictionary",
"if",
"the",
"compressed",
"data",
"does",
"not",
"refer",
"to",
"it",
".",
"If",
"the",
"compressed",
"data",
"refers... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zlib/reader.go#L80-L87 |
8,321 | klauspost/compress | zlib/reader.go | Close | func (z *reader) Close() error {
if z.err != nil && z.err != io.EOF {
return z.err
}
z.err = z.decompressor.Close()
return z.err
} | go | func (z *reader) Close() error {
if z.err != nil && z.err != io.EOF {
return z.err
}
z.err = z.decompressor.Close()
return z.err
} | [
"func",
"(",
"z",
"*",
"reader",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"z",
".",
"err",
"!=",
"nil",
"&&",
"z",
".",
"err",
"!=",
"io",
".",
"EOF",
"{",
"return",
"z",
".",
"err",
"\n",
"}",
"\n",
"z",
".",
"err",
"=",
"z",
".",
"de... | // Calling Close does not close the wrapped io.Reader originally passed to NewReader.
// In order for the ZLIB checksum to be verified, the reader must be
// fully consumed until the io.EOF. | [
"Calling",
"Close",
"does",
"not",
"close",
"the",
"wrapped",
"io",
".",
"Reader",
"originally",
"passed",
"to",
"NewReader",
".",
"In",
"order",
"for",
"the",
"ZLIB",
"checksum",
"to",
"be",
"verified",
"the",
"reader",
"must",
"be",
"fully",
"consumed",
... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zlib/reader.go#L122-L128 |
8,322 | klauspost/compress | zstd/history.go | reset | func (h *history) reset() {
h.b = h.b[:0]
h.error = false
h.recentOffsets = [3]int{1, 4, 8}
if f := h.decoders.litLengths.fse; f != nil && !f.preDefined {
fseDecoderPool.Put(f)
}
if f := h.decoders.offsets.fse; f != nil && !f.preDefined {
fseDecoderPool.Put(f)
}
if f := h.decoders.matchLengths.fse; f != nil && !f.preDefined {
fseDecoderPool.Put(f)
}
h.decoders = sequenceDecs{}
if h.huffTree != nil {
huffDecoderPool.Put(h.huffTree)
}
h.huffTree = nil
//printf("history created: %+v (l: %d, c: %d)", *h, len(h.b), cap(h.b))
} | go | func (h *history) reset() {
h.b = h.b[:0]
h.error = false
h.recentOffsets = [3]int{1, 4, 8}
if f := h.decoders.litLengths.fse; f != nil && !f.preDefined {
fseDecoderPool.Put(f)
}
if f := h.decoders.offsets.fse; f != nil && !f.preDefined {
fseDecoderPool.Put(f)
}
if f := h.decoders.matchLengths.fse; f != nil && !f.preDefined {
fseDecoderPool.Put(f)
}
h.decoders = sequenceDecs{}
if h.huffTree != nil {
huffDecoderPool.Put(h.huffTree)
}
h.huffTree = nil
//printf("history created: %+v (l: %d, c: %d)", *h, len(h.b), cap(h.b))
} | [
"func",
"(",
"h",
"*",
"history",
")",
"reset",
"(",
")",
"{",
"h",
".",
"b",
"=",
"h",
".",
"b",
"[",
":",
"0",
"]",
"\n",
"h",
".",
"error",
"=",
"false",
"\n",
"h",
".",
"recentOffsets",
"=",
"[",
"3",
"]",
"int",
"{",
"1",
",",
"4",
... | // reset will reset the history to initial state of a frame.
// The history must already have been initialized to the desired size. | [
"reset",
"will",
"reset",
"the",
"history",
"to",
"initial",
"state",
"of",
"a",
"frame",
".",
"The",
"history",
"must",
"already",
"have",
"been",
"initialized",
"to",
"the",
"desired",
"size",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/history.go#L24-L43 |
8,323 | klauspost/compress | zstd/history.go | append | func (h *history) append(b []byte) {
if len(b) >= h.windowSize {
// Discard all history by simply overwriting
h.b = h.b[:h.windowSize]
copy(h.b, b[len(b)-h.windowSize:])
return
}
// If there is space, append it.
if len(b) < cap(h.b)-len(h.b) {
h.b = append(h.b, b...)
return
}
// Move data down so we only have window size left.
// We know we have less than window size in b at this point.
discard := len(b) + len(h.b) - h.windowSize
copy(h.b, h.b[discard:])
h.b = h.b[:h.windowSize]
copy(h.b[h.windowSize-len(b):], b)
} | go | func (h *history) append(b []byte) {
if len(b) >= h.windowSize {
// Discard all history by simply overwriting
h.b = h.b[:h.windowSize]
copy(h.b, b[len(b)-h.windowSize:])
return
}
// If there is space, append it.
if len(b) < cap(h.b)-len(h.b) {
h.b = append(h.b, b...)
return
}
// Move data down so we only have window size left.
// We know we have less than window size in b at this point.
discard := len(b) + len(h.b) - h.windowSize
copy(h.b, h.b[discard:])
h.b = h.b[:h.windowSize]
copy(h.b[h.windowSize-len(b):], b)
} | [
"func",
"(",
"h",
"*",
"history",
")",
"append",
"(",
"b",
"[",
"]",
"byte",
")",
"{",
"if",
"len",
"(",
"b",
")",
">=",
"h",
".",
"windowSize",
"{",
"// Discard all history by simply overwriting",
"h",
".",
"b",
"=",
"h",
".",
"b",
"[",
":",
"h",
... | // append bytes to history.
// This function will make sure there is space for it,
// if the buffer has been allocated with enough extra space. | [
"append",
"bytes",
"to",
"history",
".",
"This",
"function",
"will",
"make",
"sure",
"there",
"is",
"space",
"for",
"it",
"if",
"the",
"buffer",
"has",
"been",
"allocated",
"with",
"enough",
"extra",
"space",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/history.go#L48-L68 |
8,324 | klauspost/compress | zstd/history.go | appendKeep | func (h *history) appendKeep(b []byte) {
h.b = append(h.b, b...)
} | go | func (h *history) appendKeep(b []byte) {
h.b = append(h.b, b...)
} | [
"func",
"(",
"h",
"*",
"history",
")",
"appendKeep",
"(",
"b",
"[",
"]",
"byte",
")",
"{",
"h",
".",
"b",
"=",
"append",
"(",
"h",
".",
"b",
",",
"b",
"...",
")",
"\n",
"}"
] | // append bytes to history without ever discarding anything. | [
"append",
"bytes",
"to",
"history",
"without",
"ever",
"discarding",
"anything",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/history.go#L71-L73 |
8,325 | klauspost/compress | huff0/decompress.go | Decompress1X | func (s *Scratch) Decompress1X(in []byte) (out []byte, err error) {
if len(s.dt.single) == 0 {
return nil, errors.New("no table loaded")
}
var br bitReader
err = br.init(in)
if err != nil {
return nil, err
}
s.Out = s.Out[:0]
decode := func() byte {
val := br.peekBitsFast(s.actualTableLog) /* note : actualTableLog >= 1 */
v := s.dt.single[val]
br.bitsRead += v.nBits
return v.byte
}
hasDec := func(v dEntrySingle) byte {
br.bitsRead += v.nBits
return v.byte
}
// Avoid bounds check by always having full sized table.
const tlSize = 1 << tableLogMax
const tlMask = tlSize - 1
dt := s.dt.single[:tlSize]
// Use temp table to avoid bound checks/append penalty.
var tmp = s.huffWeight[:256]
var off uint8
for br.off >= 8 {
br.fillFast()
tmp[off+0] = hasDec(dt[br.peekBitsFast(s.actualTableLog)&tlMask])
tmp[off+1] = hasDec(dt[br.peekBitsFast(s.actualTableLog)&tlMask])
br.fillFast()
tmp[off+2] = hasDec(dt[br.peekBitsFast(s.actualTableLog)&tlMask])
tmp[off+3] = hasDec(dt[br.peekBitsFast(s.actualTableLog)&tlMask])
off += 4
if off == 0 {
s.Out = append(s.Out, tmp...)
}
}
s.Out = append(s.Out, tmp[:off]...)
for !br.finished() {
br.fill()
s.Out = append(s.Out, decode())
}
return s.Out, br.close()
} | go | func (s *Scratch) Decompress1X(in []byte) (out []byte, err error) {
if len(s.dt.single) == 0 {
return nil, errors.New("no table loaded")
}
var br bitReader
err = br.init(in)
if err != nil {
return nil, err
}
s.Out = s.Out[:0]
decode := func() byte {
val := br.peekBitsFast(s.actualTableLog) /* note : actualTableLog >= 1 */
v := s.dt.single[val]
br.bitsRead += v.nBits
return v.byte
}
hasDec := func(v dEntrySingle) byte {
br.bitsRead += v.nBits
return v.byte
}
// Avoid bounds check by always having full sized table.
const tlSize = 1 << tableLogMax
const tlMask = tlSize - 1
dt := s.dt.single[:tlSize]
// Use temp table to avoid bound checks/append penalty.
var tmp = s.huffWeight[:256]
var off uint8
for br.off >= 8 {
br.fillFast()
tmp[off+0] = hasDec(dt[br.peekBitsFast(s.actualTableLog)&tlMask])
tmp[off+1] = hasDec(dt[br.peekBitsFast(s.actualTableLog)&tlMask])
br.fillFast()
tmp[off+2] = hasDec(dt[br.peekBitsFast(s.actualTableLog)&tlMask])
tmp[off+3] = hasDec(dt[br.peekBitsFast(s.actualTableLog)&tlMask])
off += 4
if off == 0 {
s.Out = append(s.Out, tmp...)
}
}
s.Out = append(s.Out, tmp[:off]...)
for !br.finished() {
br.fill()
s.Out = append(s.Out, decode())
}
return s.Out, br.close()
} | [
"func",
"(",
"s",
"*",
"Scratch",
")",
"Decompress1X",
"(",
"in",
"[",
"]",
"byte",
")",
"(",
"out",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"s",
".",
"dt",
".",
"single",
")",
"==",
"0",
"{",
"return",
"nil",
",",
... | // Decompress1X will decompress a 1X encoded stream.
// The length of the supplied input must match the end of a block exactly.
// Before this is called, the table must be initialized with ReadTable unless
// the encoder re-used the table. | [
"Decompress1X",
"will",
"decompress",
"a",
"1X",
"encoded",
"stream",
".",
"The",
"length",
"of",
"the",
"supplied",
"input",
"must",
"match",
"the",
"end",
"of",
"a",
"block",
"exactly",
".",
"Before",
"this",
"is",
"called",
"the",
"table",
"must",
"be",... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/huff0/decompress.go#L156-L207 |
8,326 | klauspost/compress | huff0/decompress.go | matches | func (s *Scratch) matches(ct cTable, w io.Writer) {
if s == nil || len(s.dt.single) == 0 {
return
}
dt := s.dt.single[:1<<s.actualTableLog]
tablelog := s.actualTableLog
ok := 0
broken := 0
for sym, enc := range ct {
errs := 0
broken++
if enc.nBits == 0 {
for _, dec := range dt {
if dec.byte == byte(sym) {
fmt.Fprintf(w, "symbol %x has decoder, but no encoder\n", sym)
errs++
break
}
}
if errs == 0 {
broken--
}
continue
}
// Unused bits in input
ub := tablelog - enc.nBits
top := enc.val << ub
// decoder looks at top bits.
dec := dt[top]
if dec.nBits != enc.nBits {
fmt.Fprintf(w, "symbol 0x%x bit size mismatch (enc: %d, dec:%d).\n", sym, enc.nBits, dec.nBits)
errs++
}
if dec.byte != uint8(sym) {
fmt.Fprintf(w, "symbol 0x%x decoder output mismatch (enc: %d, dec:%d).\n", sym, sym, dec.byte)
errs++
}
if errs > 0 {
fmt.Fprintf(w, "%d errros in base, stopping\n", errs)
continue
}
// Ensure that all combinations are covered.
for i := uint16(0); i < (1 << ub); i++ {
vval := top | i
dec := dt[vval]
if dec.nBits != enc.nBits {
fmt.Fprintf(w, "symbol 0x%x bit size mismatch (enc: %d, dec:%d).\n", vval, enc.nBits, dec.nBits)
errs++
}
if dec.byte != uint8(sym) {
fmt.Fprintf(w, "symbol 0x%x decoder output mismatch (enc: %d, dec:%d).\n", vval, sym, dec.byte)
errs++
}
if errs > 20 {
fmt.Fprintf(w, "%d errros, stopping\n", errs)
break
}
}
if errs == 0 {
ok++
broken--
}
}
if broken > 0 {
fmt.Fprintf(w, "%d broken, %d ok\n", broken, ok)
}
} | go | func (s *Scratch) matches(ct cTable, w io.Writer) {
if s == nil || len(s.dt.single) == 0 {
return
}
dt := s.dt.single[:1<<s.actualTableLog]
tablelog := s.actualTableLog
ok := 0
broken := 0
for sym, enc := range ct {
errs := 0
broken++
if enc.nBits == 0 {
for _, dec := range dt {
if dec.byte == byte(sym) {
fmt.Fprintf(w, "symbol %x has decoder, but no encoder\n", sym)
errs++
break
}
}
if errs == 0 {
broken--
}
continue
}
// Unused bits in input
ub := tablelog - enc.nBits
top := enc.val << ub
// decoder looks at top bits.
dec := dt[top]
if dec.nBits != enc.nBits {
fmt.Fprintf(w, "symbol 0x%x bit size mismatch (enc: %d, dec:%d).\n", sym, enc.nBits, dec.nBits)
errs++
}
if dec.byte != uint8(sym) {
fmt.Fprintf(w, "symbol 0x%x decoder output mismatch (enc: %d, dec:%d).\n", sym, sym, dec.byte)
errs++
}
if errs > 0 {
fmt.Fprintf(w, "%d errros in base, stopping\n", errs)
continue
}
// Ensure that all combinations are covered.
for i := uint16(0); i < (1 << ub); i++ {
vval := top | i
dec := dt[vval]
if dec.nBits != enc.nBits {
fmt.Fprintf(w, "symbol 0x%x bit size mismatch (enc: %d, dec:%d).\n", vval, enc.nBits, dec.nBits)
errs++
}
if dec.byte != uint8(sym) {
fmt.Fprintf(w, "symbol 0x%x decoder output mismatch (enc: %d, dec:%d).\n", vval, sym, dec.byte)
errs++
}
if errs > 20 {
fmt.Fprintf(w, "%d errros, stopping\n", errs)
break
}
}
if errs == 0 {
ok++
broken--
}
}
if broken > 0 {
fmt.Fprintf(w, "%d broken, %d ok\n", broken, ok)
}
} | [
"func",
"(",
"s",
"*",
"Scratch",
")",
"matches",
"(",
"ct",
"cTable",
",",
"w",
"io",
".",
"Writer",
")",
"{",
"if",
"s",
"==",
"nil",
"||",
"len",
"(",
"s",
".",
"dt",
".",
"single",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"dt",
"... | // matches will compare a decoding table to a coding table.
// Errors are written to the writer.
// Nothing will be written if table is ok. | [
"matches",
"will",
"compare",
"a",
"decoding",
"table",
"to",
"a",
"coding",
"table",
".",
"Errors",
"are",
"written",
"to",
"the",
"writer",
".",
"Nothing",
"will",
"be",
"written",
"if",
"table",
"is",
"ok",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/huff0/decompress.go#L331-L397 |
8,327 | klauspost/compress | fse/decompress.go | Decompress | func Decompress(b []byte, s *Scratch) ([]byte, error) {
s, err := s.prepare(b)
if err != nil {
return nil, err
}
s.Out = s.Out[:0]
err = s.readNCount()
if err != nil {
return nil, err
}
err = s.buildDtable()
if err != nil {
return nil, err
}
err = s.decompress()
if err != nil {
return nil, err
}
return s.Out, nil
} | go | func Decompress(b []byte, s *Scratch) ([]byte, error) {
s, err := s.prepare(b)
if err != nil {
return nil, err
}
s.Out = s.Out[:0]
err = s.readNCount()
if err != nil {
return nil, err
}
err = s.buildDtable()
if err != nil {
return nil, err
}
err = s.decompress()
if err != nil {
return nil, err
}
return s.Out, nil
} | [
"func",
"Decompress",
"(",
"b",
"[",
"]",
"byte",
",",
"s",
"*",
"Scratch",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"s",
".",
"prepare",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // Decompress a block of data.
// You can provide a scratch buffer to avoid allocations.
// If nil is provided a temporary one will be allocated.
// It is possible, but by no way guaranteed that corrupt data will
// return an error.
// It is up to the caller to verify integrity of the returned data.
// Use a predefined Scrach to set maximum acceptable output size. | [
"Decompress",
"a",
"block",
"of",
"data",
".",
"You",
"can",
"provide",
"a",
"scratch",
"buffer",
"to",
"avoid",
"allocations",
".",
"If",
"nil",
"is",
"provided",
"a",
"temporary",
"one",
"will",
"be",
"allocated",
".",
"It",
"is",
"possible",
"but",
"b... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/decompress.go#L19-L39 |
8,328 | klauspost/compress | fse/decompress.go | allocDtable | func (s *Scratch) allocDtable() {
tableSize := 1 << s.actualTableLog
if cap(s.decTable) < int(tableSize) {
s.decTable = make([]decSymbol, tableSize)
}
s.decTable = s.decTable[:tableSize]
if cap(s.ct.tableSymbol) < 256 {
s.ct.tableSymbol = make([]byte, 256)
}
s.ct.tableSymbol = s.ct.tableSymbol[:256]
if cap(s.ct.stateTable) < 256 {
s.ct.stateTable = make([]uint16, 256)
}
s.ct.stateTable = s.ct.stateTable[:256]
} | go | func (s *Scratch) allocDtable() {
tableSize := 1 << s.actualTableLog
if cap(s.decTable) < int(tableSize) {
s.decTable = make([]decSymbol, tableSize)
}
s.decTable = s.decTable[:tableSize]
if cap(s.ct.tableSymbol) < 256 {
s.ct.tableSymbol = make([]byte, 256)
}
s.ct.tableSymbol = s.ct.tableSymbol[:256]
if cap(s.ct.stateTable) < 256 {
s.ct.stateTable = make([]uint16, 256)
}
s.ct.stateTable = s.ct.stateTable[:256]
} | [
"func",
"(",
"s",
"*",
"Scratch",
")",
"allocDtable",
"(",
")",
"{",
"tableSize",
":=",
"1",
"<<",
"s",
".",
"actualTableLog",
"\n",
"if",
"cap",
"(",
"s",
".",
"decTable",
")",
"<",
"int",
"(",
"tableSize",
")",
"{",
"s",
".",
"decTable",
"=",
"... | // allocDtable will allocate decoding tables if they are not big enough. | [
"allocDtable",
"will",
"allocate",
"decoding",
"tables",
"if",
"they",
"are",
"not",
"big",
"enough",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/decompress.go#L173-L189 |
8,329 | klauspost/compress | fse/decompress.go | decompress | func (s *Scratch) decompress() error {
br := &s.bits
br.init(s.br.unread())
var s1, s2 decoder
// Initialize and decode first state and symbol.
s1.init(br, s.decTable, s.actualTableLog)
s2.init(br, s.decTable, s.actualTableLog)
// Use temp table to avoid bound checks/append penalty.
var tmp = s.ct.tableSymbol[:256]
var off uint8
// Main part
if !s.zeroBits {
for br.off >= 8 {
br.fillFast()
tmp[off+0] = s1.nextFast()
tmp[off+1] = s2.nextFast()
br.fillFast()
tmp[off+2] = s1.nextFast()
tmp[off+3] = s2.nextFast()
off += 4
if off == 0 {
s.Out = append(s.Out, tmp...)
}
}
} else {
for br.off >= 8 {
br.fillFast()
tmp[off+0] = s1.next()
tmp[off+1] = s2.next()
br.fillFast()
tmp[off+2] = s1.next()
tmp[off+3] = s2.next()
off += 4
if off == 0 {
s.Out = append(s.Out, tmp...)
off = 0
if len(s.Out) >= s.DecompressLimit {
return fmt.Errorf("output size (%d) > DecompressLimit (%d)", len(s.Out), s.DecompressLimit)
}
}
}
}
s.Out = append(s.Out, tmp[:off]...)
// Final bits, a bit more expensive check
for {
if s1.finished() {
s.Out = append(s.Out, s1.final(), s2.final())
break
}
br.fill()
s.Out = append(s.Out, s1.next())
if s2.finished() {
s.Out = append(s.Out, s2.final(), s1.final())
break
}
s.Out = append(s.Out, s2.next())
if len(s.Out) >= s.DecompressLimit {
return fmt.Errorf("output size (%d) > DecompressLimit (%d)", len(s.Out), s.DecompressLimit)
}
}
return br.close()
} | go | func (s *Scratch) decompress() error {
br := &s.bits
br.init(s.br.unread())
var s1, s2 decoder
// Initialize and decode first state and symbol.
s1.init(br, s.decTable, s.actualTableLog)
s2.init(br, s.decTable, s.actualTableLog)
// Use temp table to avoid bound checks/append penalty.
var tmp = s.ct.tableSymbol[:256]
var off uint8
// Main part
if !s.zeroBits {
for br.off >= 8 {
br.fillFast()
tmp[off+0] = s1.nextFast()
tmp[off+1] = s2.nextFast()
br.fillFast()
tmp[off+2] = s1.nextFast()
tmp[off+3] = s2.nextFast()
off += 4
if off == 0 {
s.Out = append(s.Out, tmp...)
}
}
} else {
for br.off >= 8 {
br.fillFast()
tmp[off+0] = s1.next()
tmp[off+1] = s2.next()
br.fillFast()
tmp[off+2] = s1.next()
tmp[off+3] = s2.next()
off += 4
if off == 0 {
s.Out = append(s.Out, tmp...)
off = 0
if len(s.Out) >= s.DecompressLimit {
return fmt.Errorf("output size (%d) > DecompressLimit (%d)", len(s.Out), s.DecompressLimit)
}
}
}
}
s.Out = append(s.Out, tmp[:off]...)
// Final bits, a bit more expensive check
for {
if s1.finished() {
s.Out = append(s.Out, s1.final(), s2.final())
break
}
br.fill()
s.Out = append(s.Out, s1.next())
if s2.finished() {
s.Out = append(s.Out, s2.final(), s1.final())
break
}
s.Out = append(s.Out, s2.next())
if len(s.Out) >= s.DecompressLimit {
return fmt.Errorf("output size (%d) > DecompressLimit (%d)", len(s.Out), s.DecompressLimit)
}
}
return br.close()
} | [
"func",
"(",
"s",
"*",
"Scratch",
")",
"decompress",
"(",
")",
"error",
"{",
"br",
":=",
"&",
"s",
".",
"bits",
"\n",
"br",
".",
"init",
"(",
"s",
".",
"br",
".",
"unread",
"(",
")",
")",
"\n\n",
"var",
"s1",
",",
"s2",
"decoder",
"\n",
"// I... | // decompress will decompress the bitstream.
// If the buffer is over-read an error is returned. | [
"decompress",
"will",
"decompress",
"the",
"bitstream",
".",
"If",
"the",
"buffer",
"is",
"over",
"-",
"read",
"an",
"error",
"is",
"returned",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/decompress.go#L261-L326 |
8,330 | klauspost/compress | fse/decompress.go | init | func (d *decoder) init(in *bitReader, dt []decSymbol, tableLog uint8) {
d.dt = dt
d.br = in
d.state = uint16(in.getBits(tableLog))
} | go | func (d *decoder) init(in *bitReader, dt []decSymbol, tableLog uint8) {
d.dt = dt
d.br = in
d.state = uint16(in.getBits(tableLog))
} | [
"func",
"(",
"d",
"*",
"decoder",
")",
"init",
"(",
"in",
"*",
"bitReader",
",",
"dt",
"[",
"]",
"decSymbol",
",",
"tableLog",
"uint8",
")",
"{",
"d",
".",
"dt",
"=",
"dt",
"\n",
"d",
".",
"br",
"=",
"in",
"\n",
"d",
".",
"state",
"=",
"uint1... | // init will initialize the decoder and read the first state from the stream. | [
"init",
"will",
"initialize",
"the",
"decoder",
"and",
"read",
"the",
"first",
"state",
"from",
"the",
"stream",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/decompress.go#L336-L340 |
8,331 | klauspost/compress | fse/decompress.go | next | func (d *decoder) next() uint8 {
n := &d.dt[d.state]
lowBits := d.br.getBits(n.nbBits)
d.state = n.newState + lowBits
return n.symbol
} | go | func (d *decoder) next() uint8 {
n := &d.dt[d.state]
lowBits := d.br.getBits(n.nbBits)
d.state = n.newState + lowBits
return n.symbol
} | [
"func",
"(",
"d",
"*",
"decoder",
")",
"next",
"(",
")",
"uint8",
"{",
"n",
":=",
"&",
"d",
".",
"dt",
"[",
"d",
".",
"state",
"]",
"\n",
"lowBits",
":=",
"d",
".",
"br",
".",
"getBits",
"(",
"n",
".",
"nbBits",
")",
"\n",
"d",
".",
"state"... | // next returns the next symbol and sets the next state.
// At least tablelog bits must be available in the bit reader. | [
"next",
"returns",
"the",
"next",
"symbol",
"and",
"sets",
"the",
"next",
"state",
".",
"At",
"least",
"tablelog",
"bits",
"must",
"be",
"available",
"in",
"the",
"bit",
"reader",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/decompress.go#L344-L349 |
8,332 | klauspost/compress | zstd/framedec.go | next | func (d *frameDec) next(block *blockDec) error {
println("decoding new block")
err := block.reset(d.rawInput, d.WindowSize)
if err != nil {
println("block error:", err)
// Signal the frame decoder we have a problem.
d.sendErr(block, err)
return err
}
block.input <- struct{}{}
if debug {
println("next block:", block)
}
d.asyncRunningMu.Lock()
defer d.asyncRunningMu.Unlock()
if !d.asyncRunning {
return nil
}
if block.Last {
// We indicate the frame is done by sending io.EOF
d.decoding <- block
return io.EOF
}
d.decoding <- block
return nil
} | go | func (d *frameDec) next(block *blockDec) error {
println("decoding new block")
err := block.reset(d.rawInput, d.WindowSize)
if err != nil {
println("block error:", err)
// Signal the frame decoder we have a problem.
d.sendErr(block, err)
return err
}
block.input <- struct{}{}
if debug {
println("next block:", block)
}
d.asyncRunningMu.Lock()
defer d.asyncRunningMu.Unlock()
if !d.asyncRunning {
return nil
}
if block.Last {
// We indicate the frame is done by sending io.EOF
d.decoding <- block
return io.EOF
}
d.decoding <- block
return nil
} | [
"func",
"(",
"d",
"*",
"frameDec",
")",
"next",
"(",
"block",
"*",
"blockDec",
")",
"error",
"{",
"println",
"(",
"\"",
"\"",
")",
"\n",
"err",
":=",
"block",
".",
"reset",
"(",
"d",
".",
"rawInput",
",",
"d",
".",
"WindowSize",
")",
"\n",
"if",
... | // next will start decoding the next block from stream. | [
"next",
"will",
"start",
"decoding",
"the",
"next",
"block",
"from",
"stream",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/framedec.go#L233-L258 |
8,333 | klauspost/compress | zstd/framedec.go | sendErr | func (d *frameDec) sendErr(block *blockDec, err error) bool {
d.asyncRunningMu.Lock()
defer d.asyncRunningMu.Unlock()
if !d.asyncRunning {
return false
}
println("sending error", err.Error())
block.sendErr(err)
d.decoding <- block
return true
} | go | func (d *frameDec) sendErr(block *blockDec, err error) bool {
d.asyncRunningMu.Lock()
defer d.asyncRunningMu.Unlock()
if !d.asyncRunning {
return false
}
println("sending error", err.Error())
block.sendErr(err)
d.decoding <- block
return true
} | [
"func",
"(",
"d",
"*",
"frameDec",
")",
"sendErr",
"(",
"block",
"*",
"blockDec",
",",
"err",
"error",
")",
"bool",
"{",
"d",
".",
"asyncRunningMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"asyncRunningMu",
".",
"Unlock",
"(",
")",
"\n",
"i... | // sendEOF will queue an error block on the frame.
// This will cause the frame decoder to return when it encounters the block.
// Returns true if the decoder was added. | [
"sendEOF",
"will",
"queue",
"an",
"error",
"block",
"on",
"the",
"frame",
".",
"This",
"will",
"cause",
"the",
"frame",
"decoder",
"to",
"return",
"when",
"it",
"encounters",
"the",
"block",
".",
"Returns",
"true",
"if",
"the",
"decoder",
"was",
"added",
... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/framedec.go#L263-L274 |
8,334 | klauspost/compress | zstd/framedec.go | checkCRC | func (d *frameDec) checkCRC() error {
if !d.HasCheckSum {
return nil
}
var tmp [8]byte
gotB := d.crc.Sum(tmp[:0])
// Flip to match file order.
gotB[0] = gotB[7]
gotB[1] = gotB[6]
gotB[2] = gotB[5]
gotB[3] = gotB[4]
// We can overwrite upper tmp now
want := d.rawInput.readSmall(4)
if want == nil {
println("CRC missing?")
return io.ErrUnexpectedEOF
}
if !bytes.Equal(gotB[:4], want) {
println("CRC Check Failed:", gotB[:4], "!=", want)
return ErrCRCMismatch
}
println("CRC ok")
return nil
} | go | func (d *frameDec) checkCRC() error {
if !d.HasCheckSum {
return nil
}
var tmp [8]byte
gotB := d.crc.Sum(tmp[:0])
// Flip to match file order.
gotB[0] = gotB[7]
gotB[1] = gotB[6]
gotB[2] = gotB[5]
gotB[3] = gotB[4]
// We can overwrite upper tmp now
want := d.rawInput.readSmall(4)
if want == nil {
println("CRC missing?")
return io.ErrUnexpectedEOF
}
if !bytes.Equal(gotB[:4], want) {
println("CRC Check Failed:", gotB[:4], "!=", want)
return ErrCRCMismatch
}
println("CRC ok")
return nil
} | [
"func",
"(",
"d",
"*",
"frameDec",
")",
"checkCRC",
"(",
")",
"error",
"{",
"if",
"!",
"d",
".",
"HasCheckSum",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"tmp",
"[",
"8",
"]",
"byte",
"\n",
"gotB",
":=",
"d",
".",
"crc",
".",
"Sum",
"(",
... | // checkCRC will check the checksum if the frame has one.
// Will return ErrCRCMismatch if crc check failed, otherwise nil. | [
"checkCRC",
"will",
"check",
"the",
"checksum",
"if",
"the",
"frame",
"has",
"one",
".",
"Will",
"return",
"ErrCRCMismatch",
"if",
"crc",
"check",
"failed",
"otherwise",
"nil",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/framedec.go#L278-L303 |
8,335 | klauspost/compress | zstd/framedec.go | runDecoder | func (d *frameDec) runDecoder(dst []byte, dec *blockDec) ([]byte, error) {
// TODO: Init to dictionary
d.history.reset()
saved := d.history.b
// We use the history for output to avoid copying it.
d.history.b = dst
// Store input length, so we only check new data.
crcStart := len(dst)
var err error
for {
err = dec.reset(d.rawInput, d.WindowSize)
if err != nil {
break
}
if debug {
println("next block:", dec)
}
err = dec.decodeBuf(&d.history)
if err != nil || dec.Last {
break
}
if uint64(len(d.history.b)) > d.o.maxDecodedSize {
err = ErrDecoderSizeExceeded
break
}
}
dst = d.history.b
if err == nil {
if d.HasCheckSum {
var n int
n, err = d.crc.Write(dst[crcStart:])
if err == nil {
if n != len(dst)-crcStart {
err = io.ErrShortWrite
}
}
err = d.checkCRC()
}
}
d.history.b = saved
return dst, err
} | go | func (d *frameDec) runDecoder(dst []byte, dec *blockDec) ([]byte, error) {
// TODO: Init to dictionary
d.history.reset()
saved := d.history.b
// We use the history for output to avoid copying it.
d.history.b = dst
// Store input length, so we only check new data.
crcStart := len(dst)
var err error
for {
err = dec.reset(d.rawInput, d.WindowSize)
if err != nil {
break
}
if debug {
println("next block:", dec)
}
err = dec.decodeBuf(&d.history)
if err != nil || dec.Last {
break
}
if uint64(len(d.history.b)) > d.o.maxDecodedSize {
err = ErrDecoderSizeExceeded
break
}
}
dst = d.history.b
if err == nil {
if d.HasCheckSum {
var n int
n, err = d.crc.Write(dst[crcStart:])
if err == nil {
if n != len(dst)-crcStart {
err = io.ErrShortWrite
}
}
err = d.checkCRC()
}
}
d.history.b = saved
return dst, err
} | [
"func",
"(",
"d",
"*",
"frameDec",
")",
"runDecoder",
"(",
"dst",
"[",
"]",
"byte",
",",
"dec",
"*",
"blockDec",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// TODO: Init to dictionary",
"d",
".",
"history",
".",
"reset",
"(",
")",
"\n",
"... | // runDecoder will create a sync decoder that will decodeAsync a block of data. | [
"runDecoder",
"will",
"create",
"a",
"sync",
"decoder",
"that",
"will",
"decodeAsync",
"a",
"block",
"of",
"data",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/framedec.go#L418-L460 |
8,336 | klauspost/compress | flate/huffman_bit_writer.go | dynamicSize | func (w *huffmanBitWriter) dynamicSize(litEnc, offEnc *huffmanEncoder, extraBits int) (size, numCodegens int) {
numCodegens = len(w.codegenFreq)
for numCodegens > 4 && w.codegenFreq[codegenOrder[numCodegens-1]] == 0 {
numCodegens--
}
header := 3 + 5 + 5 + 4 + (3 * numCodegens) +
w.codegenEncoding.bitLength(w.codegenFreq[:]) +
int(w.codegenFreq[16])*2 +
int(w.codegenFreq[17])*3 +
int(w.codegenFreq[18])*7
size = header +
litEnc.bitLength(w.literalFreq) +
offEnc.bitLength(w.offsetFreq) +
extraBits
return size, numCodegens
} | go | func (w *huffmanBitWriter) dynamicSize(litEnc, offEnc *huffmanEncoder, extraBits int) (size, numCodegens int) {
numCodegens = len(w.codegenFreq)
for numCodegens > 4 && w.codegenFreq[codegenOrder[numCodegens-1]] == 0 {
numCodegens--
}
header := 3 + 5 + 5 + 4 + (3 * numCodegens) +
w.codegenEncoding.bitLength(w.codegenFreq[:]) +
int(w.codegenFreq[16])*2 +
int(w.codegenFreq[17])*3 +
int(w.codegenFreq[18])*7
size = header +
litEnc.bitLength(w.literalFreq) +
offEnc.bitLength(w.offsetFreq) +
extraBits
return size, numCodegens
} | [
"func",
"(",
"w",
"*",
"huffmanBitWriter",
")",
"dynamicSize",
"(",
"litEnc",
",",
"offEnc",
"*",
"huffmanEncoder",
",",
"extraBits",
"int",
")",
"(",
"size",
",",
"numCodegens",
"int",
")",
"{",
"numCodegens",
"=",
"len",
"(",
"w",
".",
"codegenFreq",
"... | // dynamicSize returns the size of dynamically encoded data in bits. | [
"dynamicSize",
"returns",
"the",
"size",
"of",
"dynamically",
"encoded",
"data",
"in",
"bits",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/huffman_bit_writer.go#L296-L312 |
8,337 | klauspost/compress | flate/huffman_bit_writer.go | fixedSize | func (w *huffmanBitWriter) fixedSize(extraBits int) int {
return 3 +
fixedLiteralEncoding.bitLength(w.literalFreq) +
fixedOffsetEncoding.bitLength(w.offsetFreq) +
extraBits
} | go | func (w *huffmanBitWriter) fixedSize(extraBits int) int {
return 3 +
fixedLiteralEncoding.bitLength(w.literalFreq) +
fixedOffsetEncoding.bitLength(w.offsetFreq) +
extraBits
} | [
"func",
"(",
"w",
"*",
"huffmanBitWriter",
")",
"fixedSize",
"(",
"extraBits",
"int",
")",
"int",
"{",
"return",
"3",
"+",
"fixedLiteralEncoding",
".",
"bitLength",
"(",
"w",
".",
"literalFreq",
")",
"+",
"fixedOffsetEncoding",
".",
"bitLength",
"(",
"w",
... | // fixedSize returns the size of dynamically encoded data in bits. | [
"fixedSize",
"returns",
"the",
"size",
"of",
"dynamically",
"encoded",
"data",
"in",
"bits",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/huffman_bit_writer.go#L315-L320 |
8,338 | klauspost/compress | flate/huffman_bit_writer.go | storedSize | func (w *huffmanBitWriter) storedSize(in []byte) (int, bool) {
if in == nil {
return 0, false
}
if len(in) <= maxStoreBlockSize {
return (len(in) + 5) * 8, true
}
return 0, false
} | go | func (w *huffmanBitWriter) storedSize(in []byte) (int, bool) {
if in == nil {
return 0, false
}
if len(in) <= maxStoreBlockSize {
return (len(in) + 5) * 8, true
}
return 0, false
} | [
"func",
"(",
"w",
"*",
"huffmanBitWriter",
")",
"storedSize",
"(",
"in",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"bool",
")",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"if",
"len",
"(",
"in",
")",
"<=",
... | // storedSize calculates the stored size, including header.
// The function returns the size in bits and whether the block
// fits inside a single block. | [
"storedSize",
"calculates",
"the",
"stored",
"size",
"including",
"header",
".",
"The",
"function",
"returns",
"the",
"size",
"in",
"bits",
"and",
"whether",
"the",
"block",
"fits",
"inside",
"a",
"single",
"block",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/huffman_bit_writer.go#L325-L333 |
8,339 | klauspost/compress | flate/huffman_bit_writer.go | writeDynamicHeader | func (w *huffmanBitWriter) writeDynamicHeader(numLiterals int, numOffsets int, numCodegens int, isEof bool) {
if w.err != nil {
return
}
var firstBits int32 = 4
if isEof {
firstBits = 5
}
w.writeBits(firstBits, 3)
w.writeBits(int32(numLiterals-257), 5)
w.writeBits(int32(numOffsets-1), 5)
w.writeBits(int32(numCodegens-4), 4)
for i := 0; i < numCodegens; i++ {
value := uint(w.codegenEncoding.codes[codegenOrder[i]].len)
w.writeBits(int32(value), 3)
}
i := 0
for {
var codeWord int = int(w.codegen[i])
i++
if codeWord == badCode {
break
}
w.writeCode(w.codegenEncoding.codes[uint32(codeWord)])
switch codeWord {
case 16:
w.writeBits(int32(w.codegen[i]), 2)
i++
break
case 17:
w.writeBits(int32(w.codegen[i]), 3)
i++
break
case 18:
w.writeBits(int32(w.codegen[i]), 7)
i++
break
}
}
} | go | func (w *huffmanBitWriter) writeDynamicHeader(numLiterals int, numOffsets int, numCodegens int, isEof bool) {
if w.err != nil {
return
}
var firstBits int32 = 4
if isEof {
firstBits = 5
}
w.writeBits(firstBits, 3)
w.writeBits(int32(numLiterals-257), 5)
w.writeBits(int32(numOffsets-1), 5)
w.writeBits(int32(numCodegens-4), 4)
for i := 0; i < numCodegens; i++ {
value := uint(w.codegenEncoding.codes[codegenOrder[i]].len)
w.writeBits(int32(value), 3)
}
i := 0
for {
var codeWord int = int(w.codegen[i])
i++
if codeWord == badCode {
break
}
w.writeCode(w.codegenEncoding.codes[uint32(codeWord)])
switch codeWord {
case 16:
w.writeBits(int32(w.codegen[i]), 2)
i++
break
case 17:
w.writeBits(int32(w.codegen[i]), 3)
i++
break
case 18:
w.writeBits(int32(w.codegen[i]), 7)
i++
break
}
}
} | [
"func",
"(",
"w",
"*",
"huffmanBitWriter",
")",
"writeDynamicHeader",
"(",
"numLiterals",
"int",
",",
"numOffsets",
"int",
",",
"numCodegens",
"int",
",",
"isEof",
"bool",
")",
"{",
"if",
"w",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"v... | // Write the header of a dynamic Huffman block to the output stream.
//
// numLiterals The number of literals specified in codegen
// numOffsets The number of offsets specified in codegen
// numCodegens The number of codegens used in codegen | [
"Write",
"the",
"header",
"of",
"a",
"dynamic",
"Huffman",
"block",
"to",
"the",
"output",
"stream",
".",
"numLiterals",
"The",
"number",
"of",
"literals",
"specified",
"in",
"codegen",
"numOffsets",
"The",
"number",
"of",
"offsets",
"specified",
"in",
"codege... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/huffman_bit_writer.go#L367-L409 |
8,340 | klauspost/compress | flate/huffman_bit_writer.go | writeBlock | func (w *huffmanBitWriter) writeBlock(tokens []token, eof bool, input []byte) {
if w.err != nil {
return
}
tokens = append(tokens, endBlockMarker)
numLiterals, numOffsets := w.indexTokens(tokens)
var extraBits int
storedSize, storable := w.storedSize(input)
if storable {
// We only bother calculating the costs of the extra bits required by
// the length of offset fields (which will be the same for both fixed
// and dynamic encoding), if we need to compare those two encodings
// against stored encoding.
for lengthCode := lengthCodesStart + 8; lengthCode < numLiterals; lengthCode++ {
// First eight length codes have extra size = 0.
extraBits += int(w.literalFreq[lengthCode]) * int(lengthExtraBits[lengthCode-lengthCodesStart])
}
for offsetCode := 4; offsetCode < numOffsets; offsetCode++ {
// First four offset codes have extra size = 0.
extraBits += int(w.offsetFreq[offsetCode]) * int(offsetExtraBits[offsetCode])
}
}
// Figure out smallest code.
// Fixed Huffman baseline.
var literalEncoding = fixedLiteralEncoding
var offsetEncoding = fixedOffsetEncoding
var size = w.fixedSize(extraBits)
// Dynamic Huffman?
var numCodegens int
// Generate codegen and codegenFrequencies, which indicates how to encode
// the literalEncoding and the offsetEncoding.
w.generateCodegen(numLiterals, numOffsets, w.literalEncoding, w.offsetEncoding)
w.codegenEncoding.generate(w.codegenFreq[:], 7)
dynamicSize, numCodegens := w.dynamicSize(w.literalEncoding, w.offsetEncoding, extraBits)
if dynamicSize < size {
size = dynamicSize
literalEncoding = w.literalEncoding
offsetEncoding = w.offsetEncoding
}
// Stored bytes?
if storable && storedSize < size {
w.writeStoredHeader(len(input), eof)
w.writeBytes(input)
return
}
// Huffman.
if literalEncoding == fixedLiteralEncoding {
w.writeFixedHeader(eof)
} else {
w.writeDynamicHeader(numLiterals, numOffsets, numCodegens, eof)
}
// Write the tokens.
w.writeTokens(tokens, literalEncoding.codes, offsetEncoding.codes)
} | go | func (w *huffmanBitWriter) writeBlock(tokens []token, eof bool, input []byte) {
if w.err != nil {
return
}
tokens = append(tokens, endBlockMarker)
numLiterals, numOffsets := w.indexTokens(tokens)
var extraBits int
storedSize, storable := w.storedSize(input)
if storable {
// We only bother calculating the costs of the extra bits required by
// the length of offset fields (which will be the same for both fixed
// and dynamic encoding), if we need to compare those two encodings
// against stored encoding.
for lengthCode := lengthCodesStart + 8; lengthCode < numLiterals; lengthCode++ {
// First eight length codes have extra size = 0.
extraBits += int(w.literalFreq[lengthCode]) * int(lengthExtraBits[lengthCode-lengthCodesStart])
}
for offsetCode := 4; offsetCode < numOffsets; offsetCode++ {
// First four offset codes have extra size = 0.
extraBits += int(w.offsetFreq[offsetCode]) * int(offsetExtraBits[offsetCode])
}
}
// Figure out smallest code.
// Fixed Huffman baseline.
var literalEncoding = fixedLiteralEncoding
var offsetEncoding = fixedOffsetEncoding
var size = w.fixedSize(extraBits)
// Dynamic Huffman?
var numCodegens int
// Generate codegen and codegenFrequencies, which indicates how to encode
// the literalEncoding and the offsetEncoding.
w.generateCodegen(numLiterals, numOffsets, w.literalEncoding, w.offsetEncoding)
w.codegenEncoding.generate(w.codegenFreq[:], 7)
dynamicSize, numCodegens := w.dynamicSize(w.literalEncoding, w.offsetEncoding, extraBits)
if dynamicSize < size {
size = dynamicSize
literalEncoding = w.literalEncoding
offsetEncoding = w.offsetEncoding
}
// Stored bytes?
if storable && storedSize < size {
w.writeStoredHeader(len(input), eof)
w.writeBytes(input)
return
}
// Huffman.
if literalEncoding == fixedLiteralEncoding {
w.writeFixedHeader(eof)
} else {
w.writeDynamicHeader(numLiterals, numOffsets, numCodegens, eof)
}
// Write the tokens.
w.writeTokens(tokens, literalEncoding.codes, offsetEncoding.codes)
} | [
"func",
"(",
"w",
"*",
"huffmanBitWriter",
")",
"writeBlock",
"(",
"tokens",
"[",
"]",
"token",
",",
"eof",
"bool",
",",
"input",
"[",
"]",
"byte",
")",
"{",
"if",
"w",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"tokens",
"=",
"ap... | // writeBlock will write a block of tokens with the smallest encoding.
// The original input can be supplied, and if the huffman encoded data
// is larger than the original bytes, the data will be written as a
// stored block.
// If the input is nil, the tokens will always be Huffman encoded. | [
"writeBlock",
"will",
"write",
"a",
"block",
"of",
"tokens",
"with",
"the",
"smallest",
"encoding",
".",
"The",
"original",
"input",
"can",
"be",
"supplied",
"and",
"if",
"the",
"huffman",
"encoded",
"data",
"is",
"larger",
"than",
"the",
"original",
"bytes"... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/huffman_bit_writer.go#L442-L504 |
8,341 | klauspost/compress | flate/huffman_bit_writer.go | indexTokens | func (w *huffmanBitWriter) indexTokens(tokens []token) (numLiterals, numOffsets int) {
for i := range w.literalFreq {
w.literalFreq[i] = 0
}
for i := range w.offsetFreq {
w.offsetFreq[i] = 0
}
for _, t := range tokens {
if t < matchType {
w.literalFreq[t.literal()]++
continue
}
length := t.length()
offset := t.offset()
w.literalFreq[lengthCodesStart+lengthCode(length)]++
w.offsetFreq[offsetCode(offset)]++
}
// get the number of literals
numLiterals = len(w.literalFreq)
for w.literalFreq[numLiterals-1] == 0 {
numLiterals--
}
// get the number of offsets
numOffsets = len(w.offsetFreq)
for numOffsets > 0 && w.offsetFreq[numOffsets-1] == 0 {
numOffsets--
}
if numOffsets == 0 {
// We haven't found a single match. If we want to go with the dynamic encoding,
// we should count at least one offset to be sure that the offset huffman tree could be encoded.
w.offsetFreq[0] = 1
numOffsets = 1
}
w.literalEncoding.generate(w.literalFreq, 15)
w.offsetEncoding.generate(w.offsetFreq, 15)
return
} | go | func (w *huffmanBitWriter) indexTokens(tokens []token) (numLiterals, numOffsets int) {
for i := range w.literalFreq {
w.literalFreq[i] = 0
}
for i := range w.offsetFreq {
w.offsetFreq[i] = 0
}
for _, t := range tokens {
if t < matchType {
w.literalFreq[t.literal()]++
continue
}
length := t.length()
offset := t.offset()
w.literalFreq[lengthCodesStart+lengthCode(length)]++
w.offsetFreq[offsetCode(offset)]++
}
// get the number of literals
numLiterals = len(w.literalFreq)
for w.literalFreq[numLiterals-1] == 0 {
numLiterals--
}
// get the number of offsets
numOffsets = len(w.offsetFreq)
for numOffsets > 0 && w.offsetFreq[numOffsets-1] == 0 {
numOffsets--
}
if numOffsets == 0 {
// We haven't found a single match. If we want to go with the dynamic encoding,
// we should count at least one offset to be sure that the offset huffman tree could be encoded.
w.offsetFreq[0] = 1
numOffsets = 1
}
w.literalEncoding.generate(w.literalFreq, 15)
w.offsetEncoding.generate(w.offsetFreq, 15)
return
} | [
"func",
"(",
"w",
"*",
"huffmanBitWriter",
")",
"indexTokens",
"(",
"tokens",
"[",
"]",
"token",
")",
"(",
"numLiterals",
",",
"numOffsets",
"int",
")",
"{",
"for",
"i",
":=",
"range",
"w",
".",
"literalFreq",
"{",
"w",
".",
"literalFreq",
"[",
"i",
... | // indexTokens indexes a slice of tokens, and updates
// literalFreq and offsetFreq, and generates literalEncoding
// and offsetEncoding.
// The number of literal and offset tokens is returned. | [
"indexTokens",
"indexes",
"a",
"slice",
"of",
"tokens",
"and",
"updates",
"literalFreq",
"and",
"offsetFreq",
"and",
"generates",
"literalEncoding",
"and",
"offsetEncoding",
".",
"The",
"number",
"of",
"literal",
"and",
"offset",
"tokens",
"is",
"returned",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/huffman_bit_writer.go#L543-L581 |
8,342 | klauspost/compress | flate/huffman_bit_writer.go | writeTokens | func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode) {
if w.err != nil {
return
}
for _, t := range tokens {
if t < matchType {
w.writeCode(leCodes[t.literal()])
continue
}
// Write the length
length := t.length()
lengthCode := lengthCode(length)
w.writeCode(leCodes[lengthCode+lengthCodesStart])
extraLengthBits := uint(lengthExtraBits[lengthCode])
if extraLengthBits > 0 {
extraLength := int32(length - lengthBase[lengthCode])
w.writeBits(extraLength, extraLengthBits)
}
// Write the offset
offset := t.offset()
offsetCode := offsetCode(offset)
w.writeCode(oeCodes[offsetCode])
extraOffsetBits := uint(offsetExtraBits[offsetCode])
if extraOffsetBits > 0 {
extraOffset := int32(offset - offsetBase[offsetCode])
w.writeBits(extraOffset, extraOffsetBits)
}
}
} | go | func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode) {
if w.err != nil {
return
}
for _, t := range tokens {
if t < matchType {
w.writeCode(leCodes[t.literal()])
continue
}
// Write the length
length := t.length()
lengthCode := lengthCode(length)
w.writeCode(leCodes[lengthCode+lengthCodesStart])
extraLengthBits := uint(lengthExtraBits[lengthCode])
if extraLengthBits > 0 {
extraLength := int32(length - lengthBase[lengthCode])
w.writeBits(extraLength, extraLengthBits)
}
// Write the offset
offset := t.offset()
offsetCode := offsetCode(offset)
w.writeCode(oeCodes[offsetCode])
extraOffsetBits := uint(offsetExtraBits[offsetCode])
if extraOffsetBits > 0 {
extraOffset := int32(offset - offsetBase[offsetCode])
w.writeBits(extraOffset, extraOffsetBits)
}
}
} | [
"func",
"(",
"w",
"*",
"huffmanBitWriter",
")",
"writeTokens",
"(",
"tokens",
"[",
"]",
"token",
",",
"leCodes",
",",
"oeCodes",
"[",
"]",
"hcode",
")",
"{",
"if",
"w",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"for",
"_",
",",
"t"... | // writeTokens writes a slice of tokens to the output.
// codes for literal and offset encoding must be supplied. | [
"writeTokens",
"writes",
"a",
"slice",
"of",
"tokens",
"to",
"the",
"output",
".",
"codes",
"for",
"literal",
"and",
"offset",
"encoding",
"must",
"be",
"supplied",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/huffman_bit_writer.go#L585-L613 |
8,343 | klauspost/compress | flate/huffman_bit_writer.go | writeBlockHuff | func (w *huffmanBitWriter) writeBlockHuff(eof bool, input []byte) {
if w.err != nil {
return
}
// Clear histogram
for i := range w.literalFreq {
w.literalFreq[i] = 0
}
// Add everything as literals
histogram(input, w.literalFreq)
w.literalFreq[endBlockMarker] = 1
const numLiterals = endBlockMarker + 1
const numOffsets = 1
w.literalEncoding.generate(w.literalFreq, 15)
// Figure out smallest code.
// Always use dynamic Huffman or Store
var numCodegens int
// Generate codegen and codegenFrequencies, which indicates how to encode
// the literalEncoding and the offsetEncoding.
w.generateCodegen(numLiterals, numOffsets, w.literalEncoding, huffOffset)
w.codegenEncoding.generate(w.codegenFreq[:], 7)
size, numCodegens := w.dynamicSize(w.literalEncoding, huffOffset, 0)
// Store bytes, if we don't get a reasonable improvement.
if ssize, storable := w.storedSize(input); storable && ssize < (size+size>>4) {
w.writeStoredHeader(len(input), eof)
w.writeBytes(input)
return
}
// Huffman.
w.writeDynamicHeader(numLiterals, numOffsets, numCodegens, eof)
encoding := w.literalEncoding.codes[:257]
n := w.nbytes
for _, t := range input {
// Bitwriting inlined, ~30% speedup
c := encoding[t]
w.bits |= uint64(c.code) << w.nbits
w.nbits += uint(c.len)
if w.nbits < 48 {
continue
}
// Store 6 bytes
bits := w.bits
w.bits >>= 48
w.nbits -= 48
bytes := w.bytes[n : n+6]
bytes[0] = byte(bits)
bytes[1] = byte(bits >> 8)
bytes[2] = byte(bits >> 16)
bytes[3] = byte(bits >> 24)
bytes[4] = byte(bits >> 32)
bytes[5] = byte(bits >> 40)
n += 6
if n < bufferFlushSize {
continue
}
w.write(w.bytes[:n])
if w.err != nil {
return // Return early in the event of write failures
}
n = 0
}
w.nbytes = n
w.writeCode(encoding[endBlockMarker])
} | go | func (w *huffmanBitWriter) writeBlockHuff(eof bool, input []byte) {
if w.err != nil {
return
}
// Clear histogram
for i := range w.literalFreq {
w.literalFreq[i] = 0
}
// Add everything as literals
histogram(input, w.literalFreq)
w.literalFreq[endBlockMarker] = 1
const numLiterals = endBlockMarker + 1
const numOffsets = 1
w.literalEncoding.generate(w.literalFreq, 15)
// Figure out smallest code.
// Always use dynamic Huffman or Store
var numCodegens int
// Generate codegen and codegenFrequencies, which indicates how to encode
// the literalEncoding and the offsetEncoding.
w.generateCodegen(numLiterals, numOffsets, w.literalEncoding, huffOffset)
w.codegenEncoding.generate(w.codegenFreq[:], 7)
size, numCodegens := w.dynamicSize(w.literalEncoding, huffOffset, 0)
// Store bytes, if we don't get a reasonable improvement.
if ssize, storable := w.storedSize(input); storable && ssize < (size+size>>4) {
w.writeStoredHeader(len(input), eof)
w.writeBytes(input)
return
}
// Huffman.
w.writeDynamicHeader(numLiterals, numOffsets, numCodegens, eof)
encoding := w.literalEncoding.codes[:257]
n := w.nbytes
for _, t := range input {
// Bitwriting inlined, ~30% speedup
c := encoding[t]
w.bits |= uint64(c.code) << w.nbits
w.nbits += uint(c.len)
if w.nbits < 48 {
continue
}
// Store 6 bytes
bits := w.bits
w.bits >>= 48
w.nbits -= 48
bytes := w.bytes[n : n+6]
bytes[0] = byte(bits)
bytes[1] = byte(bits >> 8)
bytes[2] = byte(bits >> 16)
bytes[3] = byte(bits >> 24)
bytes[4] = byte(bits >> 32)
bytes[5] = byte(bits >> 40)
n += 6
if n < bufferFlushSize {
continue
}
w.write(w.bytes[:n])
if w.err != nil {
return // Return early in the event of write failures
}
n = 0
}
w.nbytes = n
w.writeCode(encoding[endBlockMarker])
} | [
"func",
"(",
"w",
"*",
"huffmanBitWriter",
")",
"writeBlockHuff",
"(",
"eof",
"bool",
",",
"input",
"[",
"]",
"byte",
")",
"{",
"if",
"w",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// Clear histogram",
"for",
"i",
":=",
"range",
"w"... | // writeBlockHuff encodes a block of bytes as either
// Huffman encoded literals or uncompressed bytes if the
// results only gains very little from compression. | [
"writeBlockHuff",
"encodes",
"a",
"block",
"of",
"bytes",
"as",
"either",
"Huffman",
"encoded",
"literals",
"or",
"uncompressed",
"bytes",
"if",
"the",
"results",
"only",
"gains",
"very",
"little",
"from",
"compression",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/huffman_bit_writer.go#L629-L701 |
8,344 | klauspost/compress | zip/reader.go | OpenReader | func OpenReader(name string) (*ReadCloser, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
}
fi, err := f.Stat()
if err != nil {
f.Close()
return nil, err
}
r := new(ReadCloser)
if err := r.init(f, fi.Size()); err != nil {
f.Close()
return nil, err
}
r.f = f
return r, nil
} | go | func OpenReader(name string) (*ReadCloser, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
}
fi, err := f.Stat()
if err != nil {
f.Close()
return nil, err
}
r := new(ReadCloser)
if err := r.init(f, fi.Size()); err != nil {
f.Close()
return nil, err
}
r.f = f
return r, nil
} | [
"func",
"OpenReader",
"(",
"name",
"string",
")",
"(",
"*",
"ReadCloser",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"fi... | // OpenReader will open the Zip file specified by name and return a ReadCloser. | [
"OpenReader",
"will",
"open",
"the",
"Zip",
"file",
"specified",
"by",
"name",
"and",
"return",
"a",
"ReadCloser",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/reader.go#L49-L66 |
8,345 | klauspost/compress | zip/reader.go | NewReader | func NewReader(r io.ReaderAt, size int64) (*Reader, error) {
zr := new(Reader)
if err := zr.init(r, size); err != nil {
return nil, err
}
return zr, nil
} | go | func NewReader(r io.ReaderAt, size int64) (*Reader, error) {
zr := new(Reader)
if err := zr.init(r, size); err != nil {
return nil, err
}
return zr, nil
} | [
"func",
"NewReader",
"(",
"r",
"io",
".",
"ReaderAt",
",",
"size",
"int64",
")",
"(",
"*",
"Reader",
",",
"error",
")",
"{",
"zr",
":=",
"new",
"(",
"Reader",
")",
"\n",
"if",
"err",
":=",
"zr",
".",
"init",
"(",
"r",
",",
"size",
")",
";",
"... | // NewReader returns a new Reader reading from r, which is assumed to
// have the given size in bytes. | [
"NewReader",
"returns",
"a",
"new",
"Reader",
"reading",
"from",
"r",
"which",
"is",
"assumed",
"to",
"have",
"the",
"given",
"size",
"in",
"bytes",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/reader.go#L70-L76 |
8,346 | klauspost/compress | zip/reader.go | RegisterDecompressor | func (z *Reader) RegisterDecompressor(method uint16, dcomp Decompressor) {
if z.decompressors == nil {
z.decompressors = make(map[uint16]Decompressor)
}
z.decompressors[method] = dcomp
} | go | func (z *Reader) RegisterDecompressor(method uint16, dcomp Decompressor) {
if z.decompressors == nil {
z.decompressors = make(map[uint16]Decompressor)
}
z.decompressors[method] = dcomp
} | [
"func",
"(",
"z",
"*",
"Reader",
")",
"RegisterDecompressor",
"(",
"method",
"uint16",
",",
"dcomp",
"Decompressor",
")",
"{",
"if",
"z",
".",
"decompressors",
"==",
"nil",
"{",
"z",
".",
"decompressors",
"=",
"make",
"(",
"map",
"[",
"uint16",
"]",
"D... | // RegisterDecompressor registers or overrides a custom decompressor for a
// specific method ID. If a decompressor for a given method is not found,
// Reader will default to looking up the decompressor at the package level.
//
// Must not be called concurrently with Open on any Files in the Reader. | [
"RegisterDecompressor",
"registers",
"or",
"overrides",
"a",
"custom",
"decompressor",
"for",
"a",
"specific",
"method",
"ID",
".",
"If",
"a",
"decompressor",
"for",
"a",
"given",
"method",
"is",
"not",
"found",
"Reader",
"will",
"default",
"to",
"looking",
"u... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/reader.go#L123-L128 |
8,347 | klauspost/compress | zip/reader.go | DataOffset | func (f *File) DataOffset() (offset int64, err error) {
bodyOffset, err := f.findBodyOffset()
if err != nil {
return
}
return f.headerOffset + bodyOffset, nil
} | go | func (f *File) DataOffset() (offset int64, err error) {
bodyOffset, err := f.findBodyOffset()
if err != nil {
return
}
return f.headerOffset + bodyOffset, nil
} | [
"func",
"(",
"f",
"*",
"File",
")",
"DataOffset",
"(",
")",
"(",
"offset",
"int64",
",",
"err",
"error",
")",
"{",
"bodyOffset",
",",
"err",
":=",
"f",
".",
"findBodyOffset",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n... | // DataOffset returns the offset of the file's possibly-compressed
// data, relative to the beginning of the zip file.
//
// Most callers should instead use Open, which transparently
// decompresses data and verifies checksums. | [
"DataOffset",
"returns",
"the",
"offset",
"of",
"the",
"file",
"s",
"possibly",
"-",
"compressed",
"data",
"relative",
"to",
"the",
"beginning",
"of",
"the",
"zip",
"file",
".",
"Most",
"callers",
"should",
"instead",
"use",
"Open",
"which",
"transparently",
... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/reader.go#L148-L154 |
8,348 | klauspost/compress | zip/reader.go | Open | func (f *File) Open() (rc io.ReadCloser, err error) {
bodyOffset, err := f.findBodyOffset()
if err != nil {
return
}
size := int64(f.CompressedSize64)
r := io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset, size)
dcomp := f.zip.decompressor(f.Method)
if dcomp == nil {
err = ErrAlgorithm
return
}
rc = dcomp(r)
var desr io.Reader
if f.hasDataDescriptor() {
desr = io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset+size, dataDescriptorLen)
}
rc = &checksumReader{
rc: rc,
hash: crc32.NewIEEE(),
f: f,
desr: desr,
}
return
} | go | func (f *File) Open() (rc io.ReadCloser, err error) {
bodyOffset, err := f.findBodyOffset()
if err != nil {
return
}
size := int64(f.CompressedSize64)
r := io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset, size)
dcomp := f.zip.decompressor(f.Method)
if dcomp == nil {
err = ErrAlgorithm
return
}
rc = dcomp(r)
var desr io.Reader
if f.hasDataDescriptor() {
desr = io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset+size, dataDescriptorLen)
}
rc = &checksumReader{
rc: rc,
hash: crc32.NewIEEE(),
f: f,
desr: desr,
}
return
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Open",
"(",
")",
"(",
"rc",
"io",
".",
"ReadCloser",
",",
"err",
"error",
")",
"{",
"bodyOffset",
",",
"err",
":=",
"f",
".",
"findBodyOffset",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
... | // Open returns a ReadCloser that provides access to the File's contents.
// Multiple files may be read concurrently. | [
"Open",
"returns",
"a",
"ReadCloser",
"that",
"provides",
"access",
"to",
"the",
"File",
"s",
"contents",
".",
"Multiple",
"files",
"may",
"be",
"read",
"concurrently",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/reader.go#L158-L182 |
8,349 | klauspost/compress | zip/reader.go | findBodyOffset | func (f *File) findBodyOffset() (int64, error) {
var buf [fileHeaderLen]byte
if _, err := f.zipr.ReadAt(buf[:], f.headerOffset); err != nil {
return 0, err
}
b := readBuf(buf[:])
if sig := b.uint32(); sig != fileHeaderSignature {
return 0, ErrFormat
}
b = b[22:] // skip over most of the header
filenameLen := int(b.uint16())
extraLen := int(b.uint16())
return int64(fileHeaderLen + filenameLen + extraLen), nil
} | go | func (f *File) findBodyOffset() (int64, error) {
var buf [fileHeaderLen]byte
if _, err := f.zipr.ReadAt(buf[:], f.headerOffset); err != nil {
return 0, err
}
b := readBuf(buf[:])
if sig := b.uint32(); sig != fileHeaderSignature {
return 0, ErrFormat
}
b = b[22:] // skip over most of the header
filenameLen := int(b.uint16())
extraLen := int(b.uint16())
return int64(fileHeaderLen + filenameLen + extraLen), nil
} | [
"func",
"(",
"f",
"*",
"File",
")",
"findBodyOffset",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"var",
"buf",
"[",
"fileHeaderLen",
"]",
"byte",
"\n",
"if",
"_",
",",
"err",
":=",
"f",
".",
"zipr",
".",
"ReadAt",
"(",
"buf",
"[",
":",
"]"... | // findBodyOffset does the minimum work to verify the file has a header
// and returns the file body offset. | [
"findBodyOffset",
"does",
"the",
"minimum",
"work",
"to",
"verify",
"the",
"file",
"has",
"a",
"header",
"and",
"returns",
"the",
"file",
"body",
"offset",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/reader.go#L234-L247 |
8,350 | klauspost/compress | zip/reader.go | readDirectory64End | func readDirectory64End(r io.ReaderAt, offset int64, d *directoryEnd) (err error) {
buf := make([]byte, directory64EndLen)
if _, err := r.ReadAt(buf, offset); err != nil {
return err
}
b := readBuf(buf)
if sig := b.uint32(); sig != directory64EndSignature {
return ErrFormat
}
b = b[12:] // skip dir size, version and version needed (uint64 + 2x uint16)
d.diskNbr = b.uint32() // number of this disk
d.dirDiskNbr = b.uint32() // number of the disk with the start of the central directory
d.dirRecordsThisDisk = b.uint64() // total number of entries in the central directory on this disk
d.directoryRecords = b.uint64() // total number of entries in the central directory
d.directorySize = b.uint64() // size of the central directory
d.directoryOffset = b.uint64() // offset of start of central directory with respect to the starting disk number
return nil
} | go | func readDirectory64End(r io.ReaderAt, offset int64, d *directoryEnd) (err error) {
buf := make([]byte, directory64EndLen)
if _, err := r.ReadAt(buf, offset); err != nil {
return err
}
b := readBuf(buf)
if sig := b.uint32(); sig != directory64EndSignature {
return ErrFormat
}
b = b[12:] // skip dir size, version and version needed (uint64 + 2x uint16)
d.diskNbr = b.uint32() // number of this disk
d.dirDiskNbr = b.uint32() // number of the disk with the start of the central directory
d.dirRecordsThisDisk = b.uint64() // total number of entries in the central directory on this disk
d.directoryRecords = b.uint64() // total number of entries in the central directory
d.directorySize = b.uint64() // size of the central directory
d.directoryOffset = b.uint64() // offset of start of central directory with respect to the starting disk number
return nil
} | [
"func",
"readDirectory64End",
"(",
"r",
"io",
".",
"ReaderAt",
",",
"offset",
"int64",
",",
"d",
"*",
"directoryEnd",
")",
"(",
"err",
"error",
")",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"directory64EndLen",
")",
"\n",
"if",
"_",
",",... | // readDirectory64End reads the zip64 directory end and updates the
// directory end with the zip64 directory end values. | [
"readDirectory64End",
"reads",
"the",
"zip64",
"directory",
"end",
"and",
"updates",
"the",
"directory",
"end",
"with",
"the",
"zip64",
"directory",
"end",
"values",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/reader.go#L466-L486 |
8,351 | klauspost/compress | zip/struct.go | FileInfoHeader | func FileInfoHeader(fi os.FileInfo) (*FileHeader, error) {
size := fi.Size()
fh := &FileHeader{
Name: fi.Name(),
UncompressedSize64: uint64(size),
}
fh.SetModTime(fi.ModTime())
fh.SetMode(fi.Mode())
if fh.UncompressedSize64 > uint32max {
fh.UncompressedSize = uint32max
} else {
fh.UncompressedSize = uint32(fh.UncompressedSize64)
}
return fh, nil
} | go | func FileInfoHeader(fi os.FileInfo) (*FileHeader, error) {
size := fi.Size()
fh := &FileHeader{
Name: fi.Name(),
UncompressedSize64: uint64(size),
}
fh.SetModTime(fi.ModTime())
fh.SetMode(fi.Mode())
if fh.UncompressedSize64 > uint32max {
fh.UncompressedSize = uint32max
} else {
fh.UncompressedSize = uint32(fh.UncompressedSize64)
}
return fh, nil
} | [
"func",
"FileInfoHeader",
"(",
"fi",
"os",
".",
"FileInfo",
")",
"(",
"*",
"FileHeader",
",",
"error",
")",
"{",
"size",
":=",
"fi",
".",
"Size",
"(",
")",
"\n",
"fh",
":=",
"&",
"FileHeader",
"{",
"Name",
":",
"fi",
".",
"Name",
"(",
")",
",",
... | // FileInfoHeader creates a partially-populated FileHeader from an
// os.FileInfo.
// Because os.FileInfo's Name method returns only the base name of
// the file it describes, it may be necessary to modify the Name field
// of the returned header to provide the full path name of the file. | [
"FileInfoHeader",
"creates",
"a",
"partially",
"-",
"populated",
"FileHeader",
"from",
"an",
"os",
".",
"FileInfo",
".",
"Because",
"os",
".",
"FileInfo",
"s",
"Name",
"method",
"returns",
"only",
"the",
"base",
"name",
"of",
"the",
"file",
"it",
"describes"... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/struct.go#L120-L134 |
8,352 | klauspost/compress | zip/struct.go | ModTime | func (h *FileHeader) ModTime() time.Time {
return msDosTimeToTime(h.ModifiedDate, h.ModifiedTime)
} | go | func (h *FileHeader) ModTime() time.Time {
return msDosTimeToTime(h.ModifiedDate, h.ModifiedTime)
} | [
"func",
"(",
"h",
"*",
"FileHeader",
")",
"ModTime",
"(",
")",
"time",
".",
"Time",
"{",
"return",
"msDosTimeToTime",
"(",
"h",
".",
"ModifiedDate",
",",
"h",
".",
"ModifiedTime",
")",
"\n",
"}"
] | // ModTime returns the modification time in UTC.
// The resolution is 2s. | [
"ModTime",
"returns",
"the",
"modification",
"time",
"in",
"UTC",
".",
"The",
"resolution",
"is",
"2s",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/struct.go#L179-L181 |
8,353 | klauspost/compress | zip/struct.go | SetModTime | func (h *FileHeader) SetModTime(t time.Time) {
h.ModifiedDate, h.ModifiedTime = timeToMsDosTime(t)
} | go | func (h *FileHeader) SetModTime(t time.Time) {
h.ModifiedDate, h.ModifiedTime = timeToMsDosTime(t)
} | [
"func",
"(",
"h",
"*",
"FileHeader",
")",
"SetModTime",
"(",
"t",
"time",
".",
"Time",
")",
"{",
"h",
".",
"ModifiedDate",
",",
"h",
".",
"ModifiedTime",
"=",
"timeToMsDosTime",
"(",
"t",
")",
"\n",
"}"
] | // SetModTime sets the ModifiedTime and ModifiedDate fields to the given time in UTC.
// The resolution is 2s. | [
"SetModTime",
"sets",
"the",
"ModifiedTime",
"and",
"ModifiedDate",
"fields",
"to",
"the",
"given",
"time",
"in",
"UTC",
".",
"The",
"resolution",
"is",
"2s",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/struct.go#L185-L187 |
8,354 | klauspost/compress | zip/struct.go | Mode | func (h *FileHeader) Mode() (mode os.FileMode) {
switch h.CreatorVersion >> 8 {
case creatorUnix, creatorMacOSX:
mode = unixModeToFileMode(h.ExternalAttrs >> 16)
case creatorNTFS, creatorVFAT, creatorFAT:
mode = msdosModeToFileMode(h.ExternalAttrs)
}
if len(h.Name) > 0 && h.Name[len(h.Name)-1] == '/' {
mode |= os.ModeDir
}
return mode
} | go | func (h *FileHeader) Mode() (mode os.FileMode) {
switch h.CreatorVersion >> 8 {
case creatorUnix, creatorMacOSX:
mode = unixModeToFileMode(h.ExternalAttrs >> 16)
case creatorNTFS, creatorVFAT, creatorFAT:
mode = msdosModeToFileMode(h.ExternalAttrs)
}
if len(h.Name) > 0 && h.Name[len(h.Name)-1] == '/' {
mode |= os.ModeDir
}
return mode
} | [
"func",
"(",
"h",
"*",
"FileHeader",
")",
"Mode",
"(",
")",
"(",
"mode",
"os",
".",
"FileMode",
")",
"{",
"switch",
"h",
".",
"CreatorVersion",
">>",
"8",
"{",
"case",
"creatorUnix",
",",
"creatorMacOSX",
":",
"mode",
"=",
"unixModeToFileMode",
"(",
"h... | // Mode returns the permission and mode bits for the FileHeader. | [
"Mode",
"returns",
"the",
"permission",
"and",
"mode",
"bits",
"for",
"the",
"FileHeader",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/struct.go#L209-L220 |
8,355 | klauspost/compress | zip/struct.go | SetMode | func (h *FileHeader) SetMode(mode os.FileMode) {
h.CreatorVersion = h.CreatorVersion&0xff | creatorUnix<<8
h.ExternalAttrs = fileModeToUnixMode(mode) << 16
// set MSDOS attributes too, as the original zip does.
if mode&os.ModeDir != 0 {
h.ExternalAttrs |= msdosDir
}
if mode&0200 == 0 {
h.ExternalAttrs |= msdosReadOnly
}
} | go | func (h *FileHeader) SetMode(mode os.FileMode) {
h.CreatorVersion = h.CreatorVersion&0xff | creatorUnix<<8
h.ExternalAttrs = fileModeToUnixMode(mode) << 16
// set MSDOS attributes too, as the original zip does.
if mode&os.ModeDir != 0 {
h.ExternalAttrs |= msdosDir
}
if mode&0200 == 0 {
h.ExternalAttrs |= msdosReadOnly
}
} | [
"func",
"(",
"h",
"*",
"FileHeader",
")",
"SetMode",
"(",
"mode",
"os",
".",
"FileMode",
")",
"{",
"h",
".",
"CreatorVersion",
"=",
"h",
".",
"CreatorVersion",
"&",
"0xff",
"|",
"creatorUnix",
"<<",
"8",
"\n",
"h",
".",
"ExternalAttrs",
"=",
"fileModeT... | // SetMode changes the permission and mode bits for the FileHeader. | [
"SetMode",
"changes",
"the",
"permission",
"and",
"mode",
"bits",
"for",
"the",
"FileHeader",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/struct.go#L223-L234 |
8,356 | klauspost/compress | zip/struct.go | isZip64 | func (fh *FileHeader) isZip64() bool {
return fh.CompressedSize64 >= uint32max || fh.UncompressedSize64 >= uint32max
} | go | func (fh *FileHeader) isZip64() bool {
return fh.CompressedSize64 >= uint32max || fh.UncompressedSize64 >= uint32max
} | [
"func",
"(",
"fh",
"*",
"FileHeader",
")",
"isZip64",
"(",
")",
"bool",
"{",
"return",
"fh",
".",
"CompressedSize64",
">=",
"uint32max",
"||",
"fh",
".",
"UncompressedSize64",
">=",
"uint32max",
"\n",
"}"
] | // isZip64 reports whether the file size exceeds the 32 bit limit | [
"isZip64",
"reports",
"whether",
"the",
"file",
"size",
"exceeds",
"the",
"32",
"bit",
"limit"
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zip/struct.go#L237-L239 |
8,357 | klauspost/compress | flate/huffman_code.go | set | func (h *hcode) set(code uint16, length uint16) {
h.len = length
h.code = code
} | go | func (h *hcode) set(code uint16, length uint16) {
h.len = length
h.code = code
} | [
"func",
"(",
"h",
"*",
"hcode",
")",
"set",
"(",
"code",
"uint16",
",",
"length",
"uint16",
")",
"{",
"h",
".",
"len",
"=",
"length",
"\n",
"h",
".",
"code",
"=",
"code",
"\n",
"}"
] | // set sets the code and length of an hcode. | [
"set",
"sets",
"the",
"code",
"and",
"length",
"of",
"an",
"hcode",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/huffman_code.go#L51-L54 |
8,358 | klauspost/compress | flate/huffman_code.go | generateFixedLiteralEncoding | func generateFixedLiteralEncoding() *huffmanEncoder {
h := newHuffmanEncoder(maxNumLit)
codes := h.codes
var ch uint16
for ch = 0; ch < maxNumLit; ch++ {
var bits uint16
var size uint16
switch {
case ch < 144:
// size 8, 000110000 .. 10111111
bits = ch + 48
size = 8
break
case ch < 256:
// size 9, 110010000 .. 111111111
bits = ch + 400 - 144
size = 9
break
case ch < 280:
// size 7, 0000000 .. 0010111
bits = ch - 256
size = 7
break
default:
// size 8, 11000000 .. 11000111
bits = ch + 192 - 280
size = 8
}
codes[ch] = hcode{code: reverseBits(bits, byte(size)), len: size}
}
return h
} | go | func generateFixedLiteralEncoding() *huffmanEncoder {
h := newHuffmanEncoder(maxNumLit)
codes := h.codes
var ch uint16
for ch = 0; ch < maxNumLit; ch++ {
var bits uint16
var size uint16
switch {
case ch < 144:
// size 8, 000110000 .. 10111111
bits = ch + 48
size = 8
break
case ch < 256:
// size 9, 110010000 .. 111111111
bits = ch + 400 - 144
size = 9
break
case ch < 280:
// size 7, 0000000 .. 0010111
bits = ch - 256
size = 7
break
default:
// size 8, 11000000 .. 11000111
bits = ch + 192 - 280
size = 8
}
codes[ch] = hcode{code: reverseBits(bits, byte(size)), len: size}
}
return h
} | [
"func",
"generateFixedLiteralEncoding",
"(",
")",
"*",
"huffmanEncoder",
"{",
"h",
":=",
"newHuffmanEncoder",
"(",
"maxNumLit",
")",
"\n",
"codes",
":=",
"h",
".",
"codes",
"\n",
"var",
"ch",
"uint16",
"\n",
"for",
"ch",
"=",
"0",
";",
"ch",
"<",
"maxNum... | // Generates a HuffmanCode corresponding to the fixed literal table | [
"Generates",
"a",
"HuffmanCode",
"corresponding",
"to",
"the",
"fixed",
"literal",
"table"
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/huffman_code.go#L63-L94 |
8,359 | klauspost/compress | flate/huffman_code.go | assignEncodingAndSize | func (h *huffmanEncoder) assignEncodingAndSize(bitCount []int32, list []literalNode) {
code := uint16(0)
for n, bits := range bitCount {
code <<= 1
if n == 0 || bits == 0 {
continue
}
// The literals list[len(list)-bits] .. list[len(list)-bits]
// are encoded using "bits" bits, and get the values
// code, code + 1, .... The code values are
// assigned in literal order (not frequency order).
chunk := list[len(list)-int(bits):]
h.lns.sort(chunk)
for _, node := range chunk {
h.codes[node.literal] = hcode{code: reverseBits(code, uint8(n)), len: uint16(n)}
code++
}
list = list[0 : len(list)-int(bits)]
}
} | go | func (h *huffmanEncoder) assignEncodingAndSize(bitCount []int32, list []literalNode) {
code := uint16(0)
for n, bits := range bitCount {
code <<= 1
if n == 0 || bits == 0 {
continue
}
// The literals list[len(list)-bits] .. list[len(list)-bits]
// are encoded using "bits" bits, and get the values
// code, code + 1, .... The code values are
// assigned in literal order (not frequency order).
chunk := list[len(list)-int(bits):]
h.lns.sort(chunk)
for _, node := range chunk {
h.codes[node.literal] = hcode{code: reverseBits(code, uint8(n)), len: uint16(n)}
code++
}
list = list[0 : len(list)-int(bits)]
}
} | [
"func",
"(",
"h",
"*",
"huffmanEncoder",
")",
"assignEncodingAndSize",
"(",
"bitCount",
"[",
"]",
"int32",
",",
"list",
"[",
"]",
"literalNode",
")",
"{",
"code",
":=",
"uint16",
"(",
"0",
")",
"\n",
"for",
"n",
",",
"bits",
":=",
"range",
"bitCount",
... | // Look at the leaves and assign them a bit count and an encoding as specified
// in RFC 1951 3.2.2 | [
"Look",
"at",
"the",
"leaves",
"and",
"assign",
"them",
"a",
"bit",
"count",
"and",
"an",
"encoding",
"as",
"specified",
"in",
"RFC",
"1951",
"3",
".",
"2",
".",
"2"
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/huffman_code.go#L247-L267 |
8,360 | klauspost/compress | flate/token.go | offsetCode | func offsetCode(off uint32) uint32 {
if off < uint32(len(offsetCodes)) {
return offsetCodes[off]
} else if off>>7 < uint32(len(offsetCodes)) {
return offsetCodes[off>>7] + 14
} else {
return offsetCodes[off>>14] + 28
}
} | go | func offsetCode(off uint32) uint32 {
if off < uint32(len(offsetCodes)) {
return offsetCodes[off]
} else if off>>7 < uint32(len(offsetCodes)) {
return offsetCodes[off>>7] + 14
} else {
return offsetCodes[off>>14] + 28
}
} | [
"func",
"offsetCode",
"(",
"off",
"uint32",
")",
"uint32",
"{",
"if",
"off",
"<",
"uint32",
"(",
"len",
"(",
"offsetCodes",
")",
")",
"{",
"return",
"offsetCodes",
"[",
"off",
"]",
"\n",
"}",
"else",
"if",
"off",
">>",
"7",
"<",
"uint32",
"(",
"len... | // Returns the offset code corresponding to a specific offset | [
"Returns",
"the",
"offset",
"code",
"corresponding",
"to",
"a",
"specific",
"offset"
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/token.go#L107-L115 |
8,361 | klauspost/compress | flate/dict_decoder.go | init | func (dd *dictDecoder) init(size int, dict []byte) {
*dd = dictDecoder{hist: dd.hist}
if cap(dd.hist) < size {
dd.hist = make([]byte, size)
}
dd.hist = dd.hist[:size]
if len(dict) > len(dd.hist) {
dict = dict[len(dict)-len(dd.hist):]
}
dd.wrPos = copy(dd.hist, dict)
if dd.wrPos == len(dd.hist) {
dd.wrPos = 0
dd.full = true
}
dd.rdPos = dd.wrPos
} | go | func (dd *dictDecoder) init(size int, dict []byte) {
*dd = dictDecoder{hist: dd.hist}
if cap(dd.hist) < size {
dd.hist = make([]byte, size)
}
dd.hist = dd.hist[:size]
if len(dict) > len(dd.hist) {
dict = dict[len(dict)-len(dd.hist):]
}
dd.wrPos = copy(dd.hist, dict)
if dd.wrPos == len(dd.hist) {
dd.wrPos = 0
dd.full = true
}
dd.rdPos = dd.wrPos
} | [
"func",
"(",
"dd",
"*",
"dictDecoder",
")",
"init",
"(",
"size",
"int",
",",
"dict",
"[",
"]",
"byte",
")",
"{",
"*",
"dd",
"=",
"dictDecoder",
"{",
"hist",
":",
"dd",
".",
"hist",
"}",
"\n\n",
"if",
"cap",
"(",
"dd",
".",
"hist",
")",
"<",
"... | // init initializes dictDecoder to have a sliding window dictionary of the given
// size. If a preset dict is provided, it will initialize the dictionary with
// the contents of dict. | [
"init",
"initializes",
"dictDecoder",
"to",
"have",
"a",
"sliding",
"window",
"dictionary",
"of",
"the",
"given",
"size",
".",
"If",
"a",
"preset",
"dict",
"is",
"provided",
"it",
"will",
"initialize",
"the",
"dictionary",
"with",
"the",
"contents",
"of",
"d... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/dict_decoder.go#L39-L56 |
8,362 | klauspost/compress | flate/dict_decoder.go | histSize | func (dd *dictDecoder) histSize() int {
if dd.full {
return len(dd.hist)
}
return dd.wrPos
} | go | func (dd *dictDecoder) histSize() int {
if dd.full {
return len(dd.hist)
}
return dd.wrPos
} | [
"func",
"(",
"dd",
"*",
"dictDecoder",
")",
"histSize",
"(",
")",
"int",
"{",
"if",
"dd",
".",
"full",
"{",
"return",
"len",
"(",
"dd",
".",
"hist",
")",
"\n",
"}",
"\n",
"return",
"dd",
".",
"wrPos",
"\n",
"}"
] | // histSize reports the total amount of historical data in the dictionary. | [
"histSize",
"reports",
"the",
"total",
"amount",
"of",
"historical",
"data",
"in",
"the",
"dictionary",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/dict_decoder.go#L59-L64 |
8,363 | klauspost/compress | flate/dict_decoder.go | readFlush | func (dd *dictDecoder) readFlush() []byte {
toRead := dd.hist[dd.rdPos:dd.wrPos]
dd.rdPos = dd.wrPos
if dd.wrPos == len(dd.hist) {
dd.wrPos, dd.rdPos = 0, 0
dd.full = true
}
return toRead
} | go | func (dd *dictDecoder) readFlush() []byte {
toRead := dd.hist[dd.rdPos:dd.wrPos]
dd.rdPos = dd.wrPos
if dd.wrPos == len(dd.hist) {
dd.wrPos, dd.rdPos = 0, 0
dd.full = true
}
return toRead
} | [
"func",
"(",
"dd",
"*",
"dictDecoder",
")",
"readFlush",
"(",
")",
"[",
"]",
"byte",
"{",
"toRead",
":=",
"dd",
".",
"hist",
"[",
"dd",
".",
"rdPos",
":",
"dd",
".",
"wrPos",
"]",
"\n",
"dd",
".",
"rdPos",
"=",
"dd",
".",
"wrPos",
"\n",
"if",
... | // readFlush returns a slice of the historical buffer that is ready to be
// emitted to the user. The data returned by readFlush must be fully consumed
// before calling any other dictDecoder methods. | [
"readFlush",
"returns",
"a",
"slice",
"of",
"the",
"historical",
"buffer",
"that",
"is",
"ready",
"to",
"be",
"emitted",
"to",
"the",
"user",
".",
"The",
"data",
"returned",
"by",
"readFlush",
"must",
"be",
"fully",
"consumed",
"before",
"calling",
"any",
... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/dict_decoder.go#L176-L184 |
8,364 | klauspost/compress | flate/snappy.go | Reset | func (e *snappyGen) Reset() {
e.prev = e.prev[:0]
e.cur += maxMatchOffset
} | go | func (e *snappyGen) Reset() {
e.prev = e.prev[:0]
e.cur += maxMatchOffset
} | [
"func",
"(",
"e",
"*",
"snappyGen",
")",
"Reset",
"(",
")",
"{",
"e",
".",
"prev",
"=",
"e",
".",
"prev",
"[",
":",
"0",
"]",
"\n",
"e",
".",
"cur",
"+=",
"maxMatchOffset",
"\n",
"}"
] | // Reset the encoding table. | [
"Reset",
"the",
"encoding",
"table",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/snappy.go#L897-L900 |
8,365 | klauspost/compress | zstd/decoder_options.go | WithDecoderLowmem | func WithDecoderLowmem(b bool) DOption {
return func(o *decoderOptions) error { o.lowMem = b; return nil }
} | go | func WithDecoderLowmem(b bool) DOption {
return func(o *decoderOptions) error { o.lowMem = b; return nil }
} | [
"func",
"WithDecoderLowmem",
"(",
"b",
"bool",
")",
"DOption",
"{",
"return",
"func",
"(",
"o",
"*",
"decoderOptions",
")",
"error",
"{",
"o",
".",
"lowMem",
"=",
"b",
";",
"return",
"nil",
"}",
"\n",
"}"
] | // WithDecoderLowmem will set whether to use a lower amount of memory,
// but possibly have to allocate more while running. | [
"WithDecoderLowmem",
"will",
"set",
"whether",
"to",
"use",
"a",
"lower",
"amount",
"of",
"memory",
"but",
"possibly",
"have",
"to",
"allocate",
"more",
"while",
"running",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/decoder_options.go#L34-L36 |
8,366 | klauspost/compress | zstd/decoder_options.go | WithDecoderConcurrency | func WithDecoderConcurrency(n int) DOption {
return func(o *decoderOptions) error {
if n <= 0 {
return fmt.Errorf("Concurrency must be at least 1")
}
o.concurrent = n
return nil
}
} | go | func WithDecoderConcurrency(n int) DOption {
return func(o *decoderOptions) error {
if n <= 0 {
return fmt.Errorf("Concurrency must be at least 1")
}
o.concurrent = n
return nil
}
} | [
"func",
"WithDecoderConcurrency",
"(",
"n",
"int",
")",
"DOption",
"{",
"return",
"func",
"(",
"o",
"*",
"decoderOptions",
")",
"error",
"{",
"if",
"n",
"<=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"o",
"."... | // WithDecoderConcurrency will set the concurrency,
// meaning the maximum number of decoders to run concurrently.
// The value supplied must be at least 1.
// By default this will be set to GOMAXPROCS. | [
"WithDecoderConcurrency",
"will",
"set",
"the",
"concurrency",
"meaning",
"the",
"maximum",
"number",
"of",
"decoders",
"to",
"run",
"concurrently",
".",
"The",
"value",
"supplied",
"must",
"be",
"at",
"least",
"1",
".",
"By",
"default",
"this",
"will",
"be",
... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/decoder_options.go#L42-L50 |
8,367 | klauspost/compress | fse/fse.go | HistogramFinished | func (s *Scratch) HistogramFinished(maxSymbol uint8, maxCount int) {
s.maxCount = maxCount
s.symbolLen = uint16(maxSymbol) + 1
s.clearCount = maxCount != 0
} | go | func (s *Scratch) HistogramFinished(maxSymbol uint8, maxCount int) {
s.maxCount = maxCount
s.symbolLen = uint16(maxSymbol) + 1
s.clearCount = maxCount != 0
} | [
"func",
"(",
"s",
"*",
"Scratch",
")",
"HistogramFinished",
"(",
"maxSymbol",
"uint8",
",",
"maxCount",
"int",
")",
"{",
"s",
".",
"maxCount",
"=",
"maxCount",
"\n",
"s",
".",
"symbolLen",
"=",
"uint16",
"(",
"maxSymbol",
")",
"+",
"1",
"\n",
"s",
".... | // HistogramFinished can be called to indicate that the histogram has been populated.
// maxSymbol is the index of the highest set symbol of the next data segment.
// maxCount is the number of entries in the most populated entry.
// These are accepted at face value. | [
"HistogramFinished",
"can",
"be",
"called",
"to",
"indicate",
"that",
"the",
"histogram",
"has",
"been",
"populated",
".",
"maxSymbol",
"is",
"the",
"index",
"of",
"the",
"highest",
"set",
"symbol",
"of",
"the",
"next",
"data",
"segment",
".",
"maxCount",
"i... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/fse.go#L98-L102 |
8,368 | klauspost/compress | fse/fse.go | prepare | func (s *Scratch) prepare(in []byte) (*Scratch, error) {
if s == nil {
s = &Scratch{}
}
if s.MaxSymbolValue == 0 {
s.MaxSymbolValue = 255
}
if s.TableLog == 0 {
s.TableLog = defaultTablelog
}
if s.TableLog > maxTableLog {
return nil, fmt.Errorf("tableLog (%d) > maxTableLog (%d)", s.TableLog, maxTableLog)
}
if cap(s.Out) == 0 {
s.Out = make([]byte, 0, len(in))
}
if s.clearCount && s.maxCount == 0 {
for i := range s.count {
s.count[i] = 0
}
s.clearCount = false
}
s.br.init(in)
if s.DecompressLimit == 0 {
// Max size 2GB.
s.DecompressLimit = 2 << 30
}
return s, nil
} | go | func (s *Scratch) prepare(in []byte) (*Scratch, error) {
if s == nil {
s = &Scratch{}
}
if s.MaxSymbolValue == 0 {
s.MaxSymbolValue = 255
}
if s.TableLog == 0 {
s.TableLog = defaultTablelog
}
if s.TableLog > maxTableLog {
return nil, fmt.Errorf("tableLog (%d) > maxTableLog (%d)", s.TableLog, maxTableLog)
}
if cap(s.Out) == 0 {
s.Out = make([]byte, 0, len(in))
}
if s.clearCount && s.maxCount == 0 {
for i := range s.count {
s.count[i] = 0
}
s.clearCount = false
}
s.br.init(in)
if s.DecompressLimit == 0 {
// Max size 2GB.
s.DecompressLimit = 2 << 30
}
return s, nil
} | [
"func",
"(",
"s",
"*",
"Scratch",
")",
"prepare",
"(",
"in",
"[",
"]",
"byte",
")",
"(",
"*",
"Scratch",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"s",
"=",
"&",
"Scratch",
"{",
"}",
"\n",
"}",
"\n",
"if",
"s",
".",
"MaxSymbolValue... | // prepare will prepare and allocate scratch tables used for both compression and decompression. | [
"prepare",
"will",
"prepare",
"and",
"allocate",
"scratch",
"tables",
"used",
"for",
"both",
"compression",
"and",
"decompression",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/fse.go#L105-L134 |
8,369 | klauspost/compress | compressible.go | Estimate | func Estimate(b []byte) float64 {
if len(b) < 16 {
return 0
}
// Correctly predicted order 1
hits := 0
lastMatch := false
var o1 [256]byte
var hist [256]int
c1 := byte(0)
for _, c := range b {
if c == o1[c1] {
// We only count a hit if there was two correct predictions in a row.
if lastMatch {
hits++
}
lastMatch = true
} else {
lastMatch = false
}
o1[c1] = c
c1 = c
hist[c]++
}
// Use x^0.6 to give better spread
prediction := math.Pow(float64(hits)/float64(len(b)), 0.6)
// Calculate histogram distribution
variance := float64(0)
avg := float64(len(b)) / 256
for _, v := range hist {
Δ := float64(v) - avg
variance += Δ * Δ
}
stddev := math.Sqrt(float64(variance)) / float64(len(b))
exp := math.Sqrt(1 / float64(len(b)))
// Subtract expected stddev
stddev -= exp
if stddev < 0 {
stddev = 0
}
stddev *= 1 + exp
// Use x^0.4 to give better spread
entropy := math.Pow(stddev, 0.4)
// 50/50 weight between prediction and histogram distribution
return math.Pow((prediction+entropy)/2, 0.9)
} | go | func Estimate(b []byte) float64 {
if len(b) < 16 {
return 0
}
// Correctly predicted order 1
hits := 0
lastMatch := false
var o1 [256]byte
var hist [256]int
c1 := byte(0)
for _, c := range b {
if c == o1[c1] {
// We only count a hit if there was two correct predictions in a row.
if lastMatch {
hits++
}
lastMatch = true
} else {
lastMatch = false
}
o1[c1] = c
c1 = c
hist[c]++
}
// Use x^0.6 to give better spread
prediction := math.Pow(float64(hits)/float64(len(b)), 0.6)
// Calculate histogram distribution
variance := float64(0)
avg := float64(len(b)) / 256
for _, v := range hist {
Δ := float64(v) - avg
variance += Δ * Δ
}
stddev := math.Sqrt(float64(variance)) / float64(len(b))
exp := math.Sqrt(1 / float64(len(b)))
// Subtract expected stddev
stddev -= exp
if stddev < 0 {
stddev = 0
}
stddev *= 1 + exp
// Use x^0.4 to give better spread
entropy := math.Pow(stddev, 0.4)
// 50/50 weight between prediction and histogram distribution
return math.Pow((prediction+entropy)/2, 0.9)
} | [
"func",
"Estimate",
"(",
"b",
"[",
"]",
"byte",
")",
"float64",
"{",
"if",
"len",
"(",
"b",
")",
"<",
"16",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"// Correctly predicted order 1",
"hits",
":=",
"0",
"\n",
"lastMatch",
":=",
"false",
"\n",
"var",
"o1... | // Estimate returns a normalized compressibility estimate of block b.
// Values close to zero are likely uncompressible.
// Values above 0.1 are likely to be compressible.
// Values above 0.5 are very compressible.
// Very small lengths will return 0. | [
"Estimate",
"returns",
"a",
"normalized",
"compressibility",
"estimate",
"of",
"block",
"b",
".",
"Values",
"close",
"to",
"zero",
"are",
"likely",
"uncompressible",
".",
"Values",
"above",
"0",
".",
"1",
"are",
"likely",
"to",
"be",
"compressible",
".",
"Va... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/compressible.go#L10-L63 |
8,370 | klauspost/compress | fse/bytereader.go | init | func (b *byteReader) init(in []byte) {
b.b = in
b.off = 0
} | go | func (b *byteReader) init(in []byte) {
b.b = in
b.off = 0
} | [
"func",
"(",
"b",
"*",
"byteReader",
")",
"init",
"(",
"in",
"[",
"]",
"byte",
")",
"{",
"b",
".",
"b",
"=",
"in",
"\n",
"b",
".",
"off",
"=",
"0",
"\n",
"}"
] | // init will initialize the reader and set the input. | [
"init",
"will",
"initialize",
"the",
"reader",
"and",
"set",
"the",
"input",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/bytereader.go#L18-L21 |
8,371 | klauspost/compress | zstd/bytereader.go | Uint8 | func (b *byteReader) Uint8() uint8 {
v := b.b[b.off]
return v
} | go | func (b *byteReader) Uint8() uint8 {
v := b.b[b.off]
return v
} | [
"func",
"(",
"b",
"*",
"byteReader",
")",
"Uint8",
"(",
")",
"uint8",
"{",
"v",
":=",
"b",
".",
"b",
"[",
"b",
".",
"off",
"]",
"\n",
"return",
"v",
"\n",
"}"
] | // Uint8 returns the next byte | [
"Uint8",
"returns",
"the",
"next",
"byte"
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/bytereader.go#L43-L46 |
8,372 | klauspost/compress | flate/inflate.go | dataBlock | func (f *decompressor) dataBlock() {
// Uncompressed.
// Discard current half-byte.
f.nb = 0
f.b = 0
// Length then ones-complement of length.
nr, err := io.ReadFull(f.r, f.buf[0:4])
f.roffset += int64(nr)
if err != nil {
f.err = noEOF(err)
return
}
n := int(f.buf[0]) | int(f.buf[1])<<8
nn := int(f.buf[2]) | int(f.buf[3])<<8
if uint16(nn) != uint16(^n) {
f.err = CorruptInputError(f.roffset)
return
}
if n == 0 {
f.toRead = f.dict.readFlush()
f.finishBlock()
return
}
f.copyLen = n
f.copyData()
} | go | func (f *decompressor) dataBlock() {
// Uncompressed.
// Discard current half-byte.
f.nb = 0
f.b = 0
// Length then ones-complement of length.
nr, err := io.ReadFull(f.r, f.buf[0:4])
f.roffset += int64(nr)
if err != nil {
f.err = noEOF(err)
return
}
n := int(f.buf[0]) | int(f.buf[1])<<8
nn := int(f.buf[2]) | int(f.buf[3])<<8
if uint16(nn) != uint16(^n) {
f.err = CorruptInputError(f.roffset)
return
}
if n == 0 {
f.toRead = f.dict.readFlush()
f.finishBlock()
return
}
f.copyLen = n
f.copyData()
} | [
"func",
"(",
"f",
"*",
"decompressor",
")",
"dataBlock",
"(",
")",
"{",
"// Uncompressed.",
"// Discard current half-byte.",
"f",
".",
"nb",
"=",
"0",
"\n",
"f",
".",
"b",
"=",
"0",
"\n\n",
"// Length then ones-complement of length.",
"nr",
",",
"err",
":=",
... | // Copy a single uncompressed data block from input to output. | [
"Copy",
"a",
"single",
"uncompressed",
"data",
"block",
"from",
"input",
"to",
"output",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/inflate.go#L675-L703 |
8,373 | klauspost/compress | flate/inflate.go | copyData | func (f *decompressor) copyData() {
buf := f.dict.writeSlice()
if len(buf) > f.copyLen {
buf = buf[:f.copyLen]
}
cnt, err := io.ReadFull(f.r, buf)
f.roffset += int64(cnt)
f.copyLen -= cnt
f.dict.writeMark(cnt)
if err != nil {
f.err = noEOF(err)
return
}
if f.dict.availWrite() == 0 || f.copyLen > 0 {
f.toRead = f.dict.readFlush()
f.step = (*decompressor).copyData
return
}
f.finishBlock()
} | go | func (f *decompressor) copyData() {
buf := f.dict.writeSlice()
if len(buf) > f.copyLen {
buf = buf[:f.copyLen]
}
cnt, err := io.ReadFull(f.r, buf)
f.roffset += int64(cnt)
f.copyLen -= cnt
f.dict.writeMark(cnt)
if err != nil {
f.err = noEOF(err)
return
}
if f.dict.availWrite() == 0 || f.copyLen > 0 {
f.toRead = f.dict.readFlush()
f.step = (*decompressor).copyData
return
}
f.finishBlock()
} | [
"func",
"(",
"f",
"*",
"decompressor",
")",
"copyData",
"(",
")",
"{",
"buf",
":=",
"f",
".",
"dict",
".",
"writeSlice",
"(",
")",
"\n",
"if",
"len",
"(",
"buf",
")",
">",
"f",
".",
"copyLen",
"{",
"buf",
"=",
"buf",
"[",
":",
"f",
".",
"copy... | // copyData copies f.copyLen bytes from the underlying reader into f.hist.
// It pauses for reads when f.hist is full. | [
"copyData",
"copies",
"f",
".",
"copyLen",
"bytes",
"from",
"the",
"underlying",
"reader",
"into",
"f",
".",
"hist",
".",
"It",
"pauses",
"for",
"reads",
"when",
"f",
".",
"hist",
"is",
"full",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/inflate.go#L707-L728 |
8,374 | klauspost/compress | flate/inflate.go | noEOF | func noEOF(e error) error {
if e == io.EOF {
return io.ErrUnexpectedEOF
}
return e
} | go | func noEOF(e error) error {
if e == io.EOF {
return io.ErrUnexpectedEOF
}
return e
} | [
"func",
"noEOF",
"(",
"e",
"error",
")",
"error",
"{",
"if",
"e",
"==",
"io",
".",
"EOF",
"{",
"return",
"io",
".",
"ErrUnexpectedEOF",
"\n",
"}",
"\n",
"return",
"e",
"\n",
"}"
] | // noEOF returns err, unless err == io.EOF, in which case it returns io.ErrUnexpectedEOF. | [
"noEOF",
"returns",
"err",
"unless",
"err",
"==",
"io",
".",
"EOF",
"in",
"which",
"case",
"it",
"returns",
"io",
".",
"ErrUnexpectedEOF",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/inflate.go#L741-L746 |
8,375 | klauspost/compress | flate/inflate.go | huffSym | func (f *decompressor) huffSym(h *huffmanDecoder) (int, error) {
// Since a huffmanDecoder can be empty or be composed of a degenerate tree
// with single element, huffSym must error on these two edge cases. In both
// cases, the chunks slice will be 0 for the invalid sequence, leading it
// satisfy the n == 0 check below.
n := uint(h.min)
// Optimization. Compiler isn't smart enough to keep f.b,f.nb in registers,
// but is smart enough to keep local variables in registers, so use nb and b,
// inline call to moreBits and reassign b,nb back to f on return.
nb, b := f.nb, f.b
for {
for nb < n {
c, err := f.r.ReadByte()
if err != nil {
f.b = b
f.nb = nb
return 0, noEOF(err)
}
f.roffset++
b |= uint32(c) << (nb & 31)
nb += 8
}
chunk := h.chunks[b&(huffmanNumChunks-1)]
n = uint(chunk & huffmanCountMask)
if n > huffmanChunkBits {
chunk = h.links[chunk>>huffmanValueShift][(b>>huffmanChunkBits)&h.linkMask]
n = uint(chunk & huffmanCountMask)
}
if n <= nb {
if n == 0 {
f.b = b
f.nb = nb
f.err = CorruptInputError(f.roffset)
return 0, f.err
}
f.b = b >> (n & 31)
f.nb = nb - n
return int(chunk >> huffmanValueShift), nil
}
}
} | go | func (f *decompressor) huffSym(h *huffmanDecoder) (int, error) {
// Since a huffmanDecoder can be empty or be composed of a degenerate tree
// with single element, huffSym must error on these two edge cases. In both
// cases, the chunks slice will be 0 for the invalid sequence, leading it
// satisfy the n == 0 check below.
n := uint(h.min)
// Optimization. Compiler isn't smart enough to keep f.b,f.nb in registers,
// but is smart enough to keep local variables in registers, so use nb and b,
// inline call to moreBits and reassign b,nb back to f on return.
nb, b := f.nb, f.b
for {
for nb < n {
c, err := f.r.ReadByte()
if err != nil {
f.b = b
f.nb = nb
return 0, noEOF(err)
}
f.roffset++
b |= uint32(c) << (nb & 31)
nb += 8
}
chunk := h.chunks[b&(huffmanNumChunks-1)]
n = uint(chunk & huffmanCountMask)
if n > huffmanChunkBits {
chunk = h.links[chunk>>huffmanValueShift][(b>>huffmanChunkBits)&h.linkMask]
n = uint(chunk & huffmanCountMask)
}
if n <= nb {
if n == 0 {
f.b = b
f.nb = nb
f.err = CorruptInputError(f.roffset)
return 0, f.err
}
f.b = b >> (n & 31)
f.nb = nb - n
return int(chunk >> huffmanValueShift), nil
}
}
} | [
"func",
"(",
"f",
"*",
"decompressor",
")",
"huffSym",
"(",
"h",
"*",
"huffmanDecoder",
")",
"(",
"int",
",",
"error",
")",
"{",
"// Since a huffmanDecoder can be empty or be composed of a degenerate tree",
"// with single element, huffSym must error on these two edge cases. In... | // Read the next Huffman-encoded symbol from f according to h. | [
"Read",
"the",
"next",
"Huffman",
"-",
"encoded",
"symbol",
"from",
"f",
"according",
"to",
"h",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/inflate.go#L760-L800 |
8,376 | klauspost/compress | flate/inflate.go | NewReader | func NewReader(r io.Reader) io.ReadCloser {
fixedHuffmanDecoderInit()
var f decompressor
f.r = makeReader(r)
f.bits = new([maxNumLit + maxNumDist]int)
f.codebits = new([numCodes]int)
f.step = (*decompressor).nextBlock
f.dict.init(maxMatchOffset, nil)
return &f
} | go | func NewReader(r io.Reader) io.ReadCloser {
fixedHuffmanDecoderInit()
var f decompressor
f.r = makeReader(r)
f.bits = new([maxNumLit + maxNumDist]int)
f.codebits = new([numCodes]int)
f.step = (*decompressor).nextBlock
f.dict.init(maxMatchOffset, nil)
return &f
} | [
"func",
"NewReader",
"(",
"r",
"io",
".",
"Reader",
")",
"io",
".",
"ReadCloser",
"{",
"fixedHuffmanDecoderInit",
"(",
")",
"\n\n",
"var",
"f",
"decompressor",
"\n",
"f",
".",
"r",
"=",
"makeReader",
"(",
"r",
")",
"\n",
"f",
".",
"bits",
"=",
"new",... | // NewReader returns a new ReadCloser that can be used
// to read the uncompressed version of r.
// If r does not also implement io.ByteReader,
// the decompressor may read more data than necessary from r.
// It is the caller's responsibility to call Close on the ReadCloser
// when finished reading.
//
// The ReadCloser returned by NewReader also implements Resetter. | [
"NewReader",
"returns",
"a",
"new",
"ReadCloser",
"that",
"can",
"be",
"used",
"to",
"read",
"the",
"uncompressed",
"version",
"of",
"r",
".",
"If",
"r",
"does",
"not",
"also",
"implement",
"io",
".",
"ByteReader",
"the",
"decompressor",
"may",
"read",
"mo... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/flate/inflate.go#L851-L861 |
8,377 | klauspost/compress | zstd/fse_predefined.go | fillBase | func fillBase(dst []baseOffset, base uint32, bits ...uint8) {
if len(bits) != len(dst) {
panic(fmt.Sprintf("len(dst) (%d) != len(bits) (%d)", len(dst), len(bits)))
}
for i, bit := range bits {
if base > math.MaxInt32 {
panic(fmt.Sprintf("invalid decoding table, base overflows int32"))
}
dst[i] = baseOffset{
baseLine: base,
addBits: bit,
}
base += 1 << bit
}
} | go | func fillBase(dst []baseOffset, base uint32, bits ...uint8) {
if len(bits) != len(dst) {
panic(fmt.Sprintf("len(dst) (%d) != len(bits) (%d)", len(dst), len(bits)))
}
for i, bit := range bits {
if base > math.MaxInt32 {
panic(fmt.Sprintf("invalid decoding table, base overflows int32"))
}
dst[i] = baseOffset{
baseLine: base,
addBits: bit,
}
base += 1 << bit
}
} | [
"func",
"fillBase",
"(",
"dst",
"[",
"]",
"baseOffset",
",",
"base",
"uint32",
",",
"bits",
"...",
"uint8",
")",
"{",
"if",
"len",
"(",
"bits",
")",
"!=",
"len",
"(",
"dst",
")",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"... | // fillBase will precalculate base offsets with the given bit distributions. | [
"fillBase",
"will",
"precalculate",
"base",
"offsets",
"with",
"the",
"given",
"bit",
"distributions",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/fse_predefined.go#L43-L58 |
8,378 | klauspost/compress | fse/compress.go | Compress | func Compress(in []byte, s *Scratch) ([]byte, error) {
if len(in) <= 1 {
return nil, ErrIncompressible
}
if len(in) >= 2<<30 {
return nil, errors.New("input too big, must be < 2GB")
}
s, err := s.prepare(in)
if err != nil {
return nil, err
}
// Create histogram, if none was provided.
maxCount := s.maxCount
if maxCount == 0 {
maxCount = s.countSimple(in)
}
// Reset for next run.
s.clearCount = true
s.maxCount = 0
if maxCount == len(in) {
// One symbol, use RLE
return nil, ErrUseRLE
}
if maxCount == 1 || maxCount < (len(in)>>7) {
// Each symbol present maximum once or too well distributed.
return nil, ErrIncompressible
}
s.optimalTableLog()
err = s.normalizeCount()
if err != nil {
return nil, err
}
err = s.writeCount()
if err != nil {
return nil, err
}
if false {
err = s.validateNorm()
if err != nil {
return nil, err
}
}
err = s.buildCTable()
if err != nil {
return nil, err
}
err = s.compress(in)
if err != nil {
return nil, err
}
s.Out = s.bw.out
// Check if we compressed.
if len(s.Out) >= len(in) {
return nil, ErrIncompressible
}
return s.Out, nil
} | go | func Compress(in []byte, s *Scratch) ([]byte, error) {
if len(in) <= 1 {
return nil, ErrIncompressible
}
if len(in) >= 2<<30 {
return nil, errors.New("input too big, must be < 2GB")
}
s, err := s.prepare(in)
if err != nil {
return nil, err
}
// Create histogram, if none was provided.
maxCount := s.maxCount
if maxCount == 0 {
maxCount = s.countSimple(in)
}
// Reset for next run.
s.clearCount = true
s.maxCount = 0
if maxCount == len(in) {
// One symbol, use RLE
return nil, ErrUseRLE
}
if maxCount == 1 || maxCount < (len(in)>>7) {
// Each symbol present maximum once or too well distributed.
return nil, ErrIncompressible
}
s.optimalTableLog()
err = s.normalizeCount()
if err != nil {
return nil, err
}
err = s.writeCount()
if err != nil {
return nil, err
}
if false {
err = s.validateNorm()
if err != nil {
return nil, err
}
}
err = s.buildCTable()
if err != nil {
return nil, err
}
err = s.compress(in)
if err != nil {
return nil, err
}
s.Out = s.bw.out
// Check if we compressed.
if len(s.Out) >= len(in) {
return nil, ErrIncompressible
}
return s.Out, nil
} | [
"func",
"Compress",
"(",
"in",
"[",
"]",
"byte",
",",
"s",
"*",
"Scratch",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"len",
"(",
"in",
")",
"<=",
"1",
"{",
"return",
"nil",
",",
"ErrIncompressible",
"\n",
"}",
"\n",
"if",
"len",... | // Compress the input bytes. Input must be < 2GB.
// Provide a Scratch buffer to avoid memory allocations.
// Note that the output is also kept in the scratch buffer.
// If input is too hard to compress, ErrIncompressible is returned.
// If input is a single byte value repeated ErrUseRLE is returned. | [
"Compress",
"the",
"input",
"bytes",
".",
"Input",
"must",
"be",
"<",
"2GB",
".",
"Provide",
"a",
"Scratch",
"buffer",
"to",
"avoid",
"memory",
"allocations",
".",
"Note",
"that",
"the",
"output",
"is",
"also",
"kept",
"in",
"the",
"scratch",
"buffer",
"... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/compress.go#L18-L77 |
8,379 | klauspost/compress | fse/compress.go | init | func (c *cState) init(bw *bitWriter, ct *cTable, tableLog uint8, first symbolTransform) {
c.bw = bw
c.stateTable = ct.stateTable
nbBitsOut := (first.deltaNbBits + (1 << 15)) >> 16
im := int32((nbBitsOut << 16) - first.deltaNbBits)
lu := (im >> nbBitsOut) + first.deltaFindState
c.state = c.stateTable[lu]
return
} | go | func (c *cState) init(bw *bitWriter, ct *cTable, tableLog uint8, first symbolTransform) {
c.bw = bw
c.stateTable = ct.stateTable
nbBitsOut := (first.deltaNbBits + (1 << 15)) >> 16
im := int32((nbBitsOut << 16) - first.deltaNbBits)
lu := (im >> nbBitsOut) + first.deltaFindState
c.state = c.stateTable[lu]
return
} | [
"func",
"(",
"c",
"*",
"cState",
")",
"init",
"(",
"bw",
"*",
"bitWriter",
",",
"ct",
"*",
"cTable",
",",
"tableLog",
"uint8",
",",
"first",
"symbolTransform",
")",
"{",
"c",
".",
"bw",
"=",
"bw",
"\n",
"c",
".",
"stateTable",
"=",
"ct",
".",
"st... | // init will initialize the compression state to the first symbol of the stream. | [
"init",
"will",
"initialize",
"the",
"compression",
"state",
"to",
"the",
"first",
"symbol",
"of",
"the",
"stream",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/compress.go#L87-L96 |
8,380 | klauspost/compress | fse/compress.go | flush | func (c *cState) flush(tableLog uint8) {
c.bw.flush32()
c.bw.addBits16NC(c.state, tableLog)
c.bw.flush()
} | go | func (c *cState) flush(tableLog uint8) {
c.bw.flush32()
c.bw.addBits16NC(c.state, tableLog)
c.bw.flush()
} | [
"func",
"(",
"c",
"*",
"cState",
")",
"flush",
"(",
"tableLog",
"uint8",
")",
"{",
"c",
".",
"bw",
".",
"flush32",
"(",
")",
"\n",
"c",
".",
"bw",
".",
"addBits16NC",
"(",
"c",
".",
"state",
",",
"tableLog",
")",
"\n",
"c",
".",
"bw",
".",
"f... | // flush will write the tablelog to the output and flush the remaining full bytes. | [
"flush",
"will",
"write",
"the",
"tablelog",
"to",
"the",
"output",
"and",
"flush",
"the",
"remaining",
"full",
"bytes",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/compress.go#L115-L119 |
8,381 | klauspost/compress | fse/compress.go | String | func (s symbolTransform) String() string {
return fmt.Sprintf("dnbits: %08x, fs:%d", s.deltaNbBits, s.deltaFindState)
} | go | func (s symbolTransform) String() string {
return fmt.Sprintf("dnbits: %08x, fs:%d", s.deltaNbBits, s.deltaFindState)
} | [
"func",
"(",
"s",
"symbolTransform",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"deltaNbBits",
",",
"s",
".",
"deltaFindState",
")",
"\n",
"}"
] | // String prints values as a human readable string. | [
"String",
"prints",
"values",
"as",
"a",
"human",
"readable",
"string",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/compress.go#L318-L320 |
8,382 | klauspost/compress | fse/compress.go | allocCtable | func (s *Scratch) allocCtable() {
tableSize := 1 << s.actualTableLog
// get tableSymbol that is big enough.
if cap(s.ct.tableSymbol) < int(tableSize) {
s.ct.tableSymbol = make([]byte, tableSize)
}
s.ct.tableSymbol = s.ct.tableSymbol[:tableSize]
ctSize := tableSize
if cap(s.ct.stateTable) < ctSize {
s.ct.stateTable = make([]uint16, ctSize)
}
s.ct.stateTable = s.ct.stateTable[:ctSize]
if cap(s.ct.symbolTT) < int(s.symbolLen) {
s.ct.symbolTT = make([]symbolTransform, 256)
}
s.ct.symbolTT = s.ct.symbolTT[:256]
} | go | func (s *Scratch) allocCtable() {
tableSize := 1 << s.actualTableLog
// get tableSymbol that is big enough.
if cap(s.ct.tableSymbol) < int(tableSize) {
s.ct.tableSymbol = make([]byte, tableSize)
}
s.ct.tableSymbol = s.ct.tableSymbol[:tableSize]
ctSize := tableSize
if cap(s.ct.stateTable) < ctSize {
s.ct.stateTable = make([]uint16, ctSize)
}
s.ct.stateTable = s.ct.stateTable[:ctSize]
if cap(s.ct.symbolTT) < int(s.symbolLen) {
s.ct.symbolTT = make([]symbolTransform, 256)
}
s.ct.symbolTT = s.ct.symbolTT[:256]
} | [
"func",
"(",
"s",
"*",
"Scratch",
")",
"allocCtable",
"(",
")",
"{",
"tableSize",
":=",
"1",
"<<",
"s",
".",
"actualTableLog",
"\n",
"// get tableSymbol that is big enough.",
"if",
"cap",
"(",
"s",
".",
"ct",
".",
"tableSymbol",
")",
"<",
"int",
"(",
"ta... | // allocCtable will allocate tables needed for compression.
// If existing tables a re big enough, they are simply re-used. | [
"allocCtable",
"will",
"allocate",
"tables",
"needed",
"for",
"compression",
".",
"If",
"existing",
"tables",
"a",
"re",
"big",
"enough",
"they",
"are",
"simply",
"re",
"-",
"used",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/compress.go#L331-L349 |
8,383 | klauspost/compress | fse/compress.go | normalizeCount | func (s *Scratch) normalizeCount() error {
var (
tableLog = s.actualTableLog
scale = 62 - uint64(tableLog)
step = (1 << 62) / uint64(s.br.remain())
vStep = uint64(1) << (scale - 20)
stillToDistribute = int16(1 << tableLog)
largest int
largestP int16
lowThreshold = (uint32)(s.br.remain() >> tableLog)
)
for i, cnt := range s.count[:s.symbolLen] {
// already handled
// if (count[s] == s.length) return 0; /* rle special case */
if cnt == 0 {
s.norm[i] = 0
continue
}
if cnt <= lowThreshold {
s.norm[i] = -1
stillToDistribute--
} else {
proba := (int16)((uint64(cnt) * step) >> scale)
if proba < 8 {
restToBeat := vStep * uint64(rtbTable[proba])
v := uint64(cnt)*step - (uint64(proba) << scale)
if v > restToBeat {
proba++
}
}
if proba > largestP {
largestP = proba
largest = i
}
s.norm[i] = proba
stillToDistribute -= proba
}
}
if -stillToDistribute >= (s.norm[largest] >> 1) {
// corner case, need another normalization method
return s.normalizeCount2()
}
s.norm[largest] += stillToDistribute
return nil
} | go | func (s *Scratch) normalizeCount() error {
var (
tableLog = s.actualTableLog
scale = 62 - uint64(tableLog)
step = (1 << 62) / uint64(s.br.remain())
vStep = uint64(1) << (scale - 20)
stillToDistribute = int16(1 << tableLog)
largest int
largestP int16
lowThreshold = (uint32)(s.br.remain() >> tableLog)
)
for i, cnt := range s.count[:s.symbolLen] {
// already handled
// if (count[s] == s.length) return 0; /* rle special case */
if cnt == 0 {
s.norm[i] = 0
continue
}
if cnt <= lowThreshold {
s.norm[i] = -1
stillToDistribute--
} else {
proba := (int16)((uint64(cnt) * step) >> scale)
if proba < 8 {
restToBeat := vStep * uint64(rtbTable[proba])
v := uint64(cnt)*step - (uint64(proba) << scale)
if v > restToBeat {
proba++
}
}
if proba > largestP {
largestP = proba
largest = i
}
s.norm[i] = proba
stillToDistribute -= proba
}
}
if -stillToDistribute >= (s.norm[largest] >> 1) {
// corner case, need another normalization method
return s.normalizeCount2()
}
s.norm[largest] += stillToDistribute
return nil
} | [
"func",
"(",
"s",
"*",
"Scratch",
")",
"normalizeCount",
"(",
")",
"error",
"{",
"var",
"(",
"tableLog",
"=",
"s",
".",
"actualTableLog",
"\n",
"scale",
"=",
"62",
"-",
"uint64",
"(",
"tableLog",
")",
"\n",
"step",
"=",
"(",
"1",
"<<",
"62",
")",
... | // normalizeCount will normalize the count of the symbols so
// the total is equal to the table size. | [
"normalizeCount",
"will",
"normalize",
"the",
"count",
"of",
"the",
"symbols",
"so",
"the",
"total",
"is",
"equal",
"to",
"the",
"table",
"size",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/compress.go#L511-L558 |
8,384 | klauspost/compress | fse/compress.go | validateNorm | func (s *Scratch) validateNorm() (err error) {
var total int
for _, v := range s.norm[:s.symbolLen] {
if v >= 0 {
total += int(v)
} else {
total -= int(v)
}
}
defer func() {
if err == nil {
return
}
fmt.Printf("selected TableLog: %d, Symbol length: %d\n", s.actualTableLog, s.symbolLen)
for i, v := range s.norm[:s.symbolLen] {
fmt.Printf("%3d: %5d -> %4d \n", i, s.count[i], v)
}
}()
if total != (1 << s.actualTableLog) {
return fmt.Errorf("warning: Total == %d != %d", total, 1<<s.actualTableLog)
}
for i, v := range s.count[s.symbolLen:] {
if v != 0 {
return fmt.Errorf("warning: Found symbol out of range, %d after cut", i)
}
}
return nil
} | go | func (s *Scratch) validateNorm() (err error) {
var total int
for _, v := range s.norm[:s.symbolLen] {
if v >= 0 {
total += int(v)
} else {
total -= int(v)
}
}
defer func() {
if err == nil {
return
}
fmt.Printf("selected TableLog: %d, Symbol length: %d\n", s.actualTableLog, s.symbolLen)
for i, v := range s.norm[:s.symbolLen] {
fmt.Printf("%3d: %5d -> %4d \n", i, s.count[i], v)
}
}()
if total != (1 << s.actualTableLog) {
return fmt.Errorf("warning: Total == %d != %d", total, 1<<s.actualTableLog)
}
for i, v := range s.count[s.symbolLen:] {
if v != 0 {
return fmt.Errorf("warning: Found symbol out of range, %d after cut", i)
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Scratch",
")",
"validateNorm",
"(",
")",
"(",
"err",
"error",
")",
"{",
"var",
"total",
"int",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"s",
".",
"norm",
"[",
":",
"s",
".",
"symbolLen",
"]",
"{",
"if",
"v",
">=",
"0... | // validateNorm validates the normalized histogram table. | [
"validateNorm",
"validates",
"the",
"normalized",
"histogram",
"table",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/fse/compress.go#L657-L684 |
8,385 | klauspost/compress | zstd/decoder.go | Read | func (d *Decoder) Read(p []byte) (int, error) {
if d.stream == nil {
return 0, errors.New("no input has been initialized")
}
var n int
for {
if len(d.current.b) > 0 {
filled := copy(p, d.current.b)
p = p[filled:]
d.current.b = d.current.b[filled:]
n += filled
}
if len(p) == 0 {
break
}
if len(d.current.b) == 0 {
// We have an error and no more data
if d.current.err != nil {
break
}
d.nextBlock()
}
}
if len(d.current.b) > 0 {
// Only return error at end of block
return n, nil
}
if d.current.err != nil {
d.drainOutput()
}
if debug {
println("returning", n, d.current.err, len(d.decoders))
}
return n, d.current.err
} | go | func (d *Decoder) Read(p []byte) (int, error) {
if d.stream == nil {
return 0, errors.New("no input has been initialized")
}
var n int
for {
if len(d.current.b) > 0 {
filled := copy(p, d.current.b)
p = p[filled:]
d.current.b = d.current.b[filled:]
n += filled
}
if len(p) == 0 {
break
}
if len(d.current.b) == 0 {
// We have an error and no more data
if d.current.err != nil {
break
}
d.nextBlock()
}
}
if len(d.current.b) > 0 {
// Only return error at end of block
return n, nil
}
if d.current.err != nil {
d.drainOutput()
}
if debug {
println("returning", n, d.current.err, len(d.decoders))
}
return n, d.current.err
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"d",
".",
"stream",
"==",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",... | // Read bytes from the decompressed stream into p.
// Returns the number of bytes written and any error that occurred.
// When the stream is done, io.EOF will be returned. | [
"Read",
"bytes",
"from",
"the",
"decompressed",
"stream",
"into",
"p",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"written",
"and",
"any",
"error",
"that",
"occurred",
".",
"When",
"the",
"stream",
"is",
"done",
"io",
".",
"EOF",
"will",
"be",
"retu... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/decoder.go#L105-L139 |
8,386 | klauspost/compress | zstd/decoder.go | Reset | func (d *Decoder) Reset(r io.Reader) error {
if d.current.err == ErrDecoderClosed {
return d.current.err
}
if r == nil {
return errors.New("nil Reader sent as input")
}
// TODO: If r is a *bytes.Buffer, we could automatically switch to sync operation.
if d.stream == nil {
d.stream = make(chan decodeStream, 1)
go d.startStreamDecoder(d.stream)
}
d.drainOutput()
// Remove current block.
d.current.decodeOutput = decodeOutput{}
d.current.err = nil
d.current.cancel = make(chan struct{})
d.current.flushed = false
d.current.d = nil
d.stream <- decodeStream{
r: r,
output: d.current.output,
cancel: d.current.cancel,
}
return nil
} | go | func (d *Decoder) Reset(r io.Reader) error {
if d.current.err == ErrDecoderClosed {
return d.current.err
}
if r == nil {
return errors.New("nil Reader sent as input")
}
// TODO: If r is a *bytes.Buffer, we could automatically switch to sync operation.
if d.stream == nil {
d.stream = make(chan decodeStream, 1)
go d.startStreamDecoder(d.stream)
}
d.drainOutput()
// Remove current block.
d.current.decodeOutput = decodeOutput{}
d.current.err = nil
d.current.cancel = make(chan struct{})
d.current.flushed = false
d.current.d = nil
d.stream <- decodeStream{
r: r,
output: d.current.output,
cancel: d.current.cancel,
}
return nil
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"Reset",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"if",
"d",
".",
"current",
".",
"err",
"==",
"ErrDecoderClosed",
"{",
"return",
"d",
".",
"current",
".",
"err",
"\n",
"}",
"\n",
"if",
"r",
"==",
... | // Reset will reset the decoder the supplied stream after the current has finished processing.
// Note that this functionality cannot be used after Close has been called. | [
"Reset",
"will",
"reset",
"the",
"decoder",
"the",
"supplied",
"stream",
"after",
"the",
"current",
"has",
"finished",
"processing",
".",
"Note",
"that",
"this",
"functionality",
"cannot",
"be",
"used",
"after",
"Close",
"has",
"been",
"called",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/decoder.go#L143-L173 |
8,387 | klauspost/compress | zstd/decoder.go | drainOutput | func (d *Decoder) drainOutput() {
if d.current.cancel != nil {
println("cancelling current")
close(d.current.cancel)
d.current.cancel = nil
}
if d.current.d != nil {
println("re-adding current decoder", d.current.d, len(d.decoders))
d.decoders <- d.current.d
d.current.d = nil
d.current.b = nil
}
if d.current.output == nil || d.current.flushed {
println("current already flushed")
return
}
for {
select {
case v := <-d.current.output:
if v.d != nil {
println("got decoder", v.d)
d.decoders <- v.d
}
if v.err == errEndOfStream {
println("current flushed")
d.current.flushed = true
return
}
}
}
} | go | func (d *Decoder) drainOutput() {
if d.current.cancel != nil {
println("cancelling current")
close(d.current.cancel)
d.current.cancel = nil
}
if d.current.d != nil {
println("re-adding current decoder", d.current.d, len(d.decoders))
d.decoders <- d.current.d
d.current.d = nil
d.current.b = nil
}
if d.current.output == nil || d.current.flushed {
println("current already flushed")
return
}
for {
select {
case v := <-d.current.output:
if v.d != nil {
println("got decoder", v.d)
d.decoders <- v.d
}
if v.err == errEndOfStream {
println("current flushed")
d.current.flushed = true
return
}
}
}
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"drainOutput",
"(",
")",
"{",
"if",
"d",
".",
"current",
".",
"cancel",
"!=",
"nil",
"{",
"println",
"(",
"\"",
"\"",
")",
"\n",
"close",
"(",
"d",
".",
"current",
".",
"cancel",
")",
"\n",
"d",
".",
"curr... | // drainOutput will drain the output until errEndOfStream is sent. | [
"drainOutput",
"will",
"drain",
"the",
"output",
"until",
"errEndOfStream",
"is",
"sent",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/decoder.go#L176-L206 |
8,388 | klauspost/compress | zstd/decoder.go | WriteTo | func (d *Decoder) WriteTo(w io.Writer) (int64, error) {
if d.stream == nil {
return 0, errors.New("no input has been initialized")
}
var n int64
for d.current.err == nil {
if len(d.current.b) > 0 {
n2, err2 := w.Write(d.current.b)
n += int64(n2)
if err2 != nil && d.current.err == nil {
d.current.err = err2
break
}
}
d.nextBlock()
}
err := d.current.err
if err != nil {
d.drainOutput()
}
if err == io.EOF {
err = nil
}
return n, err
} | go | func (d *Decoder) WriteTo(w io.Writer) (int64, error) {
if d.stream == nil {
return 0, errors.New("no input has been initialized")
}
var n int64
for d.current.err == nil {
if len(d.current.b) > 0 {
n2, err2 := w.Write(d.current.b)
n += int64(n2)
if err2 != nil && d.current.err == nil {
d.current.err = err2
break
}
}
d.nextBlock()
}
err := d.current.err
if err != nil {
d.drainOutput()
}
if err == io.EOF {
err = nil
}
return n, err
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"d",
".",
"stream",
"==",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",... | // WriteTo writes data to w until there's no more data to write or when an error occurs.
// The return value n is the number of bytes written.
// Any error encountered during the write is also returned. | [
"WriteTo",
"writes",
"data",
"to",
"w",
"until",
"there",
"s",
"no",
"more",
"data",
"to",
"write",
"or",
"when",
"an",
"error",
"occurs",
".",
"The",
"return",
"value",
"n",
"is",
"the",
"number",
"of",
"bytes",
"written",
".",
"Any",
"error",
"encoun... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/decoder.go#L211-L235 |
8,389 | klauspost/compress | zstd/decoder.go | DecodeAll | func (d *Decoder) DecodeAll(input, dst []byte) ([]byte, error) {
if d.current.err == ErrDecoderClosed {
return dst, ErrDecoderClosed
}
//println(len(d.frames), len(d.decoders), d.current)
block, frame := <-d.decoders, <-d.frames
defer func() {
d.decoders <- block
frame.rawInput = nil
d.frames <- frame
}()
if cap(dst) == 0 {
// Allocate 1MB by default.
dst = make([]byte, 0, 1<<20)
}
br := byteBuf(input)
for {
err := frame.reset(&br)
if err == io.EOF {
return dst, nil
}
if err != nil {
return dst, err
}
if frame.FrameContentSize > d.o.maxDecodedSize-uint64(len(dst)) {
return dst, ErrDecoderSizeExceeded
}
if frame.FrameContentSize > 0 && frame.FrameContentSize < 1<<30 {
// Never preallocate moe than 1 GB up front.
if uint64(cap(dst)) < frame.FrameContentSize {
dst2 := make([]byte, len(dst), len(dst)+int(frame.FrameContentSize))
copy(dst2, dst)
dst = dst2
}
}
dst, err = frame.runDecoder(dst, block)
if err != nil {
return dst, err
}
if len(br) == 0 {
break
}
}
return dst, nil
} | go | func (d *Decoder) DecodeAll(input, dst []byte) ([]byte, error) {
if d.current.err == ErrDecoderClosed {
return dst, ErrDecoderClosed
}
//println(len(d.frames), len(d.decoders), d.current)
block, frame := <-d.decoders, <-d.frames
defer func() {
d.decoders <- block
frame.rawInput = nil
d.frames <- frame
}()
if cap(dst) == 0 {
// Allocate 1MB by default.
dst = make([]byte, 0, 1<<20)
}
br := byteBuf(input)
for {
err := frame.reset(&br)
if err == io.EOF {
return dst, nil
}
if err != nil {
return dst, err
}
if frame.FrameContentSize > d.o.maxDecodedSize-uint64(len(dst)) {
return dst, ErrDecoderSizeExceeded
}
if frame.FrameContentSize > 0 && frame.FrameContentSize < 1<<30 {
// Never preallocate moe than 1 GB up front.
if uint64(cap(dst)) < frame.FrameContentSize {
dst2 := make([]byte, len(dst), len(dst)+int(frame.FrameContentSize))
copy(dst2, dst)
dst = dst2
}
}
dst, err = frame.runDecoder(dst, block)
if err != nil {
return dst, err
}
if len(br) == 0 {
break
}
}
return dst, nil
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"DecodeAll",
"(",
"input",
",",
"dst",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"d",
".",
"current",
".",
"err",
"==",
"ErrDecoderClosed",
"{",
"return",
"dst",
",",
"ErrDe... | // DecodeAll allows stateless decoding of a blob of bytes.
// Output will be appended to dst, so if the destination size is known
// you can pre-allocate the destination slice to avoid allocations.
// DecodeAll can be used concurrently.
// The Decoder concurrency limits will be respected. | [
"DecodeAll",
"allows",
"stateless",
"decoding",
"of",
"a",
"blob",
"of",
"bytes",
".",
"Output",
"will",
"be",
"appended",
"to",
"dst",
"so",
"if",
"the",
"destination",
"size",
"is",
"known",
"you",
"can",
"pre",
"-",
"allocate",
"the",
"destination",
"sl... | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/decoder.go#L242-L286 |
8,390 | klauspost/compress | zstd/decoder.go | nextBlock | func (d *Decoder) nextBlock() {
if d.current.d != nil {
d.decoders <- d.current.d
d.current.d = nil
}
if d.current.err != nil {
// Keep error state.
return
}
d.current.decodeOutput = <-d.current.output
if debug {
println("got", len(d.current.b), "bytes, error:", d.current.err)
}
} | go | func (d *Decoder) nextBlock() {
if d.current.d != nil {
d.decoders <- d.current.d
d.current.d = nil
}
if d.current.err != nil {
// Keep error state.
return
}
d.current.decodeOutput = <-d.current.output
if debug {
println("got", len(d.current.b), "bytes, error:", d.current.err)
}
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"nextBlock",
"(",
")",
"{",
"if",
"d",
".",
"current",
".",
"d",
"!=",
"nil",
"{",
"d",
".",
"decoders",
"<-",
"d",
".",
"current",
".",
"d",
"\n",
"d",
".",
"current",
".",
"d",
"=",
"nil",
"\n",
"}",
... | // nextBlock returns the next block.
// If an error occurs d.err will be set. | [
"nextBlock",
"returns",
"the",
"next",
"block",
".",
"If",
"an",
"error",
"occurs",
"d",
".",
"err",
"will",
"be",
"set",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/decoder.go#L290-L303 |
8,391 | klauspost/compress | zstd/decoder.go | Close | func (d *Decoder) Close() {
if d.current.err == ErrDecoderClosed {
return
}
d.drainOutput()
if d.stream != nil {
close(d.stream)
d.streamWg.Wait()
d.stream = nil
}
if d.decoders != nil {
close(d.decoders)
for dec := range d.decoders {
dec.Close()
}
d.decoders = nil
}
if d.current.d != nil {
d.current.d.Close()
d.current.d = nil
}
d.current.err = ErrDecoderClosed
} | go | func (d *Decoder) Close() {
if d.current.err == ErrDecoderClosed {
return
}
d.drainOutput()
if d.stream != nil {
close(d.stream)
d.streamWg.Wait()
d.stream = nil
}
if d.decoders != nil {
close(d.decoders)
for dec := range d.decoders {
dec.Close()
}
d.decoders = nil
}
if d.current.d != nil {
d.current.d.Close()
d.current.d = nil
}
d.current.err = ErrDecoderClosed
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"Close",
"(",
")",
"{",
"if",
"d",
".",
"current",
".",
"err",
"==",
"ErrDecoderClosed",
"{",
"return",
"\n",
"}",
"\n",
"d",
".",
"drainOutput",
"(",
")",
"\n",
"if",
"d",
".",
"stream",
"!=",
"nil",
"{",
... | // Close will release all resources.
// It is NOT possible to reuse the decoder after this. | [
"Close",
"will",
"release",
"all",
"resources",
".",
"It",
"is",
"NOT",
"possible",
"to",
"reuse",
"the",
"decoder",
"after",
"this",
"."
] | ae52aff18558bd92cbe681549bfe9e8cbffd5903 | https://github.com/klauspost/compress/blob/ae52aff18558bd92cbe681549bfe9e8cbffd5903/zstd/decoder.go#L307-L329 |
8,392 | go-gl/gl | v4.3-compatibility/gl/package.go | BeginConditionalRender | func BeginConditionalRender(id uint32, mode uint32) {
C.glowBeginConditionalRender(gpBeginConditionalRender, (C.GLuint)(id), (C.GLenum)(mode))
} | go | func BeginConditionalRender(id uint32, mode uint32) {
C.glowBeginConditionalRender(gpBeginConditionalRender, (C.GLuint)(id), (C.GLenum)(mode))
} | [
"func",
"BeginConditionalRender",
"(",
"id",
"uint32",
",",
"mode",
"uint32",
")",
"{",
"C",
".",
"glowBeginConditionalRender",
"(",
"gpBeginConditionalRender",
",",
"(",
"C",
".",
"GLuint",
")",
"(",
"id",
")",
",",
"(",
"C",
".",
"GLenum",
")",
"(",
"m... | // start conditional rendering | [
"start",
"conditional",
"rendering"
] | bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587 | https://github.com/go-gl/gl/blob/bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587/v4.3-compatibility/gl/package.go#L19819-L19821 |
8,393 | go-gl/gl | v4.3-compatibility/gl/package.go | BindFragDataLocation | func BindFragDataLocation(program uint32, color uint32, name *uint8) {
C.glowBindFragDataLocation(gpBindFragDataLocation, (C.GLuint)(program), (C.GLuint)(color), (*C.GLchar)(unsafe.Pointer(name)))
} | go | func BindFragDataLocation(program uint32, color uint32, name *uint8) {
C.glowBindFragDataLocation(gpBindFragDataLocation, (C.GLuint)(program), (C.GLuint)(color), (*C.GLchar)(unsafe.Pointer(name)))
} | [
"func",
"BindFragDataLocation",
"(",
"program",
"uint32",
",",
"color",
"uint32",
",",
"name",
"*",
"uint8",
")",
"{",
"C",
".",
"glowBindFragDataLocation",
"(",
"gpBindFragDataLocation",
",",
"(",
"C",
".",
"GLuint",
")",
"(",
"program",
")",
",",
"(",
"C... | // bind a user-defined varying out variable to a fragment shader color number | [
"bind",
"a",
"user",
"-",
"defined",
"varying",
"out",
"variable",
"to",
"a",
"fragment",
"shader",
"color",
"number"
] | bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587 | https://github.com/go-gl/gl/blob/bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587/v4.3-compatibility/gl/package.go#L19924-L19926 |
8,394 | go-gl/gl | v4.3-compatibility/gl/package.go | ClampColor | func ClampColor(target uint32, clamp uint32) {
C.glowClampColor(gpClampColor, (C.GLenum)(target), (C.GLenum)(clamp))
} | go | func ClampColor(target uint32, clamp uint32) {
C.glowClampColor(gpClampColor, (C.GLenum)(target), (C.GLenum)(clamp))
} | [
"func",
"ClampColor",
"(",
"target",
"uint32",
",",
"clamp",
"uint32",
")",
"{",
"C",
".",
"glowClampColor",
"(",
"gpClampColor",
",",
"(",
"C",
".",
"GLenum",
")",
"(",
"target",
")",
",",
"(",
"C",
".",
"GLenum",
")",
"(",
"clamp",
")",
")",
"\n"... | // specify whether data read via should be clamped | [
"specify",
"whether",
"data",
"read",
"via",
"should",
"be",
"clamped"
] | bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587 | https://github.com/go-gl/gl/blob/bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587/v4.3-compatibility/gl/package.go#L20282-L20284 |
8,395 | go-gl/gl | v4.3-compatibility/gl/package.go | ColorTable | func ColorTable(target uint32, internalformat uint32, width int32, format uint32, xtype uint32, table unsafe.Pointer) {
C.glowColorTable(gpColorTable, (C.GLenum)(target), (C.GLenum)(internalformat), (C.GLsizei)(width), (C.GLenum)(format), (C.GLenum)(xtype), table)
} | go | func ColorTable(target uint32, internalformat uint32, width int32, format uint32, xtype uint32, table unsafe.Pointer) {
C.glowColorTable(gpColorTable, (C.GLenum)(target), (C.GLenum)(internalformat), (C.GLsizei)(width), (C.GLenum)(format), (C.GLenum)(xtype), table)
} | [
"func",
"ColorTable",
"(",
"target",
"uint32",
",",
"internalformat",
"uint32",
",",
"width",
"int32",
",",
"format",
"uint32",
",",
"xtype",
"uint32",
",",
"table",
"unsafe",
".",
"Pointer",
")",
"{",
"C",
".",
"glowColorTable",
"(",
"gpColorTable",
",",
... | // define a color lookup table | [
"define",
"a",
"color",
"lookup",
"table"
] | bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587 | https://github.com/go-gl/gl/blob/bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587/v4.3-compatibility/gl/package.go#L20646-L20648 |
8,396 | go-gl/gl | v4.3-compatibility/gl/package.go | ConvolutionFilter1D | func ConvolutionFilter1D(target uint32, internalformat uint32, width int32, format uint32, xtype uint32, image unsafe.Pointer) {
C.glowConvolutionFilter1D(gpConvolutionFilter1D, (C.GLenum)(target), (C.GLenum)(internalformat), (C.GLsizei)(width), (C.GLenum)(format), (C.GLenum)(xtype), image)
} | go | func ConvolutionFilter1D(target uint32, internalformat uint32, width int32, format uint32, xtype uint32, image unsafe.Pointer) {
C.glowConvolutionFilter1D(gpConvolutionFilter1D, (C.GLenum)(target), (C.GLenum)(internalformat), (C.GLsizei)(width), (C.GLenum)(format), (C.GLenum)(xtype), image)
} | [
"func",
"ConvolutionFilter1D",
"(",
"target",
"uint32",
",",
"internalformat",
"uint32",
",",
"width",
"int32",
",",
"format",
"uint32",
",",
"xtype",
"uint32",
",",
"image",
"unsafe",
".",
"Pointer",
")",
"{",
"C",
".",
"glowConvolutionFilter1D",
"(",
"gpConv... | // define a one-dimensional convolution filter | [
"define",
"a",
"one",
"-",
"dimensional",
"convolution",
"filter"
] | bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587 | https://github.com/go-gl/gl/blob/bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587/v4.3-compatibility/gl/package.go#L20812-L20814 |
8,397 | go-gl/gl | v4.3-compatibility/gl/package.go | ConvolutionFilter2D | func ConvolutionFilter2D(target uint32, internalformat uint32, width int32, height int32, format uint32, xtype uint32, image unsafe.Pointer) {
C.glowConvolutionFilter2D(gpConvolutionFilter2D, (C.GLenum)(target), (C.GLenum)(internalformat), (C.GLsizei)(width), (C.GLsizei)(height), (C.GLenum)(format), (C.GLenum)(xtype), image)
} | go | func ConvolutionFilter2D(target uint32, internalformat uint32, width int32, height int32, format uint32, xtype uint32, image unsafe.Pointer) {
C.glowConvolutionFilter2D(gpConvolutionFilter2D, (C.GLenum)(target), (C.GLenum)(internalformat), (C.GLsizei)(width), (C.GLsizei)(height), (C.GLenum)(format), (C.GLenum)(xtype), image)
} | [
"func",
"ConvolutionFilter2D",
"(",
"target",
"uint32",
",",
"internalformat",
"uint32",
",",
"width",
"int32",
",",
"height",
"int32",
",",
"format",
"uint32",
",",
"xtype",
"uint32",
",",
"image",
"unsafe",
".",
"Pointer",
")",
"{",
"C",
".",
"glowConvolut... | // define a two-dimensional convolution filter | [
"define",
"a",
"two",
"-",
"dimensional",
"convolution",
"filter"
] | bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587 | https://github.com/go-gl/gl/blob/bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587/v4.3-compatibility/gl/package.go#L20820-L20822 |
8,398 | go-gl/gl | v4.3-compatibility/gl/package.go | CopyColorTable | func CopyColorTable(target uint32, internalformat uint32, x int32, y int32, width int32) {
C.glowCopyColorTable(gpCopyColorTable, (C.GLenum)(target), (C.GLenum)(internalformat), (C.GLint)(x), (C.GLint)(y), (C.GLsizei)(width))
} | go | func CopyColorTable(target uint32, internalformat uint32, x int32, y int32, width int32) {
C.glowCopyColorTable(gpCopyColorTable, (C.GLenum)(target), (C.GLenum)(internalformat), (C.GLint)(x), (C.GLint)(y), (C.GLsizei)(width))
} | [
"func",
"CopyColorTable",
"(",
"target",
"uint32",
",",
"internalformat",
"uint32",
",",
"x",
"int32",
",",
"y",
"int32",
",",
"width",
"int32",
")",
"{",
"C",
".",
"glowCopyColorTable",
"(",
"gpCopyColorTable",
",",
"(",
"C",
".",
"GLenum",
")",
"(",
"t... | // copy pixels into a color table | [
"copy",
"pixels",
"into",
"a",
"color",
"table"
] | bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587 | https://github.com/go-gl/gl/blob/bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587/v4.3-compatibility/gl/package.go#L20871-L20873 |
8,399 | go-gl/gl | v4.3-compatibility/gl/package.go | CopyConvolutionFilter1D | func CopyConvolutionFilter1D(target uint32, internalformat uint32, x int32, y int32, width int32) {
C.glowCopyConvolutionFilter1D(gpCopyConvolutionFilter1D, (C.GLenum)(target), (C.GLenum)(internalformat), (C.GLint)(x), (C.GLint)(y), (C.GLsizei)(width))
} | go | func CopyConvolutionFilter1D(target uint32, internalformat uint32, x int32, y int32, width int32) {
C.glowCopyConvolutionFilter1D(gpCopyConvolutionFilter1D, (C.GLenum)(target), (C.GLenum)(internalformat), (C.GLint)(x), (C.GLint)(y), (C.GLsizei)(width))
} | [
"func",
"CopyConvolutionFilter1D",
"(",
"target",
"uint32",
",",
"internalformat",
"uint32",
",",
"x",
"int32",
",",
"y",
"int32",
",",
"width",
"int32",
")",
"{",
"C",
".",
"glowCopyConvolutionFilter1D",
"(",
"gpCopyConvolutionFilter1D",
",",
"(",
"C",
".",
"... | // copy pixels into a one-dimensional convolution filter | [
"copy",
"pixels",
"into",
"a",
"one",
"-",
"dimensional",
"convolution",
"filter"
] | bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587 | https://github.com/go-gl/gl/blob/bf2b1f2f34d7f6a60a99a830f65dcd6afb0c6587/v4.3-compatibility/gl/package.go#L20879-L20881 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.