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
aa8accd7
Commit
aa8accd7
authored
Apr 10, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
6397d666
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
23 deletions
+47
-23
all_test.go
all_test.go
+2
-1
btree.go
btree.go
+45
-22
No files found.
all_test.go
View file @
aa8accd7
...
...
@@ -27,6 +27,7 @@ var caller = func(s string, va ...interface{}) {
}
func
dbg
(
s
string
,
va
...
interface
{})
{
return
if
s
==
""
{
s
=
strings
.
Repeat
(
"%v "
,
len
(
va
))
}
...
...
@@ -234,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 @
aa8accd7
...
...
@@ -41,6 +41,7 @@ func (p *btTpool) get(cmp Cmp) *Tree {
x
.
cmp
=
cmp
x
.
hitIdx
=
-
1
x
.
hitPi
=
-
1
x
.
hitMinKMInf
=
true
x
.
hitMaxKInf
=
true
return
x
}
...
...
@@ -108,8 +109,10 @@ type (
hitP
*
x
hitPi
int
hitMaxK
interface
{}
/*K*/
hitMaxKInf
bool
// whether hitMaxK = ∞
hitMinK
interface
{}
/*K*/
hitMinKMInf
bool
// whether hitMinK = -∞
hitMaxK
interface
{}
/*K*/
hitMaxKInf
bool
// whether hitMaxK = +∞
}
xe
struct
{
// x element
...
...
@@ -434,8 +437,8 @@ func (t *Tree) hitFind(k interface{} /*K*/) (i int, ok bool) {
}
i
=
t
.
hitIdx
p
:=
t
.
hitP
pi
:=
t
.
hitPi
//
p := t.hitP
//
pi := t.hitPi
switch
cmp
:=
t
.
cmp
(
k
,
hit
.
d
[
i
]
.
k
);
{
case
cmp
>
0
:
...
...
@@ -461,8 +464,12 @@ func (t *Tree) hitFind(k interface{} /*K*/) (i int, ok bool) {
*/
case
cmp
<
0
:
// in hit range: >= pprev.k
if
p
!=
nil
&&
pi
>
0
&&
t
.
cmp
(
k
,
p
.
x
[
pi
-
1
]
.
k
)
<
0
{
// // in hit range: >= pprev.k
// if p != nil && pi > 0 && t.cmp(k, p.x[pi-1].k) < 0 {
// return -1, false
// }
if
!
(
t
.
hitMinKMInf
||
t
.
cmp
(
k
,
t
.
hitMinK
)
>=
0
)
{
return
-
1
,
false
}
...
...
@@ -634,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 @%d)\n%s", k, v, t.hit, t.hitIdx
, 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
...
...
@@ -684,8 +691,8 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
return
}
var
maxK
interface
{}
/*K*/
// XXX max key limiting found hit range
m
axKInf
:=
true
// if there will be no limiting factors ... XXX
var
m
inK
,
m
axK
interface
{}
/*K*/
// XXX max key limiting found hit range
m
inKMInf
,
maxKInf
:=
true
,
true
// if there will be no limiting factors ... XXX
for
{
i
,
ok
=
t
.
find
(
q
,
k
)
...
...
@@ -703,12 +710,22 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
p
=
x
q
=
p
.
x
[
pi
]
.
ch
if
pi
>
0
{
minK
=
p
.
x
[
pi
-
1
]
.
k
minKMInf
=
false
}
if
pi
<
p
.
c
{
maxK
=
p
.
x
[
pi
]
.
k
maxKInf
=
false
}
if
minK
!=
nil
&&
minKMInf
{
dbg
(
"MINK WRONG"
,
pi
,
minK
)
panic
(
minK
)
}
if
maxK
!=
nil
&&
maxKInf
{
dbg
(
""
,
pi
,
maxK
)
dbg
(
"
MAXK WRONG
"
,
pi
,
maxK
)
panic
(
maxK
)
}
...
...
@@ -716,23 +733,29 @@ 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
t
.
hitMinK
=
minK
t
.
hitMinKMInf
=
minKMInf
t
.
hitMaxK
=
maxK
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
t
.
hitMinKMInf
=
minKMInf
t
.
hitMaxK
=
maxK
t
.
hitMaxKInf
=
maxKInf
default
:
//
dbg("overflow")
dbg
(
"overflow"
)
t
.
overflow
(
p
,
x
,
pi
,
i
,
k
,
v
)
t
.
hitMinK
=
minK
t
.
hitMinKMInf
=
minKMInf
t
.
hitMaxK
=
maxK
t
.
hitMaxKInf
=
maxKInf
}
...
...
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