mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Run gofmt
This commit is contained in:
1 parent
315b2e5262
commit
be1f605108
9 files changed
+378
-372
No files matched your search
+14
-14
@@ -35,20 +35,20 @@
|
||||
// To quantify "much faster", on this one C file, this program was 80 times
|
||||
// faster than `clang-format`, even without a column limit:
|
||||
//
|
||||
// $ wc release/c/wuffs-v0.2.c
|
||||
// 11858 35980 431885 release/c/wuffs-v0.2.c
|
||||
// $ time dumbindent < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.008s
|
||||
// user 0m0.005s
|
||||
// sys 0m0.005s
|
||||
// $ time clang-format-9 < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.668s
|
||||
// user 0m0.618s
|
||||
// sys 0m0.032s
|
||||
// $ time clang-format-9 -style='{ColumnLimit: 0}' < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.641s
|
||||
// user 0m0.585s
|
||||
// sys 0m0.037s
|
||||
// $ wc release/c/wuffs-v0.2.c
|
||||
// 11858 35980 431885 release/c/wuffs-v0.2.c
|
||||
// $ time dumbindent < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.008s
|
||||
// user 0m0.005s
|
||||
// sys 0m0.005s
|
||||
// $ time clang-format-9 < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.668s
|
||||
// user 0m0.618s
|
||||
// sys 0m0.032s
|
||||
// $ time clang-format-9 -style='{ColumnLimit: 0}' < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.641s
|
||||
// user 0m0.585s
|
||||
// sys 0m0.037s
|
||||
//
|
||||
// More commentary is at:
|
||||
// https://godoc.org/github.com/google/wuffs/lib/dumbindent
|
||||
|
||||
+137
-137
@@ -33,7 +33,7 @@ https://github.com/google/wuffs/blob/main/doc/spec/rac-spec.md
|
||||
|
||||
Usage:
|
||||
|
||||
ractool [flags] [input_filename]
|
||||
ractool [flags] [input_filename]
|
||||
|
||||
If no input_filename is given, stdin is used. Either way, output is written to
|
||||
stdout.
|
||||
@@ -63,10 +63,10 @@ or temporary disk space.
|
||||
|
||||
Examples:
|
||||
|
||||
ractool -decode foo.rac | sha256sum
|
||||
ractool -decode -drange=400..500 foo.rac
|
||||
ractool -encode foo.dat > foo.rac
|
||||
ractool -encode -codec=zlib -dchunksize=256k foo.dat > foo.rac
|
||||
ractool -decode foo.rac | sha256sum
|
||||
ractool -decode -drange=400..500 foo.rac
|
||||
ractool -encode foo.dat > foo.rac
|
||||
ractool -encode -codec=zlib -dchunksize=256k foo.dat > foo.rac
|
||||
|
||||
The "400..500" flag value means the 100 bytes ranging from a DSpace offset
|
||||
(offset in terms of decompressed bytes, not compressed bytes) of 400
|
||||
@@ -79,42 +79,42 @@ Similarly, "1m" and "1M" both mean 1 mebibyte (1048576 bytes).
|
||||
|
||||
General Flags:
|
||||
|
||||
-decode
|
||||
whether to decode the input
|
||||
-encode
|
||||
whether to encode the input
|
||||
-quiet
|
||||
whether to suppress messages
|
||||
-decode
|
||||
whether to decode the input
|
||||
-encode
|
||||
whether to encode the input
|
||||
-quiet
|
||||
whether to suppress messages
|
||||
|
||||
Decode-Related Flags:
|
||||
|
||||
-drange
|
||||
the "i..j" range to decompress, "..8" means the first 8 bytes
|
||||
-singlethreaded
|
||||
whether to decode on a single execution thread
|
||||
-drange
|
||||
the "i..j" range to decompress, "..8" means the first 8 bytes
|
||||
-singlethreaded
|
||||
whether to decode on a single execution thread
|
||||
|
||||
Encode-Related Flags:
|
||||
|
||||
-cchunksize
|
||||
the chunk size (in CSpace)
|
||||
-codec
|
||||
the compression codec (default "zstd")
|
||||
-cpagesize
|
||||
the page size (in CSpace)
|
||||
-dchunksize
|
||||
the chunk size (in DSpace)
|
||||
-indexlocation
|
||||
the index location, "start" or "end" (default "start")
|
||||
-resources
|
||||
comma-separated list of resource files, such as shared dictionaries
|
||||
-tmpdir
|
||||
directory (e.g. $TMPDIR) for intermediate work; empty means in-memory
|
||||
-cchunksize
|
||||
the chunk size (in CSpace)
|
||||
-codec
|
||||
the compression codec (default "zstd")
|
||||
-cpagesize
|
||||
the page size (in CSpace)
|
||||
-dchunksize
|
||||
the chunk size (in DSpace)
|
||||
-indexlocation
|
||||
the index location, "start" or "end" (default "start")
|
||||
-resources
|
||||
comma-separated list of resource files, such as shared dictionaries
|
||||
-tmpdir
|
||||
directory (e.g. $TMPDIR) for intermediate work; empty means in-memory
|
||||
|
||||
Codecs:
|
||||
|
||||
lz4
|
||||
zlib
|
||||
zstd
|
||||
lz4
|
||||
zlib
|
||||
zstd
|
||||
|
||||
Only zlib is fully supported. The others will work for the flags' default
|
||||
values, but they (1) don't support -cchunksize, only -dchunksize, and (2) don't
|
||||
@@ -125,123 +125,123 @@ Installation:
|
||||
|
||||
Like any other implemented-in-Go program, to install the ractool program:
|
||||
|
||||
go install github.com/google/wuffs/cmd/ractool
|
||||
go install github.com/google/wuffs/cmd/ractool
|
||||
|
||||
Extended Example:
|
||||
|
||||
--------
|
||||
$ # Fetch and unzip the enwik8 test file, a sample of Wikipedia.
|
||||
$ wget http://mattmahoney.net/dc/enwik8.zip
|
||||
$ unzip enwik8.zip
|
||||
--------
|
||||
$ # Fetch and unzip the enwik8 test file, a sample of Wikipedia.
|
||||
$ wget http://mattmahoney.net/dc/enwik8.zip
|
||||
$ unzip enwik8.zip
|
||||
|
||||
$ # Also zstd-encode it, as a reference point. Using compression level 15,
|
||||
$ # instead of the default of 3, matches what ractool uses.
|
||||
$ zstd -15 enwik8
|
||||
$ # Also zstd-encode it, as a reference point. Using compression level 15,
|
||||
$ # instead of the default of 3, matches what ractool uses.
|
||||
$ zstd -15 enwik8
|
||||
|
||||
$ # Create a shared dictionary. Using zstd-the-program produces a
|
||||
$ # dictionary that is especially useful for zstd-the-format, but it can
|
||||
$ # also be used by other formats as a 'raw' prefix dictionary.
|
||||
$ zstd -15 --train -B64K --maxdict=32K -o dict.dat enwik8
|
||||
$ # Create a shared dictionary. Using zstd-the-program produces a
|
||||
$ # dictionary that is especially useful for zstd-the-format, but it can
|
||||
$ # also be used by other formats as a 'raw' prefix dictionary.
|
||||
$ zstd -15 --train -B64K --maxdict=32K -o dict.dat enwik8
|
||||
|
||||
$ # RAC-encode it with various codecs, with and without that dictionary.
|
||||
$ ractool -encode -codec=zlib -resources=dict.dat enwik8 > zlib.withdict.rac
|
||||
$ ractool -encode -codec=zlib enwik8 > zlib.sansdict.rac
|
||||
$ ractool -encode -codec=zstd -resources=dict.dat enwik8 > zstd.withdict.rac
|
||||
$ ractool -encode -codec=zstd enwik8 > zstd.sansdict.rac
|
||||
$ ractool -encode -codec=lz4 enwik8 > lz4.sansdict.rac
|
||||
$ # RAC-encode it with various codecs, with and without that dictionary.
|
||||
$ ractool -encode -codec=zlib -resources=dict.dat enwik8 > zlib.withdict.rac
|
||||
$ ractool -encode -codec=zlib enwik8 > zlib.sansdict.rac
|
||||
$ ractool -encode -codec=zstd -resources=dict.dat enwik8 > zstd.withdict.rac
|
||||
$ ractool -encode -codec=zstd enwik8 > zstd.sansdict.rac
|
||||
$ ractool -encode -codec=lz4 enwik8 > lz4.sansdict.rac
|
||||
|
||||
$ # The size overhead (comparing RAC+Xxx to Xxx) is about 0.2% (with) or
|
||||
$ # 4.8% (sans) for zlib/zip and about 13% (with) or 28% (sans) for zstd,
|
||||
$ # depending on whether we used a shared dictionary (with or sans).
|
||||
$ ls -l
|
||||
total 362080
|
||||
-rw-r----- 1 tao tao 32768 Oct 25 10:10 dict.dat
|
||||
-rw-r----- 1 tao tao 100000000 Jun 2 2011 enwik8
|
||||
-rw-r----- 1 tao tao 36445475 Sep 2 2011 enwik8.zip
|
||||
-rw-r----- 1 tao tao 29563109 Jun 2 2011 enwik8.zst
|
||||
-rw-r----- 1 tao tao 58813316 Oct 25 10:17 lz4.sansdict.rac
|
||||
-rw-r----- 1 tao tao 38185178 Oct 25 10:16 zlib.sansdict.rac
|
||||
-rw-r----- 1 tao tao 36505786 Oct 25 10:16 zlib.withdict.rac
|
||||
-rw-r----- 1 tao tao 37820491 Oct 25 10:17 zstd.sansdict.rac
|
||||
-rw-r----- 1 tao tao 33386395 Oct 25 10:17 zstd.withdict.rac
|
||||
$ # The size overhead (comparing RAC+Xxx to Xxx) is about 0.2% (with) or
|
||||
$ # 4.8% (sans) for zlib/zip and about 13% (with) or 28% (sans) for zstd,
|
||||
$ # depending on whether we used a shared dictionary (with or sans).
|
||||
$ ls -l
|
||||
total 362080
|
||||
-rw-r----- 1 tao tao 32768 Oct 25 10:10 dict.dat
|
||||
-rw-r----- 1 tao tao 100000000 Jun 2 2011 enwik8
|
||||
-rw-r----- 1 tao tao 36445475 Sep 2 2011 enwik8.zip
|
||||
-rw-r----- 1 tao tao 29563109 Jun 2 2011 enwik8.zst
|
||||
-rw-r----- 1 tao tao 58813316 Oct 25 10:17 lz4.sansdict.rac
|
||||
-rw-r----- 1 tao tao 38185178 Oct 25 10:16 zlib.sansdict.rac
|
||||
-rw-r----- 1 tao tao 36505786 Oct 25 10:16 zlib.withdict.rac
|
||||
-rw-r----- 1 tao tao 37820491 Oct 25 10:17 zstd.sansdict.rac
|
||||
-rw-r----- 1 tao tao 33386395 Oct 25 10:17 zstd.withdict.rac
|
||||
|
||||
$ # Check that the decompressed forms all match.
|
||||
$ cat enwik8 | sha256sum
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ unzip -p enwik8.zip | sha256sum
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ unzstd --stdout enwik8.zst | sha256sum
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ for f in *.rac; do ractool -decode $f | sha256sum; done
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ # Check that the decompressed forms all match.
|
||||
$ cat enwik8 | sha256sum
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ unzip -p enwik8.zip | sha256sum
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ unzstd --stdout enwik8.zst | sha256sum
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
$ for f in *.rac; do ractool -decode $f | sha256sum; done
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
|
||||
|
||||
$ # Compare how long it takes to produce 8 bytes from the middle of
|
||||
$ # the decompressed file, which happens to be the word "Business".
|
||||
$ time unzip -p enwik8.zip | dd if=/dev/stdin status=none \
|
||||
> iflag=skip_bytes,count_bytes skip=50000000 count=8
|
||||
Business
|
||||
real 0m0.379s
|
||||
user 0m0.410s
|
||||
sys 0m0.080s
|
||||
$ time unzstd --stdout enwik8.zst | dd if=/dev/stdin status=none \
|
||||
> iflag=skip_bytes,count_bytes skip=50000000 count=8
|
||||
Business
|
||||
real 0m0.172s
|
||||
user 0m0.141s
|
||||
sys 0m0.103s
|
||||
$ time ractool -decode -drange=50000000..50000008 zstd.withdict.rac
|
||||
Business
|
||||
real 0m0.004s
|
||||
user 0m0.005s
|
||||
sys 0m0.001s
|
||||
$ # Compare how long it takes to produce 8 bytes from the middle of
|
||||
$ # the decompressed file, which happens to be the word "Business".
|
||||
$ time unzip -p enwik8.zip | dd if=/dev/stdin status=none \
|
||||
> iflag=skip_bytes,count_bytes skip=50000000 count=8
|
||||
Business
|
||||
real 0m0.379s
|
||||
user 0m0.410s
|
||||
sys 0m0.080s
|
||||
$ time unzstd --stdout enwik8.zst | dd if=/dev/stdin status=none \
|
||||
> iflag=skip_bytes,count_bytes skip=50000000 count=8
|
||||
Business
|
||||
real 0m0.172s
|
||||
user 0m0.141s
|
||||
sys 0m0.103s
|
||||
$ time ractool -decode -drange=50000000..50000008 zstd.withdict.rac
|
||||
Business
|
||||
real 0m0.004s
|
||||
user 0m0.005s
|
||||
sys 0m0.001s
|
||||
|
||||
$ # A RAC file's chunks can be decoded in parallel, unlike ZIP,
|
||||
$ # substantially reducing the real (wall clock) time taken even
|
||||
$ # though both of these files use DEFLATE (RFC 1951) compression.
|
||||
$ #
|
||||
$ # Comparing the -singlethreaded time suggests that zlib-the-library's
|
||||
$ # DEFLATE implementation is faster than unzip's.
|
||||
$ time unzip -p enwik8.zip > /dev/null
|
||||
real 0m0.711s
|
||||
user 0m0.690s
|
||||
sys 0m0.021s
|
||||
$ time ractool -decode -singlethreaded zlib.withdict.rac > /dev/null
|
||||
real 0m0.519s
|
||||
user 0m0.513s
|
||||
sys 0m0.017s
|
||||
$ time ractool -decode zlib.withdict.rac > /dev/null
|
||||
real 0m0.052s
|
||||
user 0m0.678s
|
||||
sys 0m0.036s
|
||||
$ # A RAC file's chunks can be decoded in parallel, unlike ZIP,
|
||||
$ # substantially reducing the real (wall clock) time taken even
|
||||
$ # though both of these files use DEFLATE (RFC 1951) compression.
|
||||
$ #
|
||||
$ # Comparing the -singlethreaded time suggests that zlib-the-library's
|
||||
$ # DEFLATE implementation is faster than unzip's.
|
||||
$ time unzip -p enwik8.zip > /dev/null
|
||||
real 0m0.711s
|
||||
user 0m0.690s
|
||||
sys 0m0.021s
|
||||
$ time ractool -decode -singlethreaded zlib.withdict.rac > /dev/null
|
||||
real 0m0.519s
|
||||
user 0m0.513s
|
||||
sys 0m0.017s
|
||||
$ time ractool -decode zlib.withdict.rac > /dev/null
|
||||
real 0m0.052s
|
||||
user 0m0.678s
|
||||
sys 0m0.036s
|
||||
|
||||
$ # A similar comparison can be made for Zstandard.
|
||||
$ time unzstd --stdout enwik8.zst > /dev/null
|
||||
real 0m0.203s
|
||||
user 0m0.187s
|
||||
sys 0m0.016s
|
||||
$ time ractool -decode -singlethreaded zstd.withdict.rac > /dev/null
|
||||
real 0m0.235s
|
||||
user 0m0.206s
|
||||
sys 0m0.033s
|
||||
$ time ractool -decode zstd.withdict.rac > /dev/null
|
||||
real 0m0.037s
|
||||
user 0m0.374s
|
||||
sys 0m0.080s
|
||||
$ # A similar comparison can be made for Zstandard.
|
||||
$ time unzstd --stdout enwik8.zst > /dev/null
|
||||
real 0m0.203s
|
||||
user 0m0.187s
|
||||
sys 0m0.016s
|
||||
$ time ractool -decode -singlethreaded zstd.withdict.rac > /dev/null
|
||||
real 0m0.235s
|
||||
user 0m0.206s
|
||||
sys 0m0.033s
|
||||
$ time ractool -decode zstd.withdict.rac > /dev/null
|
||||
real 0m0.037s
|
||||
user 0m0.374s
|
||||
sys 0m0.080s
|
||||
|
||||
$ # For reference, LZ4 numbers.
|
||||
$ time ractool -decode -singlethreaded lz4.sansdict.rac > /dev/null
|
||||
real 0m0.072s
|
||||
user 0m0.053s
|
||||
sys 0m0.021s
|
||||
$ time ractool -decode lz4.sansdict.rac > /dev/null
|
||||
real 0m0.024s
|
||||
user 0m0.097s
|
||||
sys 0m0.034s
|
||||
--------
|
||||
$ # For reference, LZ4 numbers.
|
||||
$ time ractool -decode -singlethreaded lz4.sansdict.rac > /dev/null
|
||||
real 0m0.072s
|
||||
user 0m0.053s
|
||||
sys 0m0.021s
|
||||
$ time ractool -decode lz4.sansdict.rac > /dev/null
|
||||
real 0m0.024s
|
||||
user 0m0.097s
|
||||
sys 0m0.034s
|
||||
--------
|
||||
*/
|
||||
package main
|
||||
|
||||
|
||||
+82
-82
@@ -328,12 +328,12 @@ func (n *Raw) SetPackage(tm *t.Map, pkg t.ID) error {
|
||||
const MaxExprDepth = 255
|
||||
|
||||
// Expr is an expression, such as "i", "+j" or "k + l[m(n, o)].p":
|
||||
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDDotDot|IDDot>
|
||||
// - ID2: <0|literal|ident>
|
||||
// - LHS: <nil|Expr>
|
||||
// - MHS: <nil|Expr>
|
||||
// - RHS: <nil|Expr|TypeExpr>
|
||||
// - List0: <Arg|Expr> function call args, assoc. op args or list members.
|
||||
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDDotDot|IDDot>
|
||||
// - ID2: <0|literal|ident>
|
||||
// - LHS: <nil|Expr>
|
||||
// - MHS: <nil|Expr>
|
||||
// - RHS: <nil|Expr|TypeExpr>
|
||||
// - List0: <Arg|Expr> function call args, assoc. op args or list members.
|
||||
//
|
||||
// A zero ID0 means an identifier or literal in ID2, like `foo`, `42` or a
|
||||
// status literal like `"#foo"`.
|
||||
@@ -468,10 +468,10 @@ func NewExpr(flags Flags, operator t.ID, ident t.ID, lhs *Node, mhs *Node, rhs *
|
||||
|
||||
// Assert is "assert RHS via ID2(args)", "choose etc", "pre etc", "inv etc" or
|
||||
// "post etc":
|
||||
// - ID0: <IDAssert|IDChoose|IDPre|IDInv|IDPost>
|
||||
// - ID2: <"-string literal> reason
|
||||
// - RHS: <Expr>
|
||||
// - List0: <Arg> reason arguments
|
||||
// - ID0: <IDAssert|IDChoose|IDPre|IDInv|IDPost>
|
||||
// - ID2: <"-string literal> reason
|
||||
// - RHS: <Expr>
|
||||
// - List0: <Arg> reason arguments
|
||||
type Assert Node
|
||||
|
||||
func (n *Assert) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -513,8 +513,8 @@ func NewAssert(keyword t.ID, condition *Expr, reason t.ID, args []*Node) *Assert
|
||||
}
|
||||
|
||||
// Arg is "name:value".
|
||||
// - ID2: <ident> name
|
||||
// - RHS: <Expr> value
|
||||
// - ID2: <ident> name
|
||||
// - RHS: <Expr> value
|
||||
type Arg Node
|
||||
|
||||
func (n *Arg) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -530,9 +530,9 @@ func NewArg(name t.ID, value *Expr) *Arg {
|
||||
}
|
||||
|
||||
// Assign is "LHS = RHS" or "LHS op= RHS" or "RHS":
|
||||
// - ID0: operator
|
||||
// - LHS: <nil|Expr>
|
||||
// - RHS: <Expr>
|
||||
// - ID0: operator
|
||||
// - LHS: <nil|Expr>
|
||||
// - RHS: <Expr>
|
||||
type Assign Node
|
||||
|
||||
func (n *Assign) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -550,8 +550,8 @@ func NewAssign(operator t.ID, lhs *Expr, rhs *Expr) *Assign {
|
||||
}
|
||||
|
||||
// Var is "var ID2 LHS":
|
||||
// - ID2: name
|
||||
// - LHS: <TypeExpr>
|
||||
// - ID2: name
|
||||
// - LHS: <TypeExpr>
|
||||
type Var Node
|
||||
|
||||
func (n *Var) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -569,9 +569,9 @@ func NewVar(name t.ID, xType *TypeExpr) *Var {
|
||||
}
|
||||
|
||||
// Field is a "name : type" struct field:
|
||||
// - FlagsPrivateData is the initializer need not explicitly memset to zero.
|
||||
// - ID2: name
|
||||
// - LHS: <TypeExpr>
|
||||
// - FlagsPrivateData is the initializer need not explicitly memset to zero.
|
||||
// - ID2: name
|
||||
// - LHS: <TypeExpr>
|
||||
type Field Node
|
||||
|
||||
func (n *Field) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -590,11 +590,11 @@ func NewField(flags Flags, name t.ID, xType *TypeExpr) *Field {
|
||||
|
||||
// IOManip is "io_bind (io:LHS, data:MHS, history_position:RHS) { List2 }" or
|
||||
// "io_limit (io:LHS, limit:MHS) { List2 }":
|
||||
// - ID0: <IDIOBind|IDIOLimit>
|
||||
// - LHS: <Expr>
|
||||
// - MHS: <Expr>
|
||||
// - RHS: <Expr>
|
||||
// - List2: <Statement> body
|
||||
// - ID0: <IDIOBind|IDIOLimit>
|
||||
// - LHS: <Expr>
|
||||
// - MHS: <Expr>
|
||||
// - RHS: <Expr>
|
||||
// - List2: <Statement> body
|
||||
type IOManip Node
|
||||
|
||||
func (n *IOManip) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -617,16 +617,16 @@ func NewIOManip(keyword t.ID, io *Expr, arg1 *Expr, historyPosition *Expr, body
|
||||
|
||||
// Iterate is
|
||||
// "iterate.ID1 (assigns)(length:ID2, advance:ID0, unroll:LHS), List1 { List2 } else RHS":
|
||||
// - FlagsHasBreak is the iterate has an explicit break
|
||||
// - FlagsHasContinue is the iterate has an explicit continue
|
||||
// - ID0: advance
|
||||
// - ID1: <0|label>
|
||||
// - ID2: length
|
||||
// - LHS: <Expr> unroll
|
||||
// - RHS: <nil|Iterate>
|
||||
// - List0: <Assign> assigns
|
||||
// - List1: <Assert> asserts
|
||||
// - List2: <Statement> body
|
||||
// - FlagsHasBreak is the iterate has an explicit break
|
||||
// - FlagsHasContinue is the iterate has an explicit continue
|
||||
// - ID0: advance
|
||||
// - ID1: <0|label>
|
||||
// - ID2: length
|
||||
// - LHS: <Expr> unroll
|
||||
// - RHS: <nil|Iterate>
|
||||
// - List0: <Assign> assigns
|
||||
// - List1: <Assert> asserts
|
||||
// - List2: <Statement> body
|
||||
type Iterate Node
|
||||
|
||||
func (n *Iterate) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -661,12 +661,12 @@ func NewIterate(label t.ID, assigns []*Node, length t.ID, advance t.ID, unroll t
|
||||
}
|
||||
|
||||
// While is "while.ID1 MHS, List1 { List2 } endwhile.ID1":
|
||||
// - FlagsHasBreak is the while has an explicit break
|
||||
// - FlagsHasContinue is the while has an explicit continue
|
||||
// - ID1: <0|label>
|
||||
// - MHS: <Expr>
|
||||
// - List1: <Assert> asserts
|
||||
// - List2: <Statement> body
|
||||
// - FlagsHasBreak is the while has an explicit break
|
||||
// - FlagsHasContinue is the while has an explicit continue
|
||||
// - ID1: <0|label>
|
||||
// - MHS: <Expr>
|
||||
// - List1: <Assert> asserts
|
||||
// - List2: <Statement> body
|
||||
//
|
||||
// TODO: should we be able to unroll while loops too?
|
||||
type While Node
|
||||
@@ -699,10 +699,10 @@ func NewWhile(label t.ID, condition *Expr, asserts []*Node) *While {
|
||||
}
|
||||
|
||||
// If is "if MHS { List2 } else RHS" or "if MHS { List2 } else { List1 }":
|
||||
// - MHS: <Expr>
|
||||
// - RHS: <nil|If>
|
||||
// - List1: <Statement> if-false body
|
||||
// - List2: <Statement> if-true body
|
||||
// - MHS: <Expr>
|
||||
// - RHS: <nil|If>
|
||||
// - List1: <Statement> if-false body
|
||||
// - List2: <Statement> if-true body
|
||||
type If Node
|
||||
|
||||
func (n *If) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -722,8 +722,8 @@ func NewIf(condition *Expr, bodyIfTrue []*Node, bodyIfFalse []*Node, elseIf *If)
|
||||
}
|
||||
|
||||
// Choose is "choose ID2: List0":
|
||||
// - ID2: name
|
||||
// - List0: <Expr> method names.
|
||||
// - ID2: name
|
||||
// - List0: <Expr> method names.
|
||||
type Choose Node
|
||||
|
||||
func (n *Choose) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -739,9 +739,9 @@ func NewChoose(name t.ID, args []*Node) *Choose {
|
||||
}
|
||||
|
||||
// Ret is "return LHS" or "yield LHS":
|
||||
// - FlagsReturnsError LHS is an error status
|
||||
// - ID0: <IDReturn|IDYield>
|
||||
// - LHS: <Expr>
|
||||
// - FlagsReturnsError LHS is an error status
|
||||
// - ID0: <IDReturn|IDYield>
|
||||
// - LHS: <Expr>
|
||||
type Ret Node
|
||||
|
||||
func (n *Ret) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -760,8 +760,8 @@ func NewRet(keyword t.ID, value *Expr) *Ret {
|
||||
}
|
||||
|
||||
// Jump is "break" or "continue", with an optional label, "break.label":
|
||||
// - ID0: <IDBreak|IDContinue>
|
||||
// - ID1: <0|label>
|
||||
// - ID0: <IDBreak|IDContinue>
|
||||
// - ID1: <0|label>
|
||||
type Jump Node
|
||||
|
||||
func (n *Jump) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -784,12 +784,12 @@ const MaxTypeExprDepth = 63
|
||||
|
||||
// TypeExpr is a type expression, such as "base.u32", "base.u32[..= 8]", "foo",
|
||||
// "pkg.bar", "ptr T", "array[8] T", "slice T" or "table T":
|
||||
// - ID0: <0|IDArray|IDFunc|IDNptr|IDPtr|IDSlice|IDTable>
|
||||
// - ID1: <0|pkg>
|
||||
// - ID2: <0|type name>
|
||||
// - LHS: <nil|Expr>
|
||||
// - MHS: <nil|Expr>
|
||||
// - RHS: <nil|TypeExpr>
|
||||
// - ID0: <0|IDArray|IDFunc|IDNptr|IDPtr|IDSlice|IDTable>
|
||||
// - ID1: <0|pkg>
|
||||
// - ID2: <0|type name>
|
||||
// - LHS: <nil|Expr>
|
||||
// - MHS: <nil|Expr>
|
||||
// - RHS: <nil|TypeExpr>
|
||||
//
|
||||
// An IDNptr or IDPtr ID0 means "nptr RHS" or "ptr RHS". RHS is the inner type.
|
||||
//
|
||||
@@ -958,14 +958,14 @@ func NewTypeExpr(decorator t.ID, pkg t.ID, name t.ID, alenRecvMin *Node, max *Ex
|
||||
const MaxBodyDepth = 255
|
||||
|
||||
// Func is "func ID2.ID0(LHS)(RHS) { List2 }":
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID0: funcName
|
||||
// - ID1: <0|receiverPkg> (set by calling SetPackage)
|
||||
// - ID2: <0|receiverName>
|
||||
// - LHS: <Struct> in-parameters
|
||||
// - RHS: <Struct> out-parameters
|
||||
// - List1: <Assert> asserts
|
||||
// - List2: <Statement> body
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID0: funcName
|
||||
// - ID1: <0|receiverPkg> (set by calling SetPackage)
|
||||
// - ID2: <0|receiverName>
|
||||
// - LHS: <Struct> in-parameters
|
||||
// - RHS: <Struct> out-parameters
|
||||
// - List1: <Assert> asserts
|
||||
// - List2: <Statement> body
|
||||
type Func Node
|
||||
|
||||
func (n *Func) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -1033,9 +1033,9 @@ func NewFunc(flags Flags, filename string, line uint32, receiverName t.ID, funcN
|
||||
}
|
||||
|
||||
// Status is "error (RHS) ID2" or "suspension (RHS) ID2":
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: message
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: message
|
||||
type Status Node
|
||||
|
||||
func (n *Status) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -1055,11 +1055,11 @@ func NewStatus(flags Flags, filename string, line uint32, message t.ID) *Status
|
||||
}
|
||||
|
||||
// Const is "const ID2 LHS = RHS":
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: name
|
||||
// - LHS: <TypeExpr>
|
||||
// - RHS: <Expr>
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: name
|
||||
// - LHS: <TypeExpr>
|
||||
// - RHS: <Expr>
|
||||
type Const Node
|
||||
|
||||
func (n *Const) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -1087,12 +1087,12 @@ func NewConst(flags Flags, filename string, line uint32, name t.ID, xType *TypeE
|
||||
const MaxImplements = 63
|
||||
|
||||
// Struct is "struct ID2? implements List0 (List1)":
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - FlagsClassy is "ID2" vs "ID2?"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: name
|
||||
// - List0: <TypeExpr> implements
|
||||
// - List1: <Field> fields
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - FlagsClassy is "ID2" vs "ID2?"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: name
|
||||
// - List0: <TypeExpr> implements
|
||||
// - List1: <Field> fields
|
||||
//
|
||||
// The question mark indicates a classy struct - one that supports methods,
|
||||
// especially coroutines.
|
||||
@@ -1120,7 +1120,7 @@ func NewStruct(flags Flags, filename string, line uint32, name t.ID, implements
|
||||
}
|
||||
|
||||
// Use is "use ID2":
|
||||
// - ID2: <"-string literal> package path
|
||||
// - ID2: <"-string literal> package path
|
||||
type Use Node
|
||||
|
||||
func (n *Use) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -1138,7 +1138,7 @@ func NewUse(filename string, line uint32, path t.ID) *Use {
|
||||
}
|
||||
|
||||
// File is a file of source code:
|
||||
// - List0: <Const|Func|Status|Struct|Use> top-level declarations
|
||||
// - List0: <Const|Func|Status|Struct|Use> top-level declarations
|
||||
type File Node
|
||||
|
||||
func (n *File) AsNode() *Node { return (*Node)(n) }
|
||||
|
||||
+15
-12
@@ -201,16 +201,16 @@ type Token struct {
|
||||
}
|
||||
|
||||
// nBuiltInIDs is the number of built-in IDs. The packing is:
|
||||
// - 0x00 is invalid.
|
||||
// - 0x01 ..= 0x0F are squiggly punctuation, such as ";", "." and "?".
|
||||
// - 0x10 ..= 0x1F are squiggly bookends, such as "(", ")" and "]".
|
||||
// - 0x20 ..= 0x3F are squiggly assignments, such as "=" and "+=".
|
||||
// - 0x40 ..= 0x6F are operators, such as "+", "==" and "not".
|
||||
// - 0x70 ..= 0xAF are x-ops (disambiguation forms): unary vs binary "+".
|
||||
// - 0xB0 ..= 0xCF are keywords, such as "if" and "return".
|
||||
// - 0xD0 ..= 0xDF are type modifiers, such as "ptr" and "slice".
|
||||
// - 0xE0 ..= 0xFF are literals, such as "ok" and "true".
|
||||
// - 0x100 ..= 0x3FF are identifiers, such as "bool", "u32" and "read_u8".
|
||||
// - 0x00 is invalid.
|
||||
// - 0x01 ..= 0x0F are squiggly punctuation, such as ";", "." and "?".
|
||||
// - 0x10 ..= 0x1F are squiggly bookends, such as "(", ")" and "]".
|
||||
// - 0x20 ..= 0x3F are squiggly assignments, such as "=" and "+=".
|
||||
// - 0x40 ..= 0x6F are operators, such as "+", "==" and "not".
|
||||
// - 0x70 ..= 0xAF are x-ops (disambiguation forms): unary vs binary "+".
|
||||
// - 0xB0 ..= 0xCF are keywords, such as "if" and "return".
|
||||
// - 0xD0 ..= 0xDF are type modifiers, such as "ptr" and "slice".
|
||||
// - 0xE0 ..= 0xFF are literals, such as "ok" and "true".
|
||||
// - 0x100 ..= 0x3FF are identifiers, such as "bool", "u32" and "read_u8".
|
||||
//
|
||||
// Squiggly means a sequence of non-alpha-numeric bytes, such as "+" and "&=".
|
||||
const (
|
||||
@@ -1299,9 +1299,12 @@ func init() {
|
||||
// addXForms modifies table so that, if table[x] == y, then table[y] = y.
|
||||
//
|
||||
// For example, for the unaryForms table, the explicit entries are like:
|
||||
// IDPlus: IDXUnaryPlus,
|
||||
//
|
||||
// IDPlus: IDXUnaryPlus,
|
||||
//
|
||||
// and this function implicitly addes entries like:
|
||||
// IDXUnaryPlus: IDXUnaryPlus,
|
||||
//
|
||||
// IDXUnaryPlus: IDXUnaryPlus,
|
||||
func addXForms(table *[nBuiltInSymbolicIDs]ID) {
|
||||
implicitEntries := [nBuiltInSymbolicIDs]bool{}
|
||||
for _, y := range table {
|
||||
|
||||
@@ -27,57 +27,57 @@
|
||||
// repository was 80 times faster than `clang-format`, even without a column
|
||||
// limit:
|
||||
//
|
||||
// $ wc release/c/wuffs-v0.2.c
|
||||
// 11858 35980 431885 release/c/wuffs-v0.2.c
|
||||
// $ time dumbindent < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.008s
|
||||
// user 0m0.005s
|
||||
// sys 0m0.005s
|
||||
// $ time clang-format-9 < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.668s
|
||||
// user 0m0.618s
|
||||
// sys 0m0.032s
|
||||
// $ time clang-format-9 -style='{ColumnLimit: 0}' < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.641s
|
||||
// user 0m0.585s
|
||||
// sys 0m0.037s
|
||||
// $ wc release/c/wuffs-v0.2.c
|
||||
// 11858 35980 431885 release/c/wuffs-v0.2.c
|
||||
// $ time dumbindent < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.008s
|
||||
// user 0m0.005s
|
||||
// sys 0m0.005s
|
||||
// $ time clang-format-9 < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.668s
|
||||
// user 0m0.618s
|
||||
// sys 0m0.032s
|
||||
// $ time clang-format-9 -style='{ColumnLimit: 0}' < release/c/wuffs-v0.2.c > /dev/null
|
||||
// real 0m0.641s
|
||||
// user 0m0.585s
|
||||
// sys 0m0.037s
|
||||
//
|
||||
// Apart from some rare and largely uninteresting exceptions, the dumbindent
|
||||
// algorithm only considers:
|
||||
//
|
||||
// ∙ '{' and '}' curly braces,
|
||||
// ∙ '(' and ')' round parentheses,
|
||||
// ∙ '\n' line breaks,
|
||||
// ∙ ' ' spaces and '\t' tabs that start or end a line, and
|
||||
// ∙ strings, comments and preprocessor directives (in order to ignore any of
|
||||
// the above special characters within them),
|
||||
// ∙ '{' and '}' curly braces,
|
||||
// ∙ '(' and ')' round parentheses,
|
||||
// ∙ '\n' line breaks,
|
||||
// ∙ ' ' spaces and '\t' tabs that start or end a line, and
|
||||
// ∙ strings, comments and preprocessor directives (in order to ignore any of
|
||||
// the above special characters within them),
|
||||
//
|
||||
// Everything else is an opaque byte. Consider this input:
|
||||
//
|
||||
// for (i = 0; i < 3; i++) {
|
||||
// j = 0; // Ignore { in a comment.
|
||||
// if (i < j) { foo(); }
|
||||
// u = (v +
|
||||
// w);
|
||||
// }
|
||||
// for (i = 0; i < 3; i++) {
|
||||
// j = 0; // Ignore { in a comment.
|
||||
// if (i < j) { foo(); }
|
||||
// u = (v +
|
||||
// w);
|
||||
// }
|
||||
//
|
||||
// From the algorithm's point of view, this input is equivalent to:
|
||||
//
|
||||
// ....(.................).{
|
||||
// .................................
|
||||
// ...(.....).{....()..}
|
||||
// ....(...
|
||||
// .);
|
||||
// }
|
||||
// ....(.................).{
|
||||
// .................................
|
||||
// ...(.....).{....()..}
|
||||
// ....(...
|
||||
// .);
|
||||
// }
|
||||
//
|
||||
// The formatted output (using the default of 2 spaces per indent level) is:
|
||||
//
|
||||
// ....(.................).{
|
||||
// .................................
|
||||
// ...(.....).{....()..}
|
||||
// ....(...
|
||||
// .);
|
||||
// }
|
||||
// ....(.................).{
|
||||
// .................................
|
||||
// ...(.....).{....()..}
|
||||
// ....(...
|
||||
// .);
|
||||
// }
|
||||
//
|
||||
// Dumbindent adjusts lines horizontally (indenting) but not vertically (it
|
||||
// does not break or un-break lines, or collapse consecutive blank lines),
|
||||
@@ -103,9 +103,9 @@
|
||||
//
|
||||
// Similarly, dumbindent will not correct this mis-indentation:
|
||||
//
|
||||
// if (condition)
|
||||
// goto fail;
|
||||
// goto fail;
|
||||
// if (condition)
|
||||
// goto fail;
|
||||
// goto fail;
|
||||
//
|
||||
// Instead, when automatically or manually generating the input for dumbindent,
|
||||
// it is recommended to always emit curly braces (again, similar to `gofmt`
|
||||
|
||||
+14
-14
@@ -130,23 +130,23 @@ func (b *bitstream) take(nBits uint32) int32 {
|
||||
// 4, 4)" example from RFC 1951 section 3.2.2, the huffman struct is
|
||||
// initialized by calling:
|
||||
//
|
||||
// h.construct([]uint32{
|
||||
// 'A': 3, 'B': 3, 'C': 3, 'D': 3, 'E': 3, 'F': 2, 'G': 4, 'H': 4,
|
||||
// })
|
||||
// h.construct([]uint32{
|
||||
// 'A': 3, 'B': 3, 'C': 3, 'D': 3, 'E': 3, 'F': 2, 'G': 4, 'H': 4,
|
||||
// })
|
||||
//
|
||||
// which results in:
|
||||
//
|
||||
// huffman{
|
||||
// counts: [maxCodeBits + 1]uint32{
|
||||
// 2: 1, 3: 5, 4: 2,
|
||||
// },
|
||||
// symbols: [maxNumCodes]int32{
|
||||
// 0: 'F', 1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E', 6: 'G', 7: 'H',
|
||||
// },
|
||||
// lookUpTable: [256]uint32{
|
||||
// etc,
|
||||
// },
|
||||
// }
|
||||
// huffman{
|
||||
// counts: [maxCodeBits + 1]uint32{
|
||||
// 2: 1, 3: 5, 4: 2,
|
||||
// },
|
||||
// symbols: [maxNumCodes]int32{
|
||||
// 0: 'F', 1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E', 6: 'G', 7: 'H',
|
||||
// },
|
||||
// lookUpTable: [256]uint32{
|
||||
// etc,
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// Continuing the example from the RFC, decoding "1110" from the bitstream will
|
||||
// produce the 'G' symbol.
|
||||
|
||||
+31
-28
@@ -1057,18 +1057,19 @@ func orOneNegOneNonNeg(neg IntRange, non IntRange) (z IntRange) {
|
||||
// possible xx in x and yy in y.
|
||||
//
|
||||
// Algorithm:
|
||||
// // If the two intervals overlap, the result is the minimum of the two
|
||||
// // intervals' maxima.
|
||||
// //
|
||||
// // This overlaps code path is just an optimization.
|
||||
// if overlaps(x, y) {
|
||||
// return min(xMax, yMax)
|
||||
// }
|
||||
// xFlip = bitFillRight(bitFillRight(xMax & ~xMin) & xMax & ~yMax)
|
||||
// xResult = yMax & ((xMax & ~xFlip) | (xFlip >> 1))
|
||||
// yFlip = bitFillRight(bitFillRight(yMax & ~yMin) & yMax & ~xMax)
|
||||
// yResult = xMax & ((yMax & ~yFlip) | (yFlip >> 1))
|
||||
// return max(xResult, yResult)
|
||||
//
|
||||
// // If the two intervals overlap, the result is the minimum of the two
|
||||
// // intervals' maxima.
|
||||
// //
|
||||
// // This overlaps code path is just an optimization.
|
||||
// if overlaps(x, y) {
|
||||
// return min(xMax, yMax)
|
||||
// }
|
||||
// xFlip = bitFillRight(bitFillRight(xMax & ~xMin) & xMax & ~yMax)
|
||||
// xResult = yMax & ((xMax & ~xFlip) | (xFlip >> 1))
|
||||
// yFlip = bitFillRight(bitFillRight(yMax & ~yMin) & yMax & ~xMax)
|
||||
// yResult = xMax & ((yMax & ~yFlip) | (yFlip >> 1))
|
||||
// return max(xResult, yResult)
|
||||
//
|
||||
// If xMin and yMin are both zero, the overlaps branch is taken.
|
||||
//
|
||||
@@ -1189,13 +1190,15 @@ func (x IntRange) andMax(y IntRange) *big.Int {
|
||||
// possible xx in x and yy in y.
|
||||
//
|
||||
// Algorithm:
|
||||
// droppable = bitFillRight((xMax & ~xMin) | (yMax & ~yMin))
|
||||
// available = xMax & yMax & droppable
|
||||
// return xMax | yMax | (bitFillRight(available) >> 1)
|
||||
//
|
||||
// droppable = bitFillRight((xMax & ~xMin) | (yMax & ~yMin))
|
||||
// available = xMax & yMax & droppable
|
||||
// return xMax | yMax | (bitFillRight(available) >> 1)
|
||||
//
|
||||
// If xMin and yMin are both zero, this simplifies to:
|
||||
// available = xMax & yMax
|
||||
// return xMax | yMax | (bitFillRight(available) >> 1)
|
||||
//
|
||||
// available = xMax & yMax
|
||||
// return xMax | yMax | (bitFillRight(available) >> 1)
|
||||
func (x IntRange) orMax(y IntRange) *big.Int {
|
||||
if x[0].Sign() == 0 && y[0].Sign() == 0 {
|
||||
i := big.NewInt(0)
|
||||
@@ -1257,17 +1260,17 @@ func (x IntRange) orMax(y IntRange) *big.Int {
|
||||
}
|
||||
|
||||
// bitFillRight modifies i to round up to the next power of 2 minus 1:
|
||||
// - If i is +0 then bitFillRight(i) sets i to 0.
|
||||
// - If i is +1 then bitFillRight(i) sets i to 1.
|
||||
// - If i is +2 then bitFillRight(i) sets i to 3.
|
||||
// - If i is +3 then bitFillRight(i) sets i to 3.
|
||||
// - If i is +4 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +5 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +6 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +7 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +8 then bitFillRight(i) sets i to 15.
|
||||
// - If i is +9 then bitFillRight(i) sets i to 15.
|
||||
// - Etc.
|
||||
// - If i is +0 then bitFillRight(i) sets i to 0.
|
||||
// - If i is +1 then bitFillRight(i) sets i to 1.
|
||||
// - If i is +2 then bitFillRight(i) sets i to 3.
|
||||
// - If i is +3 then bitFillRight(i) sets i to 3.
|
||||
// - If i is +4 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +5 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +6 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +7 then bitFillRight(i) sets i to 7.
|
||||
// - If i is +8 then bitFillRight(i) sets i to 15.
|
||||
// - If i is +9 then bitFillRight(i) sets i to 15.
|
||||
// - Etc.
|
||||
func bitFillRight(i *big.Int) {
|
||||
if s := i.Sign(); s < 0 {
|
||||
panic("pre-condition failure")
|
||||
|
||||
@@ -30,23 +30,23 @@
|
||||
//
|
||||
// Example compression numbers on a small English text file (at
|
||||
// https://github.com/google/wuffs/blob/main/test/data/romeo.txt):
|
||||
// - romeo.txt is 942 bytes (100%).
|
||||
// - romeo.txt.litonlylzma is 659 bytes (70%).
|
||||
// - romeo.txt.xz is 644 bytes (68%).
|
||||
// - romeo.txt.lzma is 598 bytes (63%).
|
||||
// - romeo.txt.bz2 is 568 bytes (60%).
|
||||
// - romeo.txt.zst is 559 bytes (59%).
|
||||
// - romeo.txt.gz is 558 bytes (59%).
|
||||
// - romeo.txt is 942 bytes (100%).
|
||||
// - romeo.txt.litonlylzma is 659 bytes (70%).
|
||||
// - romeo.txt.xz is 644 bytes (68%).
|
||||
// - romeo.txt.lzma is 598 bytes (63%).
|
||||
// - romeo.txt.bz2 is 568 bytes (60%).
|
||||
// - romeo.txt.zst is 559 bytes (59%).
|
||||
// - romeo.txt.gz is 558 bytes (59%).
|
||||
//
|
||||
// Example compression numbers on a large archive of source code (at
|
||||
// https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.0.1.tar.xz):
|
||||
// - linux-5.0.1.tar is 863313920 bytes (100%).
|
||||
// - linux-5.0.1.tar.litonlylzma is 449726070 bytes (52%).
|
||||
// - linux-5.0.1.tar.gz is 164575959 bytes (19%).
|
||||
// - linux-5.0.1.tar.zst is 156959897 bytes (18%).
|
||||
// - linux-5.0.1.tar.bz2 is 125873134 bytes (15%).
|
||||
// - linux-5.0.1.tar.xz is 108233572 bytes (13%).
|
||||
// - linux-5.0.1.tar.lzma is 108216601 bytes (13%).
|
||||
// - linux-5.0.1.tar is 863313920 bytes (100%).
|
||||
// - linux-5.0.1.tar.litonlylzma is 449726070 bytes (52%).
|
||||
// - linux-5.0.1.tar.gz is 164575959 bytes (19%).
|
||||
// - linux-5.0.1.tar.zst is 156959897 bytes (18%).
|
||||
// - linux-5.0.1.tar.bz2 is 125873134 bytes (15%).
|
||||
// - linux-5.0.1.tar.xz is 108233572 bytes (13%).
|
||||
// - linux-5.0.1.tar.lzma is 108216601 bytes (13%).
|
||||
//
|
||||
// The various tools (/usr/bin/gzip, /usr/bin/xz, etc) were all ran with their
|
||||
// default settings, not their "maximum compression" settings. This is why the
|
||||
@@ -260,39 +260,39 @@ func (p *prob) encodeBit(rEnc *rangeEncoder, bitValue uint32) {
|
||||
|
||||
// byteProbs hold probabilities for coding 8 bits (1 byte) of data. It is a 256
|
||||
// element array such that:
|
||||
// - The 0th element is unused.
|
||||
// - The 1st element holds the probability that the 7th bit (the highest, most
|
||||
// significant bit) is 0.
|
||||
// - The 2nd element holds the probability that the 6th bit is 0, conditional
|
||||
// on the high bit being 0.
|
||||
// - The 3rd element holds the probability that the 6th bit is 0, conditional
|
||||
// on the high bit being 1.
|
||||
// - The 4th element holds the probability that the 5th bit is 0, conditional
|
||||
// on the high two bits being 00.
|
||||
// - The 5th element holds the probability that the 5th bit is 0, conditional
|
||||
// on the high two bits being 01.
|
||||
// - The 6th element holds the probability that the 5th bit is 0, conditional
|
||||
// on the high two bits being 10.
|
||||
// - The 7th element holds the probability that the 5th bit is 0, conditional
|
||||
// on the high two bits being 11.
|
||||
// - The 8th element holds the probability that the 4th bit is 0, conditional
|
||||
// on the high three bits being 000.
|
||||
// - etc
|
||||
// - The 255th element holds the probability that the 0th bit (the lowest,
|
||||
// least significant bit) is 0, conditional on the high seven bits being
|
||||
// 1111111.
|
||||
// - The 0th element is unused.
|
||||
// - The 1st element holds the probability that the 7th bit (the highest, most
|
||||
// significant bit) is 0.
|
||||
// - The 2nd element holds the probability that the 6th bit is 0, conditional
|
||||
// on the high bit being 0.
|
||||
// - The 3rd element holds the probability that the 6th bit is 0, conditional
|
||||
// on the high bit being 1.
|
||||
// - The 4th element holds the probability that the 5th bit is 0, conditional
|
||||
// on the high two bits being 00.
|
||||
// - The 5th element holds the probability that the 5th bit is 0, conditional
|
||||
// on the high two bits being 01.
|
||||
// - The 6th element holds the probability that the 5th bit is 0, conditional
|
||||
// on the high two bits being 10.
|
||||
// - The 7th element holds the probability that the 5th bit is 0, conditional
|
||||
// on the high two bits being 11.
|
||||
// - The 8th element holds the probability that the 4th bit is 0, conditional
|
||||
// on the high three bits being 000.
|
||||
// - etc
|
||||
// - The 255th element holds the probability that the 0th bit (the lowest,
|
||||
// least significant bit) is 0, conditional on the high seven bits being
|
||||
// 1111111.
|
||||
//
|
||||
// Put another way, the 256 elements' value of N, as in "it's a probability for
|
||||
// the Nth bit", looks like this (when arranged in 8 rows of 32 elements):
|
||||
//
|
||||
// u7665555444444443333333333333333
|
||||
// 22222222222222222222222222222222
|
||||
// 11111111111111111111111111111111
|
||||
// 11111111111111111111111111111111
|
||||
// 00000000000000000000000000000000
|
||||
// 00000000000000000000000000000000
|
||||
// 00000000000000000000000000000000
|
||||
// 00000000000000000000000000000000
|
||||
// u7665555444444443333333333333333
|
||||
// 22222222222222222222222222222222
|
||||
// 11111111111111111111111111111111
|
||||
// 11111111111111111111111111111111
|
||||
// 00000000000000000000000000000000
|
||||
// 00000000000000000000000000000000
|
||||
// 00000000000000000000000000000000
|
||||
// 00000000000000000000000000000000
|
||||
//
|
||||
// The 'u' means that the 0th element is unused.
|
||||
type byteProbs [0x100]prob
|
||||
|
||||
@@ -365,7 +365,7 @@ type bitVector []uint8
|
||||
// zig packs a pair of non-negative integers (i, j) into a single unique
|
||||
// non-negative integer, in a zig-zagging pattern:
|
||||
//
|
||||
// i=0 i=1 i=2 i=3 i=4 etc
|
||||
// . i=0 i=1 i=2 i=3 i=4 etc
|
||||
// j=0: 0 1 3 6 10 ...
|
||||
// j=1: 2 4 7 11 16 ...
|
||||
// j=2: 5 8 12 17 23 ...
|
||||
|
||||
Reference in new issue
Block a user