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
4efd872d
Commit
4efd872d
authored
Apr 18, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X find -> find + findX
parent
eca71390
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
113 deletions
+112
-113
all_test.go
all_test.go
+4
-1
btree.go
btree.go
+54
-56
example/int.go
example/int.go
+54
-56
No files found.
all_test.go
View file @
4efd872d
...
...
@@ -211,9 +211,10 @@ loop:
break
}
i
,
ok
=
t
.
find
(
q
,
k
)
switch
x
:=
q
.
(
type
)
{
case
*
x
:
i
,
ok
=
t
.
findX
(
x
,
k
)
hitPKmin
=
hitKmin
hitPKmax
=
hitKmax
hitPKminSet
=
hitKminSet
...
...
@@ -246,6 +247,8 @@ loop:
}
case
*
d
:
i
,
ok
=
t
.
find
(
x
,
k
)
switch
op
{
case
opGet
:
// tried to search for key > max k in x
...
...
btree.go
View file @
4efd872d
...
...
@@ -378,9 +378,9 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
t
.
hitPKminSet
,
t
.
hitPKmaxSet
=
false
,
false
for
{
i
,
ok
:=
t
.
find
(
q
,
k
)
switch
x
:=
q
.
(
type
)
{
case
*
x
:
i
,
ok
:=
t
.
findX
(
x
,
k
)
if
ok
{
i
++
}
...
...
@@ -408,6 +408,8 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
}
case
*
d
:
i
,
ok
:=
t
.
find
(
x
,
k
)
// data page found - perform the delete
t
.
hitP
=
p
t
.
hitPi
=
pi
...
...
@@ -461,16 +463,12 @@ func (t *Tree) extract(q *d, i int) { // (r interface{} /*V*/) {
return
}
func
(
t
*
Tree
)
find
(
q
interface
{},
k
interface
{}
/*K*/
)
(
i
int
,
ok
bool
)
{
var
mk
interface
{}
/*K*/
func
(
t
*
Tree
)
findX
(
x
*
x
,
k
interface
{}
/*K*/
)
(
i
int
,
ok
bool
)
{
l
:=
0
switch
x
:=
q
.
(
type
)
{
case
*
x
:
h
:=
x
.
c
-
1
for
l
<=
h
{
m
:=
(
l
+
h
)
>>
1
mk
=
x
.
x
[
m
]
.
k
switch
cmp
:=
t
.
cmp
(
k
,
mk
);
{
switch
cmp
:=
t
.
cmp
(
k
,
x
.
x
[
m
]
.
k
);
{
case
cmp
>
0
:
l
=
m
+
1
case
cmp
==
0
:
...
...
@@ -479,12 +477,15 @@ func (t *Tree) find(q interface{}, k interface{} /*K*/) (i int, ok bool) {
h
=
m
-
1
}
}
case
*
d
:
return
l
,
false
}
func
(
t
*
Tree
)
find
(
x
*
d
,
k
interface
{}
/*K*/
)
(
i
int
,
ok
bool
)
{
l
:=
0
h
:=
x
.
c
-
1
for
l
<=
h
{
m
:=
(
l
+
h
)
>>
1
mk
=
x
.
d
[
m
]
.
k
switch
cmp
:=
t
.
cmp
(
k
,
mk
);
{
switch
cmp
:=
t
.
cmp
(
k
,
x
.
d
[
m
]
.
k
);
{
case
cmp
>
0
:
l
=
m
+
1
case
cmp
==
0
:
...
...
@@ -493,7 +494,6 @@ func (t *Tree) find(q interface{}, k interface{} /*K*/) (i int, ok bool) {
h
=
m
-
1
}
}
}
return
l
,
false
}
...
...
@@ -570,21 +570,20 @@ func (t *Tree) Get(k interface{} /*K*/) (v interface{} /*V*/, ok bool) {
}
for
{
var
i
int
if
i
,
ok
=
t
.
find
(
q
,
k
);
ok
{
switch
x
:=
q
.
(
type
)
{
case
*
x
:
q
=
x
.
x
[
i
+
1
]
.
ch
continue
i
,
ok
:=
t
.
findX
(
x
,
k
)
if
ok
{
i
++
}
q
=
x
.
x
[
i
]
.
ch
case
*
d
:
i
,
ok
:=
t
.
find
(
x
,
k
)
if
ok
{
return
x
.
d
[
i
]
.
v
,
true
}
}
switch
x
:=
q
.
(
type
)
{
case
*
x
:
q
=
x
.
x
[
i
]
.
ch
default
:
return
return
v
,
ok
}
}
}
...
...
@@ -670,22 +669,17 @@ func (t *Tree) Seek(k interface{} /*K*/) (e *Enumerator, ok bool) {
}
for
{
var
i
int
if
i
,
ok
=
t
.
find
(
q
,
k
);
ok
{
switch
x
:=
q
.
(
type
)
{
case
*
x
:
q
=
x
.
x
[
i
+
1
]
.
ch
continue
case
*
d
:
return
btEPool
.
get
(
nil
,
ok
,
i
,
k
,
x
,
t
,
t
.
ver
),
true
}
i
,
ok
:=
t
.
findX
(
x
,
k
)
if
ok
{
i
++
}
switch
x
:=
q
.
(
type
)
{
case
*
x
:
q
=
x
.
x
[
i
]
.
ch
case
*
d
:
return
btEPool
.
get
(
nil
,
ok
,
i
,
k
,
x
,
t
,
t
.
ver
),
false
i
,
ok
:=
t
.
find
(
x
,
k
)
return
btEPool
.
get
(
nil
,
ok
,
i
,
k
,
x
,
t
,
t
.
ver
),
ok
}
}
}
...
...
@@ -764,9 +758,9 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
t
.
hitPKminSet
,
t
.
hitPKmaxSet
=
false
,
false
for
{
i
,
ok
:=
t
.
find
(
q
,
k
)
switch
x
:=
q
.
(
type
)
{
case
*
x
:
i
,
ok
:=
t
.
findX
(
x
,
k
)
if
ok
{
i
++
}
...
...
@@ -794,6 +788,8 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
}
case
*
d
:
i
,
ok
:=
t
.
find
(
x
,
k
)
// data page found - perform the update
t
.
hitP
=
p
t
.
hitPi
=
pi
...
...
@@ -904,9 +900,9 @@ func (t *Tree) Put(k interface{} /*K*/, upd func(oldV interface{} /*V*/, exists
t
.
hitPKminSet
,
t
.
hitPKmaxSet
=
false
,
false
for
{
i
,
ok
:=
t
.
find
(
q
,
k
)
switch
x
:=
q
.
(
type
)
{
case
*
x
:
i
,
ok
:=
t
.
findX
(
x
,
k
)
if
ok
{
i
++
}
...
...
@@ -934,6 +930,8 @@ func (t *Tree) Put(k interface{} /*K*/, upd func(oldV interface{} /*V*/, exists
}
case
*
d
:
i
,
ok
:=
t
.
find
(
x
,
k
)
// data page found - perform the update
t
.
hitP
=
p
t
.
hitPi
=
pi
...
...
example/int.go
View file @
4efd872d
...
...
@@ -378,9 +378,9 @@ func (t *Tree) Delete(k int) (ok bool) {
t
.
hitPKminSet
,
t
.
hitPKmaxSet
=
false
,
false
for
{
i
,
ok
:=
t
.
find
(
q
,
k
)
switch
x
:=
q
.
(
type
)
{
case
*
x
:
i
,
ok
:=
t
.
findX
(
x
,
k
)
if
ok
{
i
++
}
...
...
@@ -408,6 +408,8 @@ func (t *Tree) Delete(k int) (ok bool) {
}
case
*
d
:
i
,
ok
:=
t
.
find
(
x
,
k
)
// data page found - perform the delete
t
.
hitP
=
p
t
.
hitPi
=
pi
...
...
@@ -461,16 +463,12 @@ func (t *Tree) extract(q *d, i int) { // (r int) {
return
}
func
(
t
*
Tree
)
find
(
q
interface
{},
k
int
)
(
i
int
,
ok
bool
)
{
var
mk
int
func
(
t
*
Tree
)
findX
(
x
*
x
,
k
int
)
(
i
int
,
ok
bool
)
{
l
:=
0
switch
x
:=
q
.
(
type
)
{
case
*
x
:
h
:=
x
.
c
-
1
for
l
<=
h
{
m
:=
(
l
+
h
)
>>
1
mk
=
x
.
x
[
m
]
.
k
switch
cmp
:=
t
.
cmp
(
k
,
mk
);
{
switch
cmp
:=
t
.
cmp
(
k
,
x
.
x
[
m
]
.
k
);
{
case
cmp
>
0
:
l
=
m
+
1
case
cmp
==
0
:
...
...
@@ -479,12 +477,15 @@ func (t *Tree) find(q interface{}, k int) (i int, ok bool) {
h
=
m
-
1
}
}
case
*
d
:
return
l
,
false
}
func
(
t
*
Tree
)
find
(
x
*
d
,
k
int
)
(
i
int
,
ok
bool
)
{
l
:=
0
h
:=
x
.
c
-
1
for
l
<=
h
{
m
:=
(
l
+
h
)
>>
1
mk
=
x
.
d
[
m
]
.
k
switch
cmp
:=
t
.
cmp
(
k
,
mk
);
{
switch
cmp
:=
t
.
cmp
(
k
,
x
.
d
[
m
]
.
k
);
{
case
cmp
>
0
:
l
=
m
+
1
case
cmp
==
0
:
...
...
@@ -493,7 +494,6 @@ func (t *Tree) find(q interface{}, k int) (i int, ok bool) {
h
=
m
-
1
}
}
}
return
l
,
false
}
...
...
@@ -570,21 +570,20 @@ func (t *Tree) Get(k int) (v int, ok bool) {
}
for
{
var
i
int
if
i
,
ok
=
t
.
find
(
q
,
k
);
ok
{
switch
x
:=
q
.
(
type
)
{
case
*
x
:
q
=
x
.
x
[
i
+
1
]
.
ch
continue
i
,
ok
:=
t
.
findX
(
x
,
k
)
if
ok
{
i
++
}
q
=
x
.
x
[
i
]
.
ch
case
*
d
:
i
,
ok
:=
t
.
find
(
x
,
k
)
if
ok
{
return
x
.
d
[
i
]
.
v
,
true
}
}
switch
x
:=
q
.
(
type
)
{
case
*
x
:
q
=
x
.
x
[
i
]
.
ch
default
:
return
return
v
,
ok
}
}
}
...
...
@@ -670,22 +669,17 @@ func (t *Tree) Seek(k int) (e *Enumerator, ok bool) {
}
for
{
var
i
int
if
i
,
ok
=
t
.
find
(
q
,
k
);
ok
{
switch
x
:=
q
.
(
type
)
{
case
*
x
:
q
=
x
.
x
[
i
+
1
]
.
ch
continue
case
*
d
:
return
btEPool
.
get
(
nil
,
ok
,
i
,
k
,
x
,
t
,
t
.
ver
),
true
}
i
,
ok
:=
t
.
findX
(
x
,
k
)
if
ok
{
i
++
}
switch
x
:=
q
.
(
type
)
{
case
*
x
:
q
=
x
.
x
[
i
]
.
ch
case
*
d
:
return
btEPool
.
get
(
nil
,
ok
,
i
,
k
,
x
,
t
,
t
.
ver
),
false
i
,
ok
:=
t
.
find
(
x
,
k
)
return
btEPool
.
get
(
nil
,
ok
,
i
,
k
,
x
,
t
,
t
.
ver
),
ok
}
}
}
...
...
@@ -764,9 +758,9 @@ func (t *Tree) Set(k int, v int) {
t
.
hitPKminSet
,
t
.
hitPKmaxSet
=
false
,
false
for
{
i
,
ok
:=
t
.
find
(
q
,
k
)
switch
x
:=
q
.
(
type
)
{
case
*
x
:
i
,
ok
:=
t
.
findX
(
x
,
k
)
if
ok
{
i
++
}
...
...
@@ -794,6 +788,8 @@ func (t *Tree) Set(k int, v int) {
}
case
*
d
:
i
,
ok
:=
t
.
find
(
x
,
k
)
// data page found - perform the update
t
.
hitP
=
p
t
.
hitPi
=
pi
...
...
@@ -904,9 +900,9 @@ func (t *Tree) Put(k int, upd func(oldV int, exists bool) (newV int, write bool)
t
.
hitPKminSet
,
t
.
hitPKmaxSet
=
false
,
false
for
{
i
,
ok
:=
t
.
find
(
q
,
k
)
switch
x
:=
q
.
(
type
)
{
case
*
x
:
i
,
ok
:=
t
.
findX
(
x
,
k
)
if
ok
{
i
++
}
...
...
@@ -934,6 +930,8 @@ func (t *Tree) Put(k int, upd func(oldV int, exists bool) (newV int, write bool)
}
case
*
d
:
i
,
ok
:=
t
.
find
(
x
,
k
)
// data page found - perform the update
t
.
hitP
=
p
t
.
hitPi
=
pi
...
...
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