Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Feb 23, 2012
1 parent d4fcfa3 commit 8ce09df
Show file tree
Hide file tree
Showing 18 changed files with 313 additions and 319 deletions.
6 changes: 3 additions & 3 deletions cmd/cgrep/cgrep.go
Expand Up @@ -10,7 +10,7 @@ import (
"log"
"os"
"runtime/pprof"

"code.google.com/p/codesearch/regexp"
)

Expand All @@ -29,7 +29,7 @@ func usage() {
}

var (
iflag = flag.Bool("i", false, "case-insensitive match")
iflag = flag.Bool("i", false, "case-insensitive match")
cpuProfile = flag.String("cpuprofile", "", "write cpu profile to this file")
)

Expand Down Expand Up @@ -72,5 +72,5 @@ func main() {
}
if !g.Match {
os.Exit(1)
}
}
}
13 changes: 6 additions & 7 deletions cmd/cindex/cindex.go
Expand Up @@ -54,10 +54,10 @@ func usage() {
}

var (
listFlag = flag.Bool("list", false, "list indexed paths and exit")
resetFlag = flag.Bool("reset", false, "discard existing index")
listFlag = flag.Bool("list", false, "list indexed paths and exit")
resetFlag = flag.Bool("reset", false, "discard existing index")
verboseFlag = flag.Bool("verbose", false, "print extra information")
cpuProfile = flag.String("cpuprofile", "", "write cpu profile to this file")
cpuProfile = flag.String("cpuprofile", "", "write cpu profile to this file")
)

func main() {
Expand All @@ -82,7 +82,7 @@ func main() {
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}

if *resetFlag && len(args) == 0 {
os.Remove(index.File())
return
Expand Down Expand Up @@ -110,7 +110,7 @@ func main() {
for len(args) > 0 && args[0] == "" {
args = args[1:]
}

master := index.File()
if _, err := os.Stat(master); err != nil {
// Does not exist.
Expand Down Expand Up @@ -148,7 +148,7 @@ func main() {
}
log.Printf("flush index")
ix.Flush()

if !*resetFlag {
log.Printf("merge %s %s", master, file)
index.Merge(file+"~", master, file)
Expand All @@ -158,4 +158,3 @@ func main() {
log.Printf("done")
return
}

16 changes: 8 additions & 8 deletions cmd/csearch/csearch.go
Expand Up @@ -46,12 +46,12 @@ func usage() {
}

var (
fFlag = flag.String("f", "", "search only files with names matching this regexp")
iFlag = flag.Bool("i", false, "case-insensitive search")
fFlag = flag.String("f", "", "search only files with names matching this regexp")
iFlag = flag.Bool("i", false, "case-insensitive search")
verboseFlag = flag.Bool("verbose", false, "print extra information")
bruteFlag = flag.Bool("brute", false, "brute force - search all files in index")
cpuProfile = flag.String("cpuprofile", "", "write cpu profile to this file")
bruteFlag = flag.Bool("brute", false, "brute force - search all files in index")
cpuProfile = flag.String("cpuprofile", "", "write cpu profile to this file")

matches bool
)

Expand All @@ -65,11 +65,11 @@ func Main() {
flag.Usage = usage
flag.Parse()
args := flag.Args()

if len(args) != 1 {
usage()
}

if *cpuProfile != "" {
f, err := os.Create(*cpuProfile)
if err != nil {
Expand Down Expand Up @@ -120,7 +120,7 @@ func Main() {
}
g.File(name)
}

matches = g.Match
}

Expand Down
44 changes: 22 additions & 22 deletions index/merge.go
Expand Up @@ -42,8 +42,8 @@ type idrange struct {
}

type postIndex struct {
tri uint32
count uint32
tri uint32
count uint32
offset uint32
}

Expand Down Expand Up @@ -71,7 +71,7 @@ func Merge(dst, src1, src2 string) {
i1++
}
hi := i1

// Record range before the shadow.
if old < lo {
map1 = append(map1, idrange{old, lo, new})
Expand Down Expand Up @@ -226,22 +226,22 @@ func Merge(dst, src1, src2 string) {
ix3.writeUint32(postIndex)
ix3.writeString(trailerMagic)
ix3.flush()

os.Remove(nameIndexFile.name)
os.Remove(w.postIndexFile.name)
}

type postMapReader struct {
ix *Index
idmap []idrange
triNum uint32
ix *Index
idmap []idrange
triNum uint32
trigram uint32
count uint32
offset uint32
d []byte
oldid uint32
fileid uint32
i int
count uint32
offset uint32
d []byte
oldid uint32
fileid uint32
i int
}

func (r *postMapReader) init(ix *Index, idmap []idrange) {
Expand All @@ -263,12 +263,12 @@ func (r *postMapReader) load() {
r.fileid = ^uint32(0)
return
}
r.trigram, r.count, r.offset = r.ix.listAt(r.triNum*postEntrySize)
r.trigram, r.count, r.offset = r.ix.listAt(r.triNum * postEntrySize)
if r.count == 0 {
r.fileid = ^uint32(0)
return
}
r.d = r.ix.slice(r.ix.postData + r.offset + 3, -1)
r.d = r.ix.slice(r.ix.postData+r.offset+3, -1)
r.oldid = ^uint32(0)
r.i = 0
}
Expand All @@ -294,21 +294,21 @@ func (r *postMapReader) nextId() bool {
continue
}
r.fileid = r.idmap[r.i].new + r.oldid - r.idmap[r.i].lo
return true
return true
}

r.fileid = ^uint32(0)
return false
}

type postDataWriter struct {
out *bufWriter
out *bufWriter
postIndexFile *bufWriter
buf [10]byte
base uint32
buf [10]byte
base uint32
count, offset uint32
last uint32
t uint32
last uint32
t uint32
}

func (w *postDataWriter) init(out *bufWriter) {
Expand Down
35 changes: 16 additions & 19 deletions index/merge_test.go
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
)

var mergePaths1= []string {
var mergePaths1 = []string{
"/a",
"/b",
"/c",
Expand All @@ -21,20 +21,20 @@ var mergePaths2 = []string{
"/cc",
}

var mergeFiles1 = map[string]string {
"/a/x": "hello world",
"/a/y": "goodbye world",
var mergeFiles1 = map[string]string{
"/a/x": "hello world",
"/a/y": "goodbye world",
"/b/xx": "now is the time",
"/b/xy": "for all good men",
"/c/ab": "give me all the potatoes",
"/c/de": "or give me death now",
}

var mergeFiles2 = map[string]string {
var mergeFiles2 = map[string]string{
"/b/www": "world wide indeed",
"/b/xx": "no, not now",
"/b/yy": "first potatoes, now liberty?",
"/cc": "come to the aid of his potatoes",
"/b/xx": "no, not now",
"/b/yy": "first potatoes, now liberty?",
"/cc": "come to the aid of his potatoes",
}

func TestMerge(t *testing.T) {
Expand All @@ -44,20 +44,20 @@ func TestMerge(t *testing.T) {
defer os.Remove(f1.Name())
defer os.Remove(f2.Name())
defer os.Remove(f3.Name())

out1 := f1.Name()
out2 := f2.Name()
out3 := f3.Name()

buildIndex(out1, mergePaths1, mergeFiles1)
buildIndex(out2, mergePaths2, mergeFiles2)

Merge(out3, out1, out2)

ix1 := Open(out1)
ix2 := Open(out2)
ix3 := Open(out3)

nameof := func(ix *Index) string {
switch {
case ix == ix1:
Expand All @@ -69,19 +69,19 @@ func TestMerge(t *testing.T) {
}
return "???"
}

checkFiles := func(ix *Index, l ...string) {
for i, s := range l {
if n := ix.Name(uint32(i)); n != s {
t.Errorf("%s: Name(%d) = %s, want %s", nameof(ix), i, n, s)
}
}
}

checkFiles(ix1, "/a/x", "/a/y", "/b/xx", "/b/xy", "/c/ab", "/c/de")
checkFiles(ix2, "/b/www", "/b/xx", "/b/yy", "/cc")
checkFiles(ix3, "/a/x", "/a/y", "/b/www", "/b/xx", "/b/yy", "/c/ab", "/c/de", "/cc")

check := func(ix *Index, trig string, l ...uint32) {
l1 := ix.PostingList(tri(trig[0], trig[1], trig[2]))
if !equalList(l1, l) {
Expand All @@ -100,6 +100,3 @@ func TestMerge(t *testing.T) {
check(ix3, "now", 3, 4, 6)
check(ix3, "pot", 4, 5, 7)
}



2 changes: 1 addition & 1 deletion index/mmap_bsd.go
Expand Up @@ -14,7 +14,7 @@ import (

// missing from package syscall on freebsd, openbsd
const (
_PROT_READ = 1
_PROT_READ = 1
_MAP_SHARED = 1
)

Expand Down
4 changes: 2 additions & 2 deletions index/mmap_windows.go
Expand Up @@ -11,7 +11,7 @@ import (
"unsafe"
)

func mmapFile(f *os.File) mmapData {
func mmapFile(f *os.File) mmapData {
st, err := f.Stat()
if err != nil {
log.Fatal(err)
Expand All @@ -32,6 +32,6 @@ func mmapFile(f *os.File) mmapData {
if err != nil {
log.Fatalf("MapViewOfFile %s: %v", f.Name(), err)
}
data := (*[1<<30]byte)(unsafe.Pointer(addr))
data := (*[1 << 30]byte)(unsafe.Pointer(addr))
return mmapData{f, data[:size]}
}

0 comments on commit 8ce09df

Please sign in to comment.