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
5939d29c
Commit
5939d29c
authored
Apr 10, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
6fbd5ad7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
47 deletions
+36
-47
all_test.go
all_test.go
+4
-3
btree.go
btree.go
+32
-44
No files found.
all_test.go
View file @
5939d29c
...
...
@@ -598,8 +598,8 @@ func TestDelete0(t *testing.T) {
}
func
TestDelete1
(
t
*
testing
.
T
)
{
//
const N = 130000
const
N
=
40
const
N
=
130000
//
const N = 40
for
_
,
x
:=
range
[]
int
{
0
,
-
1
,
0x555555
,
0xaaaaaa
,
0x333333
,
0xcccccc
,
0x314159
}
{
r
:=
TreeNew
(
cmp
)
set
:=
r
.
Set
...
...
@@ -608,7 +608,8 @@ func TestDelete1(t *testing.T) {
a
[
i
]
=
(
i
^
x
)
<<
1
}
for
_
,
k
:=
range
a
{
set
(
k
,
k
)
set
(
k
,
0
)
//set(k, k)
}
for
i
,
k
:=
range
a
{
...
...
btree.go
View file @
5939d29c
...
...
@@ -11,10 +11,10 @@ import (
)
const
(
//
kx = 32 //TODO benchmark tune this number if using custom key/value type(s).
//
kd = 32 //TODO benchmark tune this number if using custom key/value type(s).
kx
=
2
//TODO benchmark tune this number if using custom key/value type(s).
kd
=
2
//TODO benchmark tune this number if using custom key/value type(s).
kx
=
32
//TODO benchmark tune this number if using custom key/value type(s).
kd
=
32
//TODO benchmark tune this number if using custom key/value type(s).
//
kx = 2 //TODO benchmark tune this number if using custom key/value type(s).
//
kd = 2 //TODO benchmark tune this number if using custom key/value type(s).
)
func
init
()
{
...
...
@@ -620,66 +620,54 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
pi
:=
-
1
var
p
*
x
var
dd
*
d
// XXX naming
q
:=
t
.
r
if
q
==
nil
{
z
:=
t
.
insert
(
btDPool
.
Get
()
.
(
*
d
),
0
,
k
,
v
)
// XXX update hit
t
.
r
,
t
.
first
,
t
.
last
=
z
,
z
,
z
return
}
// check if we can do the update nearby previous change
i
,
ok
:=
t
.
hitFind
(
k
)
if
i
>=
0
{
println
(
"NEVER"
)
println
(
"NEVER"
)
println
(
"NEVER"
)
dd
,
p
,
pi
=
t
.
hit
,
t
.
hitP
,
t
.
hitPi
}
for
{
// data page found
if
dd
!=
nil
{
if
ok
{
dd
.
d
[
i
]
.
v
=
v
}
else
{
switch
{
case
dd
.
c
<
2
*
kd
:
t
.
insert
(
dd
,
i
,
k
,
v
)
default
:
t
.
overflow
(
p
,
dd
,
pi
,
i
,
k
,
v
)
}
}
// data page not found yet - search and descent
}
else
{
q
:=
t
.
r
if
q
==
nil
{
z
:=
t
.
insert
(
btDPool
.
Get
()
.
(
*
d
),
0
,
k
,
v
)
// XXX update hit
t
.
r
,
t
.
first
,
t
.
last
=
z
,
z
,
z
return
}
// data page not found yet - sarch and descent
i
,
ok
=
t
.
find
(
q
,
k
)
if
ok
{
loop
:
for
{
i
,
ok
=
t
.
find
(
q
,
k
)
switch
x
:=
q
.
(
type
)
{
case
*
x
:
if
x
.
c
>
2
*
kx
{
x
,
i
=
t
.
splitX
(
p
,
x
,
pi
,
i
)
}
pi
=
i
+
1
p
=
x
q
=
x
.
x
[
i
+
1
]
.
ch
if
ok
{
pi
=
i
+
1
q
=
x
.
x
[
i
+
1
]
.
ch
}
else
{
pi
=
i
q
=
x
.
x
[
i
]
.
ch
}
case
*
d
:
dd
=
x
break
loop
}
continue
}
}
switch
x
:=
q
.
(
type
)
{
case
*
x
:
if
x
.
c
>
2
*
kx
{
x
,
i
=
t
.
splitX
(
p
,
x
,
pi
,
i
)
}
pi
=
i
p
=
x
q
=
x
.
x
[
i
]
.
ch
case
*
d
:
dd
=
x
// data page found - perform the update
if
ok
{
dd
.
d
[
i
]
.
v
=
v
}
else
{
switch
{
case
dd
.
c
<
2
*
kd
:
t
.
insert
(
dd
,
i
,
k
,
v
)
default
:
t
.
overflow
(
p
,
dd
,
pi
,
i
,
k
,
v
)
}
}
}
...
...
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