Commit 19dae079 authored by Russ Cox's avatar Russ Cox

gofmt -r 'α[β:len(α)] -> α[β:]' -w test/bench

except chameneosredux which i know is being edited

require gofmt for test/bench

R=r
https://golang.org/cl/157110
parent 7ada6018
......@@ -607,7 +607,7 @@ def RelativePath(path, cwd):
# Check that gofmt run on the list of files does not change them
def CheckGofmt(ui, repo, files, just_warn=False):
files = [f for f in files if f.startswith('src/') and f.endswith('.go')]
files = [f for f in files if (f.startswith('src/') or f.startswith('test/bench/')) and f.endswith('.go')]
if not files:
return
cwd = os.getcwd()
......@@ -1082,6 +1082,7 @@ def sync(ui, repo, **opts):
err = commands.postincoming(ui, repo, modheads, True, "tip")
if err:
return err
commands.update(ui, repo)
sync_changes(ui, repo)
def sync_note(msg):
......
......@@ -44,12 +44,12 @@ import (
var n = flag.Int("n", 15, "depth")
type Node struct {
item int;
left, right *Node;
item int;
left, right *Node;
}
type Arena struct {
head *Node
head *Node;
}
var arena Arena
......@@ -67,9 +67,9 @@ func (n *Node) free() {
func (a *Arena) New(item int, left, right *Node) *Node {
if a.head == nil {
nodes := make([]Node, 3 << uint(*n));
nodes := make([]Node, 3<<uint(*n));
for i := 0; i < len(nodes)-1; i++ {
nodes[i].left = &nodes[i+1];
nodes[i].left = &nodes[i+1]
}
a.head = &nodes[0];
}
......@@ -81,11 +81,11 @@ func (a *Arena) New(item int, left, right *Node) *Node {
return n;
}
func bottomUpTree(item, depth int) *Node {
func bottomUpTree(item, depth int) *Node {
if depth <= 0 {
return arena.New(item, nil, nil)
}
return arena.New(item, bottomUpTree(2*item-1, depth-1), bottomUpTree(2*item, depth-1))
return arena.New(item, bottomUpTree(2*item-1, depth-1), bottomUpTree(2*item, depth-1));
}
func (n *Node) itemCheck() int {
......@@ -95,13 +95,13 @@ func (n *Node) itemCheck() int {
return n.item + n.left.itemCheck() - n.right.itemCheck();
}
const minDepth = 4;
const minDepth = 4
func main() {
flag.Parse();
maxDepth := *n;
if minDepth + 2 > *n {
if minDepth+2 > *n {
maxDepth = minDepth + 2
}
stretchDepth := maxDepth + 1;
......@@ -111,15 +111,15 @@ func main() {
longLivedTree := bottomUpTree(0, maxDepth);
for depth := minDepth; depth <= maxDepth; depth+=2 {
iterations := 1 << uint(maxDepth - depth + minDepth);
for depth := minDepth; depth <= maxDepth; depth += 2 {
iterations := 1 << uint(maxDepth-depth+minDepth);
check = 0;
for i := 1; i <= iterations; i++ {
t := bottomUpTree(i,depth);
t := bottomUpTree(i, depth);
check += t.itemCheck();
t.free();
t = bottomUpTree(-i,depth);
t = bottomUpTree(-i, depth);
check += t.itemCheck();
t.free();
}
......
......@@ -44,15 +44,15 @@ import (
var n = flag.Int("n", 15, "depth")
type Node struct {
item int;
left, right *Node;
item int;
left, right *Node;
}
func bottomUpTree(item, depth int) *Node {
func bottomUpTree(item, depth int) *Node {
if depth <= 0 {
return &Node{item: item}
}
return &Node{ item, bottomUpTree(2*item-1, depth-1), bottomUpTree(2*item, depth-1) }
return &Node{item, bottomUpTree(2*item-1, depth-1), bottomUpTree(2*item, depth-1)};
}
func (n *Node) itemCheck() int {
......@@ -62,13 +62,13 @@ func (n *Node) itemCheck() int {
return n.item + n.left.itemCheck() - n.right.itemCheck();
}
const minDepth = 4;
const minDepth = 4
func main() {
flag.Parse();
maxDepth := *n;
if minDepth + 2 > *n {
if minDepth+2 > *n {
maxDepth = minDepth + 2
}
stretchDepth := maxDepth + 1;
......@@ -78,13 +78,13 @@ func main() {
longLivedTree := bottomUpTree(0, maxDepth);
for depth := minDepth; depth <= maxDepth; depth+=2 {
iterations := 1 << uint(maxDepth - depth + minDepth);
for depth := minDepth; depth <= maxDepth; depth += 2 {
iterations := 1 << uint(maxDepth-depth+minDepth);
check = 0;
for i := 1; i <= iterations; i++ {
check += bottomUpTree(i,depth).itemCheck();
check += bottomUpTree(-i,depth).itemCheck();
check += bottomUpTree(i, depth).itemCheck();
check += bottomUpTree(-i, depth).itemCheck();
}
fmt.Printf("%d\t trees of depth %d\t check: %d\n", iterations*2, depth, check);
}
......
......@@ -46,7 +46,7 @@ var n = flag.Int("n", 7, "count")
func fannkuch(n int) int {
if n < 1 {
return 0;
return 0
}
n1 := n - 1;
......@@ -55,43 +55,45 @@ func fannkuch(n int) int {
count := make([]int, n);
for i := 0; i < n; i++ {
perm1[i] = i; // initial (trivial) permutation
perm1[i] = i // initial (trivial) permutation
}
r := n;
didpr := 0;
flipsMax := 0;
for {
if didpr < 30 {
if didpr < 30 {
for i := 0; i < n; i++ {
fmt.Printf("%d", 1+perm1[i]);
fmt.Printf("%d", 1+perm1[i])
}
fmt.Printf("\n");
didpr++;
}
for ; r != 1; r-- {
count[r-1] = r;
count[r-1] = r
}
if perm1[0] != 0 && perm1[n1] != n1 {
flips := 0;
for i := 1; i < n; i++ { // perm = perm1
perm[i] = perm1[i];
perm[i] = perm1[i]
}
k := perm1[0]; // cache perm[0] in k
for { // k!=0 ==> k>0
k := perm1[0]; // cache perm[0] in k
for { // k!=0 ==> k>0
for i, j := 1, k-1; i < j; i, j = i+1, j-1 {
perm[i], perm[j] = perm[j], perm[i];
perm[i], perm[j] = perm[j], perm[i]
}
flips++;
// Now exchange k (caching perm[0]) and perm[k]... with care!
j := perm[k]; perm[k] = k; k = j;
j := perm[k];
perm[k] = k;
k = j;
if k == 0 {
break
}
}
if flipsMax < flips {
flipsMax = flips;
flipsMax = flips
}
}
......@@ -99,19 +101,19 @@ func fannkuch(n int) int {
// rotate down perm[0..r] by one
perm0 := perm1[0];
for i := 0; i < r; i++ {
perm1[i] = perm1[i+1];
perm1[i] = perm1[i+1]
}
perm1[r] = perm0;
count[r]--;
if count[r] > 0 {
break;
break
}
}
if r == n {
return flipsMax;
return flipsMax
}
}
return 0
return 0;
}
func main() {
......
......@@ -91,7 +91,7 @@ func RepeatFasta(s []byte, count int) {
pos := 0;
s2 := make([]byte, len(s)+WIDTH);
copy(s2, s);
copy(s2[len(s):len(s2)], s);
copy(s2[len(s):], s);
for count > 0 {
line := min(WIDTH, count);
out.Write(s2[pos : pos+line]);
......
......@@ -47,18 +47,18 @@ import (
var in *bufio.Reader
func count(data string, n int) map[string] int {
counts := make(map[string] int);
func count(data string, n int) map[string]int {
counts := make(map[string]int);
top := len(data) - n;
for i := 0; i <= top; i++ {
s := data[i:i+n];
s := data[i : i+n];
if k, ok := counts[s]; ok {
counts[s] = k+1
counts[s] = k + 1
} else {
counts[s] = 1
}
}
return counts
return counts;
}
func countOne(data string, s string) int {
......@@ -66,7 +66,7 @@ func countOne(data string, s string) int {
if i, ok := counts[s]; ok {
return i
}
return 0
return 0;
}
......@@ -77,16 +77,16 @@ type kNuc struct {
type kNucArray []kNuc
func (kn kNucArray) Len() int { return len(kn) }
func (kn kNucArray) Swap(i, j int) { kn[i], kn[j] = kn[j], kn[i] }
func (kn kNucArray) Len() int { return len(kn) }
func (kn kNucArray) Swap(i, j int) { kn[i], kn[j] = kn[j], kn[i] }
func (kn kNucArray) Less(i, j int) bool {
if kn[i].count == kn[j].count {
return kn[i].name > kn[j].name // sort down
}
return kn[i].count > kn[j].count
return kn[i].count > kn[j].count;
}
func sortedArray(m map[string] int) kNucArray {
func sortedArray(m map[string]int) kNucArray {
kn := make(kNucArray, len(m));
i := 0;
for k, v := range m {
......@@ -98,14 +98,14 @@ func sortedArray(m map[string] int) kNucArray {
return kn;
}
func print(m map[string] int) {
func print(m map[string]int) {
a := sortedArray(m);
sum := 0;
for _, kn := range a {
sum += kn.count;
sum += kn.count
}
for _, kn := range a {
fmt.Printf("%s %.3f\n", kn.name, 100*float64(kn.count)/float64(sum));
fmt.Printf("%s %.3f\n", kn.name, 100*float64(kn.count)/float64(sum))
}
}
......@@ -119,7 +119,7 @@ func main() {
os.Exit(2);
}
if line[0] == '>' && bytes.Equal(line[0:len(three)], three) {
break;
break
}
}
data, err := io.ReadAll(in);
......@@ -132,7 +132,7 @@ func main() {
for i := 0; i < len(data); i++ {
if data[i] != '\n' {
data[j] = data[i] &^ ' '; // upper case
j++
j++;
}
}
str := string(data[0:j]);
......@@ -145,6 +145,6 @@ func main() {
interests := []string{"GGT", "GGTA", "GGTATT", "GGTATTTTAATT", "GGTATTTTAATTTATAGT"};
for _, s := range interests {
fmt.Printf("%d %s\n", countOne(str, s), s);
fmt.Printf("%d %s\n", countOne(str, s), s)
}
}
......@@ -32,7 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
*
* contributed by The Go Authors.
* Based on mandelbrot.c contributed by Greg Buchholz
*/
*/
package main
......@@ -61,7 +61,7 @@ func main() {
fmt.Fprintf(out, "P4\n%d %d\n", w, h);
for y := 0; y < h; y++ {
for x := 0; x<w; x++ {
for x := 0; x < w; x++ {
Zr, Zi, Tr, Ti := Zero, Zero, Zero, Zero;
Cr := (2*float64(x)/float64(w) - 1.5);
Ci := (2*float64(y)/float64(h) - 1.0);
......@@ -75,7 +75,7 @@ func main() {
byte_acc <<= 1;
if Tr+Ti <= Limit*Limit {
byte_acc |= 0x01;
byte_acc |= 0x01
}
bit_num++;
......@@ -85,7 +85,7 @@ func main() {
byte_acc = 0;
bit_num = 0;
} else if x == w-1 {
byte_acc <<= uint(8-w%8);
byte_acc <<= uint(8 - w%8);
out.WriteByte(byte_acc);
byte_acc = 0;
bit_num = 0;
......
This diff is collapsed.
......@@ -45,15 +45,15 @@ import (
var n = flag.Int("n", 1000, "number of iterations")
type Body struct {
x, y, z, vx, vy, vz, mass float64
x, y, z, vx, vy, vz, mass float64;
}
const (
solarMass = 4 * math.Pi * math.Pi;
daysPerYear = 365.24;
solarMass = 4 * math.Pi * math.Pi;
daysPerYear = 365.24;
)
func (b *Body) offsetMomentum(px, py, pz float64){
func (b *Body) offsetMomentum(px, py, pz float64) {
b.vx = -px / solarMass;
b.vy = -py / solarMass;
b.vz = -pz / solarMass;
......@@ -82,7 +82,7 @@ func (sys System) energy() float64 {
for i, body := range sys {
e += 0.5 * body.mass *
(body.vx*body.vx + body.vy*body.vy + body.vz*body.vz);
for j := i+1; j < len(sys); j++ {
for j := i + 1; j < len(sys); j++ {
body2 := sys[j];
dx := body.x - body2.x;
dy := body.y - body2.y;
......@@ -96,7 +96,7 @@ func (sys System) energy() float64 {
func (sys System) advance(dt float64) {
for i, body := range sys {
for j := i+1; j < len(sys); j++ {
for j := i + 1; j < len(sys); j++ {
body2 := sys[j];
dx := body.x - body2.x;
dy := body.y - body2.y;
......@@ -124,7 +124,7 @@ func (sys System) advance(dt float64) {
}
var (
jupiter = Body {
jupiter = Body{
x: 4.84143144246472090e+00,
y: -1.16032004402742839e+00,
z: -1.03622044471123109e-01,
......@@ -133,7 +133,7 @@ var (
vz: -6.90460016972063023e-05 * daysPerYear,
mass: 9.54791938424326609e-04 * solarMass,
};
saturn = Body {
saturn = Body{
x: 8.34336671824457987e+00,
y: 4.12479856412430479e+00,
z: -4.03523417114321381e-01,
......@@ -142,7 +142,7 @@ var (
vz: 2.30417297573763929e-05 * daysPerYear,
mass: 2.85885980666130812e-04 * solarMass,
};
uranus = Body {
uranus = Body{
x: 1.28943695621391310e+01,
y: -1.51111514016986312e+01,
z: -2.23307578892655734e-01,
......@@ -151,7 +151,7 @@ var (
vz: -2.96589568540237556e-05 * daysPerYear,
mass: 4.36624404335156298e-05 * solarMass,
};
neptune = Body {
neptune = Body{
x: 1.53796971148509165e+01,
y: -2.59193146099879641e+01,
z: 1.79258772950371181e-01,
......@@ -160,9 +160,9 @@ var (
vz: -9.51592254519715870e-05 * daysPerYear,
mass: 5.15138902046611451e-05 * solarMass,
};
sun = Body {
mass: solarMass
}
sun = Body{
mass: solarMass,
};
)
func main() {
......
......@@ -43,20 +43,20 @@ import (
"fmt";
)
var n = flag.Int("n", 27, "number of digits");
var silent = flag.Bool("s", false, "don't print result");
var n = flag.Int("n", 27, "number of digits")
var silent = flag.Bool("s", false, "don't print result")
var (
tmp1 *bignum.Integer;
tmp2 *bignum.Integer;
numer = bignum.Int(1);
accum = bignum.Int(0);
denom = bignum.Int(1);
tmp1 *bignum.Integer;
tmp2 *bignum.Integer;
numer = bignum.Int(1);
accum = bignum.Int(0);
denom = bignum.Int(1);
)
func extract_digit() int64 {
if numer.Cmp(accum) > 0 {
return -1;
return -1
}
// Compute (numer * 3 + accum) / denom
......@@ -70,7 +70,7 @@ func extract_digit() int64 {
// ... is normalized, then the two divisions have the same result.
if tmp2.Cmp(denom) >= 0 {
return -1;
return -1
}
return tmp1.Value();
......@@ -94,7 +94,7 @@ func eliminate_digit(d int64) {
func printf(s string, arg ...) {
if !*silent {
fmt.Printf(s, arg);
fmt.Printf(s, arg)
}
}
......@@ -110,20 +110,20 @@ func main() {
d = extract_digit();
}
printf("%c", d + '0');
printf("%c", d+'0');
i++;
m = i%10;
m = i % 10;
if m == 0 {
printf("\t:%d\n", i);
printf("\t:%d\n", i)
}
if i >= *n {
break;
break
}
eliminate_digit(d);
}
if m > 0 {
printf("%s\t:%d\n", " "[m : 10], *n);
printf("%s\t:%d\n", " "[m:10], *n)
}
}
......@@ -43,7 +43,7 @@ import (
"strings";
)
var variants = []string {
var variants = []string{
"agggtaaa|tttaccct",
"[cgt]gggtaaa|tttaccc[acg]",
"a[act]ggtaaa|tttacc[agt]t",
......@@ -56,21 +56,21 @@ var variants = []string {
}
type Subst struct {
pat, repl string
pat, repl string;
}
var substs = [] Subst {
Subst {"B", "(c|g|t)"},
Subst {"D", "(a|g|t)"},
Subst {"H", "(a|c|t)"},
Subst {"K", "(g|t)"},
Subst {"M", "(a|c)"},
Subst {"N", "(a|c|g|t)"},
Subst {"R", "(a|g)"},
Subst {"S", "(c|g)"},
Subst {"V", "(a|c|g)"},
Subst {"W", "(a|t)"},
Subst {"Y", "(c|t)"},
var substs = []Subst{
Subst{"B", "(c|g|t)"},
Subst{"D", "(a|g|t)"},
Subst{"H", "(a|c|t)"},
Subst{"K", "(g|t)"},
Subst{"M", "(a|c)"},
Subst{"N", "(a|c|g|t)"},
Subst{"R", "(a|g)"},
Subst{"S", "(c|g)"},
Subst{"V", "(a|c|g)"},
Subst{"W", "(a|t)"},
Subst{"Y", "(c|t)"},
}
func countMatches(pat string, bytes []byte) int {
......@@ -79,10 +79,10 @@ func countMatches(pat string, bytes []byte) int {
for {
e := re.Execute(bytes);
if len(e) == 0 {
break;
break
}
n++;
bytes = bytes[e[1]:len(bytes)];
bytes = bytes[e[1]:];
}
return n;
}
......@@ -98,10 +98,10 @@ func main() {
bytes = regexp.MustCompile("(>[^\n]+)?\n").ReplaceAll(bytes, []byte{});
clen := len(bytes);
for _, s := range variants {
fmt.Printf("%s %d\n", s, countMatches(s, bytes));
fmt.Printf("%s %d\n", s, countMatches(s, bytes))
}
for _, sub := range substs {
bytes = regexp.MustCompile(sub.pat).ReplaceAll(bytes, strings.Bytes(sub.repl));
bytes = regexp.MustCompile(sub.pat).ReplaceAll(bytes, strings.Bytes(sub.repl))
}
fmt.Printf("\n%d\n%d\n%d\n", ilen, clen, len(bytes));
}
......@@ -96,20 +96,20 @@ func main() {
line, err := in.ReadSlice('\n');
for err == nil {
os.Stdout.Write(line);
// Accumulate reversed complement in buf[w:]
nchar := 0;
w := len(buf);
for {
line, err = in.ReadSlice('\n');
if err != nil || line[0] == '>' {
break;
break
}
line = line[0:len(line)-1];
line = line[0 : len(line)-1];
nchar += len(line);
if len(line)+nchar/60+128 >= w {
nbuf := make([]byte, len(buf)*5);
copy(nbuf[len(nbuf)-len(buf):len(nbuf)], buf);
copy(nbuf[len(nbuf)-len(buf):], buf);
w += len(nbuf) - len(buf);
buf = nbuf;
}
......@@ -118,14 +118,14 @@ func main() {
buf[w] = complement[line[r]];
}
}
// Copy down to beginning of buffer, inserting newlines.
// The loop left room for the newlines and 128 bytes of padding.
i := 0;
for j := w; j < len(buf); j += 60 {
n := copy(buf[i:i+60], buf[j:len(buf)]);
n := copy(buf[i:i+60], buf[j:]);
buf[i+n] = '\n';
i += n+1;
i += n + 1;
}
os.Stdout.Write(buf[0:i]);
}
......
......@@ -46,9 +46,7 @@ import (
var n = flag.Int("n", 2000, "count")
var nCPU = flag.Int("ncpu", 4, "number of cpus")
func evalA(i, j int) float64 {
return 1 / float64(((i + j)*(i + j + 1)/2 + i + 1));
}
func evalA(i, j int) float64 { return 1 / float64(((i+j)*(i+j+1)/2 + i + 1)) }
type Vec []float64
......@@ -56,7 +54,7 @@ func (v Vec) Times(i, n int, u Vec, c chan int) {
for ; i < n; i++ {
v[i] = 0;
for j := 0; j < len(u); j++ {
v[i] += evalA(i, j)*u[j];
v[i] += evalA(i, j) * u[j]
}
}
c <- 1;
......@@ -66,7 +64,7 @@ func (v Vec) TimesTransp(i, n int, u Vec, c chan int) {
for ; i < n; i++ {
v[i] = 0;
for j := 0; j < len(u); j++ {
v[i] += evalA(j, i)*u[j];
v[i] += evalA(j, i) * u[j]
}
}
c <- 1;
......@@ -82,11 +80,11 @@ func (v Vec) ATimesTransp(u Vec) {
x := make(Vec, len(u));
c := make(chan int, *nCPU);
for i := 0; i < *nCPU; i++ {
go x.Times(i*len(v) / *nCPU, (i+1)*len(v) / *nCPU, u, c);
go x.Times(i*len(v) / *nCPU, (i+1)*len(v) / *nCPU, u, c)
}
wait(c);
for i := 0; i < *nCPU; i++ {
go v.TimesTransp(i*len(v) / *nCPU, (i+1)*len(v) / *nCPU, x, c);
go v.TimesTransp(i*len(v) / *nCPU, (i+1)*len(v) / *nCPU, x, c)
}
wait(c);
}
......@@ -97,7 +95,7 @@ func main() {
N := *n;
u := make(Vec, N);
for i := 0; i < N; i++ {
u[i] = 1;
u[i] = 1
}
v := make(Vec, N);
for i := 0; i < 10; i++ {
......@@ -106,8 +104,8 @@ func main() {
}
var vBv, vv float64;
for i := 0; i < N; i++ {
vBv += u[i]*v[i];
vv += v[i]*v[i];
vBv += u[i] * v[i];
vv += v[i] * v[i];
}
fmt.Printf("%0.9f\n", math.Sqrt(vBv/vv));
}
......@@ -44,9 +44,7 @@ import (
var n = flag.Int("n", 2000, "count")
func evalA(i, j int) float64 {
return 1 / float64(((i + j)*(i + j + 1)/2+ i + 1));
}
func evalA(i, j int) float64 { return 1 / float64(((i+j)*(i+j+1)/2 + i + 1)) }
type Vec []float64
......@@ -54,7 +52,7 @@ func (v Vec) Times(u Vec) {
for i := 0; i < len(v); i++ {
v[i] = 0;
for j := 0; j < len(u); j++ {
v[i] += evalA(i, j)*u[j];
v[i] += evalA(i, j) * u[j]
}
}
}
......@@ -63,7 +61,7 @@ func (v Vec) TimesTransp(u Vec) {
for i := 0; i < len(v); i++ {
v[i] = 0;
for j := 0; j < len(u); j++ {
v[i] += evalA(j, i)*u[j];
v[i] += evalA(j, i) * u[j]
}
}
}
......@@ -79,7 +77,7 @@ func main() {
N := *n;
u := make(Vec, N);
for i := 0; i < N; i++ {
u[i] = 1;
u[i] = 1
}
v := make(Vec, N);
for i := 0; i < 10; i++ {
......@@ -88,8 +86,8 @@ func main() {
}
var vBv, vv float64;
for i := 0; i < N; i++ {
vBv += u[i]*v[i];
vv += v[i]*v[i];
vBv += u[i] * v[i];
vv += v[i] * v[i];
}
fmt.Printf("%0.9f\n", math.Sqrt(vBv/vv));
}
......@@ -52,7 +52,7 @@ func f(i int, in <-chan int, out chan<- int) {
fmt.Printf("%d\n", i);
os.Exit(0);
}
out <- n - 1
out <- n-1;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment