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
b51f0c5c
Commit
b51f0c5c
authored
Nov 19, 2010
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
index/suffixarray: use sort.Search
R=gri CC=golang-dev
https://golang.org/cl/3200041
parent
07791d04
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
20 deletions
+2
-20
src/pkg/index/suffixarray/suffixarray.go
src/pkg/index/suffixarray/suffixarray.go
+2
-20
No files found.
src/pkg/index/suffixarray/suffixarray.go
View file @
b51f0c5c
...
...
@@ -54,21 +54,8 @@ func (x *Index) at(i int) []byte {
}
// Binary search according to "A Method of Programming", E.W. Dijkstra.
func
(
x
*
Index
)
search
(
s
[]
byte
)
int
{
i
,
j
:=
0
,
len
(
x
.
sa
)
// i < j for non-empty x
for
i
+
1
<
j
{
// 0 <= i < j <= len(x.sa) && (x.at(i) <= s < x.at(j) || (s is not in x))
h
:=
i
+
(
j
-
i
)
/
2
// i < h < j
if
bytes
.
Compare
(
x
.
at
(
h
),
s
)
<=
0
{
i
=
h
}
else
{
// s < x.at(h)
j
=
h
}
}
// i+1 == j for non-empty x
return
i
return
sort
.
Search
(
len
(
x
.
sa
),
func
(
i
int
)
bool
{
return
bytes
.
Compare
(
x
.
at
(
i
),
s
)
>=
0
})
}
...
...
@@ -84,12 +71,7 @@ func (x *Index) Lookup(s []byte, n int) []int {
if
len
(
s
)
>
0
&&
n
!=
0
{
// find matching suffix index i
i
:=
x
.
search
(
s
)
// x.at(i) <= s < x.at(i+1)
// ignore the first suffix if it is < s
if
i
<
len
(
x
.
sa
)
&&
bytes
.
Compare
(
x
.
at
(
i
),
s
)
<
0
{
i
++
}
// x.at(i-1) < s <= x.at(i)
// collect the following suffixes with matching prefixes
for
(
n
<
0
||
len
(
res
)
<
n
)
&&
i
<
len
(
x
.
sa
)
&&
bytes
.
HasPrefix
(
x
.
at
(
i
),
s
)
{
...
...
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