OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // This file contains the infrastructure to create an | 5 // This file contains the infrastructure to create an |
6 // identifier and full-text index for a set of Go files. | 6 // identifier and full-text index for a set of Go files. |
7 // | 7 // |
8 // Algorithm for identifier index: | 8 // Algorithm for identifier index: |
9 // - traverse all .go files of the file tree specified by root | 9 // - traverse all .go files of the file tree specified by root |
10 // - for each word (identifier) encountered, collect all occurrences (spots) | 10 // - for each word (identifier) encountered, collect all occurrences (spots) |
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 line int | 947 line int |
948 } | 948 } |
949 | 949 |
950 func (list positionList) Len() int { return len(list) } | 950 func (list positionList) Len() int { return len(list) } |
951 func (list positionList) Less(i, j int) bool { return list[i].filename < list[j]
.filename } | 951 func (list positionList) Less(i, j int) bool { return list[i].filename < list[j]
.filename } |
952 func (list positionList) Swap(i, j int) { list[i], list[j] = list[j], list[
i] } | 952 func (list positionList) Swap(i, j int) { list[i], list[j] = list[j], list[
i] } |
953 | 953 |
954 | 954 |
955 // unique returns the list sorted and with duplicate entries removed | 955 // unique returns the list sorted and with duplicate entries removed |
956 func unique(list []int) []int { | 956 func unique(list []int) []int { |
957 » sort.SortInts(list) | 957 » sort.Ints(list) |
958 var last int | 958 var last int |
959 i := 0 | 959 i := 0 |
960 for _, x := range list { | 960 for _, x := range list { |
961 if i == 0 || x != last { | 961 if i == 0 || x != last { |
962 last = x | 962 last = x |
963 list[i] = x | 963 list[i] = x |
964 i++ | 964 i++ |
965 } | 965 } |
966 } | 966 } |
967 return list[0:i] | 967 return list[0:i] |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 if m.filename != last { | 1033 if m.filename != last { |
1034 addLines() | 1034 addLines() |
1035 last = m.filename | 1035 last = m.filename |
1036 } | 1036 } |
1037 lines = append(lines, m.line) | 1037 lines = append(lines, m.line) |
1038 } | 1038 } |
1039 addLines() | 1039 addLines() |
1040 | 1040 |
1041 return | 1041 return |
1042 } | 1042 } |
OLD | NEW |