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
67547ab1
Commit
67547ab1
authored
Apr 10, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
aa8accd7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
19 deletions
+19
-19
all_test.go
all_test.go
+6
-6
btree.go
btree.go
+13
-13
No files found.
all_test.go
View file @
67547ab1
...
...
@@ -27,7 +27,7 @@ var caller = func(s string, va ...interface{}) {
}
func
dbg
(
s
string
,
va
...
interface
{})
{
return
//
return
if
s
==
""
{
s
=
strings
.
Repeat
(
"%v "
,
len
(
va
))
}
...
...
@@ -223,11 +223,11 @@ func TestSetGet0(t *testing.T) {
}
func
TestSetGet1
(
t
*
testing
.
T
)
{
//
const N = 40000
const
N
=
40000
//const N = 21
const
N
=
41
//
for _, x := range []int{0, -1, 0x555555, 0xaaaaaa, 0x333333, 0xcccccc, 0x314159} {
for
_
,
x
:=
range
[]
int
{
0x314159
}
{
//
const N = 41
for
_
,
x
:=
range
[]
int
{
0
,
-
1
,
0x555555
,
0xaaaaaa
,
0x333333
,
0xcccccc
,
0x314159
}
{
//
for _, x := range []int{0x314159} {
//for _, x := range []int{0} {
r
:=
TreeNew
(
cmp
)
set
:=
r
.
Set
...
...
@@ -235,7 +235,7 @@ func TestSetGet1(t *testing.T) {
for
i
:=
range
a
{
a
[
i
]
=
(
i
^
x
)
<<
1
}
dbg
(
""
,
a
)
//
dbg("", a)
for
i
,
k
:=
range
a
{
set
(
k
,
k
^
x
)
if
g
,
e
:=
r
.
Len
(),
i
+
1
;
g
!=
e
{
...
...
btree.go
View file @
67547ab1
...
...
@@ -641,30 +641,30 @@ func (t *Tree) SeekLast() (e *Enumerator, err error) {
// Set sets the value associated with k.
func
(
t
*
Tree
)
Set
(
k
interface
{}
/*K*/
,
v
interface
{}
/*V*/
)
{
dbg
(
"--- PRE Set(%v, %v)
\t
(%v @%d, [%v/%v, %v/%v), %v @%d)
\n
%s"
,
k
,
v
,
t
.
hit
,
t
.
hitIdx
,
t
.
hitMinKMInf
,
t
.
hitMinK
,
t
.
hitMaxKInf
,
t
.
hitMaxK
,
t
.
hitP
,
t
.
hitPi
,
t
.
dump
())
defer
func
()
{
//if r := recover(); r != nil {
// panic(r)
//}
dbg
(
"--- POST
\n
%s
\n
====
\n
"
,
t
.
dump
())
}()
//
dbg("--- PRE Set(%v, %v)\t(%v @%d, [%v/%v, %v/%v), %v @%d)\n%s", k, v, t.hit, t.hitIdx, t.hitMinKMInf, t.hitMinK, t.hitMaxKInf, t.hitMaxK, t.hitP, t.hitPi, t.dump())
//
defer func() {
//
//if r := recover(); r != nil {
//
// panic(r)
//
//}
//
dbg("--- POST\n%s\n====\n", t.dump())
//
}()
// check if we can do the update nearby previous change
i
,
ok
:=
t
.
hitFind
(
k
)
if
i
>=
0
{
dbg
(
"hit found
\t
-> %d, %v"
,
i
,
ok
)
//
dbg("hit found\t-> %d, %v", i, ok)
//dd, p, pi := t.hit, t.hitP, t.hitPi
dd
:=
t
.
hit
switch
{
case
ok
:
dbg
(
"ok'"
)
//
dbg("ok'")
dd
.
d
[
i
]
.
v
=
v
t
.
hitIdx
=
i
return
case
dd
.
c
<
2
*
kd
:
dbg
(
"insert'"
)
//
dbg("insert'")
t
.
insert
(
dd
,
i
,
k
,
v
)
return
...
...
@@ -733,7 +733,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
// data page found - perform the update
switch
{
case
ok
:
dbg
(
"ok"
)
//
dbg("ok")
x
.
d
[
i
]
.
v
=
v
t
.
hit
,
t
.
hitIdx
=
x
,
i
t
.
hitP
,
t
.
hitPi
=
p
,
pi
...
...
@@ -743,7 +743,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
t
.
hitMaxKInf
=
maxKInf
case
x
.
c
<
2
*
kd
:
dbg
(
"insert"
)
//
dbg("insert")
t
.
insert
(
x
,
i
,
k
,
v
)
t
.
hitP
,
t
.
hitPi
=
p
,
pi
t
.
hitMinK
=
minK
...
...
@@ -752,7 +752,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
t
.
hitMaxKInf
=
maxKInf
default
:
dbg
(
"overflow"
)
//
dbg("overflow")
t
.
overflow
(
p
,
x
,
pi
,
i
,
k
,
v
)
t
.
hitMinK
=
minK
t
.
hitMinKMInf
=
minKMInf
...
...
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