Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
b
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
b
Commits
eca71390
Commit
eca71390
authored
Apr 18, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X inline find2 into hitFind
parent
bd3f6889
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
38 deletions
+32
-38
btree.go
btree.go
+16
-19
example/int.go
example/int.go
+16
-19
No files found.
btree.go
View file @
eca71390
...
@@ -497,23 +497,6 @@ func (t *Tree) find(q interface{}, k interface{} /*K*/) (i int, ok bool) {
...
@@ -497,23 +497,6 @@ func (t *Tree) find(q interface{}, k interface{} /*K*/) (i int, ok bool) {
return
l
,
false
return
l
,
false
}
}
// find2 is the same as find but when we pre-know range to search and for data-page only
func
(
t
*
Tree
)
find2
(
d
*
d
,
k
interface
{}
/*K*/
,
l
,
h
int
)
(
i
int
,
ok
bool
)
{
for
l
<=
h
{
m
:=
(
l
+
h
)
>>
1
mk
:=
d
.
d
[
m
]
.
k
switch
cmp
:=
t
.
cmp
(
k
,
mk
);
{
case
cmp
>
0
:
l
=
m
+
1
case
cmp
==
0
:
return
m
,
true
default
:
h
=
m
-
1
}
}
return
l
,
false
}
// hitFind returns position for k in previously hit data page
// hitFind returns position for k in previously hit data page
// if k should not reside in hit range: -1, false is returned
// if k should not reside in hit range: -1, false is returned
// otherwise returns are:
// otherwise returns are:
...
@@ -529,6 +512,7 @@ func (t *Tree) hitFind(k interface{} /*K*/) (i int, ok bool) {
...
@@ -529,6 +512,7 @@ func (t *Tree) hitFind(k interface{} /*K*/) (i int, ok bool) {
}
}
i
=
t
.
hitDi
i
=
t
.
hitDi
var
h
int
switch
cmp
:=
t
.
cmp
(
k
,
hit
.
d
[
i
]
.
k
);
{
switch
cmp
:=
t
.
cmp
(
k
,
hit
.
d
[
i
]
.
k
);
{
case
cmp
>
0
:
case
cmp
>
0
:
...
@@ -538,7 +522,7 @@ func (t *Tree) hitFind(k interface{} /*K*/) (i int, ok bool) {
...
@@ -538,7 +522,7 @@ func (t *Tree) hitFind(k interface{} /*K*/) (i int, ok bool) {
}
}
// NOTE we are ok if i+1=hit.c -> hit.c will be returned
// NOTE we are ok if i+1=hit.c -> hit.c will be returned
return
t
.
find2
(
hit
,
k
,
i
+
1
,
hit
.
c
-
1
)
i
,
h
=
i
+
1
,
hit
.
c
-
1
case
cmp
<
0
:
case
cmp
<
0
:
if
t
.
hitKminSet
&&
t
.
cmp
(
k
,
t
.
hitKmin
)
<
0
{
if
t
.
hitKminSet
&&
t
.
cmp
(
k
,
t
.
hitKmin
)
<
0
{
...
@@ -547,11 +531,24 @@ func (t *Tree) hitFind(k interface{} /*K*/) (i int, ok bool) {
...
@@ -547,11 +531,24 @@ func (t *Tree) hitFind(k interface{} /*K*/) (i int, ok bool) {
}
}
// NOTE we are ok if i-1=-1 -> 0 will be returned
// NOTE we are ok if i-1=-1 -> 0 will be returned
return
t
.
find2
(
hit
,
k
,
0
,
i
-
1
)
i
,
h
=
0
,
i
-
1
default
:
default
:
return
i
,
true
return
i
,
true
}
}
for
i
<=
h
{
m
:=
(
i
+
h
)
>>
1
switch
cmp
:=
t
.
cmp
(
k
,
hit
.
d
[
m
]
.
k
);
{
case
cmp
>
0
:
i
=
m
+
1
case
cmp
==
0
:
return
m
,
true
default
:
h
=
m
-
1
}
}
return
i
,
false
}
}
// First returns the first item of the tree in the key collating order, or
// First returns the first item of the tree in the key collating order, or
...
...
example/int.go
View file @
eca71390
...
@@ -497,23 +497,6 @@ func (t *Tree) find(q interface{}, k int) (i int, ok bool) {
...
@@ -497,23 +497,6 @@ func (t *Tree) find(q interface{}, k int) (i int, ok bool) {
return
l
,
false
return
l
,
false
}
}
// find2 is the same as find but when we pre-know range to search and for data-page only
func
(
t
*
Tree
)
find2
(
d
*
d
,
k
int
,
l
,
h
int
)
(
i
int
,
ok
bool
)
{
for
l
<=
h
{
m
:=
(
l
+
h
)
>>
1
mk
:=
d
.
d
[
m
]
.
k
switch
cmp
:=
t
.
cmp
(
k
,
mk
);
{
case
cmp
>
0
:
l
=
m
+
1
case
cmp
==
0
:
return
m
,
true
default
:
h
=
m
-
1
}
}
return
l
,
false
}
// hitFind returns position for k in previously hit data page
// hitFind returns position for k in previously hit data page
// if k should not reside in hit range: -1, false is returned
// if k should not reside in hit range: -1, false is returned
// otherwise returns are:
// otherwise returns are:
...
@@ -529,6 +512,7 @@ func (t *Tree) hitFind(k int) (i int, ok bool) {
...
@@ -529,6 +512,7 @@ func (t *Tree) hitFind(k int) (i int, ok bool) {
}
}
i
=
t
.
hitDi
i
=
t
.
hitDi
var
h
int
switch
cmp
:=
t
.
cmp
(
k
,
hit
.
d
[
i
]
.
k
);
{
switch
cmp
:=
t
.
cmp
(
k
,
hit
.
d
[
i
]
.
k
);
{
case
cmp
>
0
:
case
cmp
>
0
:
...
@@ -538,7 +522,7 @@ func (t *Tree) hitFind(k int) (i int, ok bool) {
...
@@ -538,7 +522,7 @@ func (t *Tree) hitFind(k int) (i int, ok bool) {
}
}
// NOTE we are ok if i+1=hit.c -> hit.c will be returned
// NOTE we are ok if i+1=hit.c -> hit.c will be returned
return
t
.
find2
(
hit
,
k
,
i
+
1
,
hit
.
c
-
1
)
i
,
h
=
i
+
1
,
hit
.
c
-
1
case
cmp
<
0
:
case
cmp
<
0
:
if
t
.
hitKminSet
&&
t
.
cmp
(
k
,
t
.
hitKmin
)
<
0
{
if
t
.
hitKminSet
&&
t
.
cmp
(
k
,
t
.
hitKmin
)
<
0
{
...
@@ -547,11 +531,24 @@ func (t *Tree) hitFind(k int) (i int, ok bool) {
...
@@ -547,11 +531,24 @@ func (t *Tree) hitFind(k int) (i int, ok bool) {
}
}
// NOTE we are ok if i-1=-1 -> 0 will be returned
// NOTE we are ok if i-1=-1 -> 0 will be returned
return
t
.
find2
(
hit
,
k
,
0
,
i
-
1
)
i
,
h
=
0
,
i
-
1
default
:
default
:
return
i
,
true
return
i
,
true
}
}
for
i
<=
h
{
m
:=
(
i
+
h
)
>>
1
switch
cmp
:=
t
.
cmp
(
k
,
hit
.
d
[
m
]
.
k
);
{
case
cmp
>
0
:
i
=
m
+
1
case
cmp
==
0
:
return
m
,
true
default
:
h
=
m
-
1
}
}
return
i
,
false
}
}
// First returns the first item of the tree in the key collating order, or
// First returns the first item of the tree in the key collating order, or
...
...
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