Commit c4adf3a5 authored by Jan Mercl's avatar Jan Mercl

Improve code style.

parent 930b360e
......@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
.PHONY: all todo clean cover generic mem nuke
.PHONY: all todo clean cover generic mem nuke cpu
testbin=b.test
......@@ -14,17 +14,22 @@ all: editor
make todo
editor:
go fmt
gofmt -l -s -w .
go test -i
go test
clean:
@go clean
rm -f *~
rm -f *~ *.out $(testbin)
cover:
t=$(shell tempfile) ; go test -coverprofile $$t && go tool cover -html $$t && unlink $$t
cpu:
go test -c
./$(testbin) -test.cpuprofile cpu.out
go tool pprof --lines $(testbin) cpu.out
generic:
@# writes to stdout a version where the type of key is KEY and the type
@# of value is VALUE.
......
......@@ -285,7 +285,9 @@ func (t *Tree) cat(p *x, q, r *d, pi int) {
if p.c > 1 {
p.extract(pi)
p.x[pi].ch = q
} else {
return
}
switch x := t.r.(type) {
case *x:
*x = zx
......@@ -295,7 +297,6 @@ func (t *Tree) cat(p *x, q, r *d, pi int) {
btDPool.Put(x)
}
t.r = q
}
}
func (t *Tree) catX(p, q, r *x, pi int) {
......@@ -513,10 +514,11 @@ func (t *Tree) overflow(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{
q.mvR(r, 1)
t.insert(q, i, k, v)
p.x[pi].k = r.d[0].k
} else {
return
}
t.insert(r, 0, k, v)
p.x[pi].k = k
}
return
}
......@@ -790,15 +792,22 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
if l != nil && l.c+q.c >= 2*kd {
l.mvR(q, 1)
p.x[pi-1].k = q.d[0].k
} else if r != nil && q.c+r.c >= 2*kd {
return
}
if r != nil && q.c+r.c >= 2*kd {
q.mvL(r, 1)
p.x[pi].k = r.d[0].k
r.d[r.c] = zde // GC
} else if l != nil {
return
}
if l != nil {
t.cat(p, l, q, pi-1)
} else {
t.cat(p, q, r, pi)
return
}
t.cat(p, q, r, pi)
}
func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) {
......
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