Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
4e1a25df
Commit
4e1a25df
authored
Jun 02, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
7c1cc95d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
176 additions
and
3 deletions
+176
-3
wcfs/internal/xbtree/pptreesubset.go
wcfs/internal/xbtree/pptreesubset.go
+14
-1
wcfs/internal/xbtree/pptreesubset_test.go
wcfs/internal/xbtree/pptreesubset_test.go
+2
-2
wcfs/internal/xbtree/rangeset.go
wcfs/internal/xbtree/rangeset.go
+91
-0
wcfs/internal/xbtree/rangeset_test.go
wcfs/internal/xbtree/rangeset_test.go
+69
-0
No files found.
wcfs/internal/xbtree/pptreesubset.go
View file @
4e1a25df
...
@@ -131,7 +131,16 @@ func (S PPTreeSubSet) AddPath(path []zodb.Oid) {
...
@@ -131,7 +131,16 @@ func (S PPTreeSubSet) AddPath(path []zodb.Oid) {
}
}
}
}
// ---- Union/Difference ----
// ---- Union/Difference/Intersetctior ----
// Union returns U = PP(A.leafs | B.leafs)
//
// In other words it returns sum of A and B.
func
(
A
PPTreeSubSet
)
Union
(
B
PPTreeSubSet
)
PPTreeSubSet
{
U
:=
A
.
Clone
()
U
.
UnionInplace
(
B
)
return
U
}
// UnionInplace sets A = PP(A.leafs | B.leafs)
// UnionInplace sets A = PP(A.leafs | B.leafs)
//
//
...
@@ -151,6 +160,8 @@ func (A PPTreeSubSet) UnionInplace(B PPTreeSubSet) {
...
@@ -151,6 +160,8 @@ func (A PPTreeSubSet) UnionInplace(B PPTreeSubSet) {
A
.
xUnionInplace
(
B
)
A
.
xUnionInplace
(
B
)
}
}
// XXX Difference
// DifferenceInplace sets A = PP(A.leafs \ B.leafs)
// DifferenceInplace sets A = PP(A.leafs \ B.leafs)
//
//
// In other words it removes B nodes from A while still maintaining A as PP-connected.
// In other words it removes B nodes from A while still maintaining A as PP-connected.
...
@@ -169,6 +180,8 @@ func (A PPTreeSubSet) DifferenceInplace(B PPTreeSubSet) {
...
@@ -169,6 +180,8 @@ func (A PPTreeSubSet) DifferenceInplace(B PPTreeSubSet) {
A
.
xDifferenceInplace
(
B
)
A
.
xDifferenceInplace
(
B
)
}
}
// XXX Intersection
func
(
A
PPTreeSubSet
)
xUnionInplace
(
B
PPTreeSubSet
)
{
func
(
A
PPTreeSubSet
)
xUnionInplace
(
B
PPTreeSubSet
)
{
if
debugPPSet
{
if
debugPPSet
{
fmt
.
Printf
(
"
\n\n
xUnionInplace:
\n
"
)
fmt
.
Printf
(
"
\n\n
xUnionInplace:
\n
"
)
...
...
wcfs/internal/xbtree/pptreesubset_test.go
View file @
4e1a25df
...
@@ -33,8 +33,8 @@ func TestPPTreeSubSetOps(t *testing.T) {
...
@@ -33,8 +33,8 @@ func TestPPTreeSubSetOps(t *testing.T) {
d
d
ø
=
zodb
.
InvalidOid
ø
=
zodb
.
InvalidOid
)
)
type
S
=
PPTreeSubSet
type
S
=
PPTreeSubSet
type
testEntry
struct
{
type
testEntry
struct
{
A
,
B
S
A
,
B
S
Union
S
Union
S
Difference
S
Difference
S
...
...
wcfs/internal/xbtree/rangeset.go
0 → 100644
View file @
4e1a25df
// Copyright (C) 2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
package
xbtree
// set of [lo,hi) Key ranges.
// Range represents [lo,hi) Key range.
type
Range
struct
{
lo
Key
hi_
Key
// NOTE _not_ hi) to avoid overflow at ∞; hi = hi_ + 1
}
// RangeSet is set of non-overlapping Key ranges.
type
RangeSet
struct
{
// TODO use BTree lo->hi_ instead
rangev
[]
Range
// lo↑
}
// Add adds Range r to the set of keys.
func
(
S
*
RangeSet
)
Add
(
r
Range
)
{
panic
(
"TODO"
)
// XXX
}
// Del removes Range r from the set of keys.
func
(
S
*
RangeSet
)
Del
(
r
Range
)
{
panic
(
"TODO"
)
// XXX
}
// XXX Has?
// XXX AddKey ?
// XXX DelKey ?
// XXX HasKey
// Union returns RangeSet(A.keys | B.keys).
func
(
A
*
RangeSet
)
Union
(
B
*
RangeSet
)
*
RangeSet
{
U
:=
A
.
Clone
()
U
.
UnionInplace
(
B
)
return
U
}
// Difference returns RangeSet(A.keys \ B.keys).
func
(
A
*
RangeSet
)
Difference
(
B
*
RangeSet
)
*
RangeSet
{
D
:=
A
.
Clone
()
D
.
DifferenceInplace
(
B
)
return
D
}
// XXX Intersection
// --------
// XXX RangeSet.verify to check ranges are not overlapping and ↑
func
(
r
Range
)
String
()
string
{
slo
:=
"-∞"
;
if
rn
.
lo
>
KeyMin
{
slo
=
fmt
.
Sprintf
(
"%v"
,
rn
.
lo
)
}
shi
:=
"∞"
;
if
rn
.
hi_
<
KeyMax
{
shi
=
fmt
.
Sprintf
(
"%v"
,
rn
.
hi_
+
1
)
}
return
fmt
.
Sprintf
(
"[%s,%s)"
,
slo
,
shi
)
}
func
(
S
RangeSet
)
String
()
string
{
s
:=
"{"
for
i
,
r
:=
range
S
.
rangev
{
if
i
>
0
{
s
+=
" "
}
s
+=
r
.
String
()
}
s
+=
"}"
return
s
}
wcfs/internal/xbtree/rangeset_test.go
0 → 100644
View file @
4e1a25df
// Copyright (C) 2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
package
xbtree
import
(
"testing"
)
func
TestRangeSet
(
t
*
testing
.
T
)
{
const
(
oo
=
KeyMax
noo
=
KeyMin
)
type
testEntry
struct
{
A
,
B
*
RangeSet
Union
*
RangeSet
Difference
*
RangeSet
}
E
:=
func
(
A
,
B
,
U
,
D
*
RangeSet
)
testEntry
{
return
testEntry
{
A
,
B
,
U
,
D
}
}
// S is shorthand to create RangeSet, e.g. S(1,2, 4,5) will return {[1,2) [4,5)}
S
:=
func
(
kv
...
Key
)
*
RangeSet
{
l
:=
len
(
kv
)
if
l
%
2
!=
0
{
panic
(
"odd number of keys"
)
}
S
:=
&
RangeSet
{}
for
i
:=
0
;
i
<
l
/
2
;
i
++
{
S
.
Add
(
Range
{
kv
[
2
*
i
],
kv
[
2
*
i
+
1
]})
}
return
S
}
testv
:=
testEntry
{
E
(
S
(),
// A
S
(),
// B
S
(),
// U
S
()),
// D
E
(
S
(
1
,
2
),
// A
S
(
1
,
2
),
// B
S
(
1
,
2
),
// U
S
()),
// D
// XXX
}
}
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