Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
599f758d
Commit
599f758d
authored
Sep 16, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
godoc: don't use quadratic algorithm to filter paths
R=rsc CC=golang-dev
https://golang.org/cl/2212042
parent
b610a78b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
10 deletions
+43
-10
src/cmd/godoc/godoc.go
src/cmd/godoc/godoc.go
+43
-10
No files found.
src/cmd/godoc/godoc.go
View file @
599f758d
...
@@ -107,21 +107,44 @@ func isRelated(p, q string) bool {
...
@@ -107,21 +107,44 @@ func isRelated(p, q string) bool {
}
}
// binarySearch returns an index i such that (a[i] <= s < a[i+1]) || (s is not in a).
// The slice a must not be empty and sorted in increasing order.
// (See "A Method of Programming", E.W. Dijkstra).
//
func
binarySearch
(
a
[]
string
,
s
string
)
int
{
i
,
j
:=
0
,
len
(
a
)
// i < j for non-empty a
for
i
+
1
<
j
{
// 0 <= i < j <= len(a) && (a[i] <= s < a[j] || (s is not in a))
h
:=
i
+
(
j
-
i
)
/
2
// i < h < j
if
a
[
h
]
<=
s
{
i
=
h
}
else
{
// s < a[h]
j
=
h
}
}
// i+1 == j for non-empty a
return
i
}
func
setPathFilter
(
list
[]
string
)
{
func
setPathFilter
(
list
[]
string
)
{
if
len
(
list
)
==
0
{
if
len
(
list
)
==
0
{
pathFilter
.
set
(
nil
)
pathFilter
.
set
(
nil
)
return
return
}
}
// TODO(gri) This leads to quadratic behavior.
// len(list) > 0
// Need to find a better filter solution.
pathFilter
.
set
(
func
(
path
string
)
bool
{
pathFilter
.
set
(
func
(
path
string
)
bool
{
for
_
,
p
:=
range
list
{
// list is sorted in increasing order and for each path all its children are removed
if
isRelated
(
path
,
p
)
{
i
:=
binarySearch
(
list
,
path
)
return
true
// At this point we have (list[i] <= path < list[i+1]) || (path is not in list),
}
// thus path must be either longer (a child) of list[i], or shorter (a parent)
}
// of list[i+1] - assuming an "infinitely extended" list. However, binarySearch
return
false
// will return a 0 if path < list[0], so we must be careful in that case.
return
i
==
0
&&
isParentOf
(
path
,
list
[
0
])
||
isParentOf
(
list
[
i
],
path
)
||
i
+
1
<
len
(
list
)
&&
isParentOf
(
path
,
list
[
i
+
1
])
})
})
}
}
...
@@ -142,12 +165,22 @@ func readDirList(filename string) ([]string, os.Error) {
...
@@ -142,12 +165,22 @@ func readDirList(filename string) ([]string, os.Error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
// create list of valid directory names
// create
a sorted
list of valid directory names
filter
:=
func
(
path
string
)
bool
{
filter
:=
func
(
path
string
)
bool
{
d
,
err
:=
os
.
Lstat
(
path
)
d
,
err
:=
os
.
Lstat
(
path
)
return
err
==
nil
&&
isPkgDir
(
d
)
return
err
==
nil
&&
isPkgDir
(
d
)
}
}
return
canonicalizePaths
(
strings
.
Split
(
string
(
contents
),
"
\n
"
,
-
1
),
filter
),
nil
list
:=
canonicalizePaths
(
strings
.
Split
(
string
(
contents
),
"
\n
"
,
-
1
),
filter
)
// for each parent path, remove all it's children q
// (requirement for binary search to work when filtering)
i
:=
0
for
_
,
q
:=
range
list
{
if
i
==
0
||
!
isParentOf
(
list
[
i
-
1
],
q
)
{
list
[
i
]
=
q
i
++
}
}
return
list
[
0
:
i
],
nil
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment