1
0
mirror of https://github.com/golang/go synced 2024-11-21 16:14:42 -07:00

godoc: more index size reduction

- KindRuns don't need to repeat SpotKind,
  it is stored in each Spot
- removed extra indirection from FileRuns
  to KindRuns
- slight reduction of written index size
  (~500KB)

R=rsc
CC=golang-dev
https://golang.org/cl/4969052
This commit is contained in:
Robert Griesemer 2011-08-31 14:01:58 -07:00
parent a31f317a99
commit 3f1269ff1e
3 changed files with 22 additions and 25 deletions

View File

@ -26,7 +26,7 @@
{{range .Files}} {{range .Files}}
{{$src_html := srcLink .File.Path | html}} {{$src_html := srcLink .File.Path | html}}
{{range .Groups}} {{range .Groups}}
{{range .Infos}} {{range .}}
<a href="/{{$src_html}}?h={{$query_url}}#L{{infoLine .}}">{{$src_html}}:{{infoLine .}}</a> <a href="/{{$src_html}}?h={{$query_url}}#L{{infoLine .}}">{{$src_html}}:{{infoLine .}}</a>
{{infoSnippet_html .}} {{infoSnippet_html .}}
{{end}} {{end}}
@ -46,10 +46,10 @@
{{range .Groups}} {{range .Groups}}
<tr> <tr>
<td width="25"></td> <td width="25"></td>
<th align="left" valign="top">{{infoKind_html .Kind}}</th> <th align="left" valign="top">{{index . 0 | infoKind_html}}</th>
<td align="left" width="4"></td> <td align="left" width="4"></td>
<td> <td>
{{range .Infos}} {{range .}}
<a href="/{{$src_html}}?h={{$query_url}}#L{{infoLine .}}">{{infoLine .}}</a> <a href="/{{$src_html}}?h={{$query_url}}#L{{infoLine .}}">{{infoLine .}}</a>
{{end}} {{end}}
</td> </td>

View File

@ -406,8 +406,8 @@ var infoKinds = [nKinds]string{
Use: "use", Use: "use",
} }
func infoKind_htmlFunc(kind SpotKind) string { func infoKind_htmlFunc(info SpotInfo) string {
return infoKinds[kind] // infoKind entries are html-escaped return infoKinds[info.Kind()] // infoKind entries are html-escaped
} }
func infoLineFunc(info SpotInfo) int { func infoLineFunc(info SpotInfo) int {

View File

@ -7,7 +7,7 @@
// //
// Algorithm for identifier index: // Algorithm for identifier index:
// - traverse all .go files of the file tree specified by root // - traverse all .go files of the file tree specified by root
// - for each word (identifier) encountered, collect all occurrences (spots) // - for each identifier (word) encountered, collect all occurrences (spots)
// into a list; this produces a list of spots for each word // into a list; this produces a list of spots for each word
// - reduce the lists: from a list of spots to a list of FileRuns, // - reduce the lists: from a list of spots to a list of FileRuns,
// and from a list of FileRuns into a list of PakRuns // and from a list of FileRuns into a list of PakRuns
@ -179,28 +179,25 @@ func (x SpotInfo) IsIndex() bool { return x&1 != 0 }
const removeDuplicates = true const removeDuplicates = true
// A KindRun is a run of SpotInfos of the same kind in a given file. // A KindRun is a run of SpotInfos of the same kind in a given file.
type KindRun struct { // The kind (3 bits) is stored in each SpotInfo element; to find the
Kind SpotKind // kind of a KindRun, look at any of it's elements.
Infos []SpotInfo type KindRun []SpotInfo
}
// KindRuns are sorted by line number or index. Since the isIndex bit // KindRuns are sorted by line number or index. Since the isIndex bit
// is always the same for all infos in one list we can compare lori's. // is always the same for all infos in one list we can compare lori's.
func (f *KindRun) Len() int { return len(f.Infos) } func (k KindRun) Len() int { return len(k) }
func (f *KindRun) Less(i, j int) bool { return f.Infos[i].Lori() < f.Infos[j].Lori() } func (k KindRun) Less(i, j int) bool { return k[i].Lori() < k[j].Lori() }
func (f *KindRun) Swap(i, j int) { f.Infos[i], f.Infos[j] = f.Infos[j], f.Infos[i] } func (k KindRun) Swap(i, j int) { k[i], k[j] = k[j], k[i] }
// FileRun contents are sorted by Kind for the reduction into KindRuns. // FileRun contents are sorted by Kind for the reduction into KindRuns.
func lessKind(x, y interface{}) bool { return x.(SpotInfo).Kind() < y.(SpotInfo).Kind() } func lessKind(x, y interface{}) bool { return x.(SpotInfo).Kind() < y.(SpotInfo).Kind() }
// newKindRun allocates a new KindRun from the SpotInfo run h. // newKindRun allocates a new KindRun from the SpotInfo run h.
func newKindRun(h RunList) interface{} { func newKindRun(h RunList) interface{} {
kind := h[0].(SpotInfo).Kind() run := make(KindRun, len(h))
infos := make([]SpotInfo, len(h))
for i, x := range h { for i, x := range h {
infos[i] = x.(SpotInfo) run[i] = x.(SpotInfo)
} }
run := &KindRun{kind, infos}
// Spots were sorted by file and kind to create this run. // Spots were sorted by file and kind to create this run.
// Within this run, sort them by line number or index. // Within this run, sort them by line number or index.
@ -212,15 +209,15 @@ func newKindRun(h RunList) interface{} {
// bit is always the same for all infos in one // bit is always the same for all infos in one
// list we can simply compare the entire info. // list we can simply compare the entire info.
k := 0 k := 0
var prev SpotInfo prev := SpotInfo(1<<32 - 1) // an unlikely value
for i, x := range infos { for _, x := range run {
if x != prev || i == 0 { if x != prev {
infos[k] = x run[k] = x
k++ k++
prev = x prev = x
} }
} }
run.Infos = infos[0:k] run = run[0:k]
} }
return run return run
@ -260,7 +257,7 @@ type Spot struct {
// A FileRun is a list of KindRuns belonging to the same file. // A FileRun is a list of KindRuns belonging to the same file.
type FileRun struct { type FileRun struct {
File *File File *File
Groups []*KindRun Groups []KindRun
} }
// Spots are sorted by file path for the reduction into FileRuns. // Spots are sorted by file path for the reduction into FileRuns.
@ -285,9 +282,9 @@ func newFileRun(h RunList) interface{} {
h2 := h1.reduce(lessKind, newKindRun) h2 := h1.reduce(lessKind, newKindRun)
// create the FileRun // create the FileRun
groups := make([]*KindRun, len(h2)) groups := make([]KindRun, len(h2))
for i, x := range h2 { for i, x := range h2 {
groups[i] = x.(*KindRun) groups[i] = x.(KindRun)
} }
return &FileRun{file, groups} return &FileRun{file, groups}
} }