Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
code
PMem-based Data Structures
Commits
4adcc20d
Commit
4adcc20d
authored
Jul 17, 2019
by
Philipp Götze
Browse files
🐞
Fixed a bug during merge by forbidding odd branch nodes sizes
parent
a82ebe93
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
src/fptree/CMakeLists.txt
View file @
4adcc20d
project
(
fptree
)
include_directories
(
${
PROJECT_SOURCE_DIR
}
${
THIRD_PARTY_DIR
}
)
include_directories
(
${
PROJECT_SOURCE_DIR
}
)
get_property
(
I_DIRS DIRECTORY
${
CMAKE_CURRENT_SOURCE_DIR
}
PROPERTY INCLUDE_DIRECTORIES
)
set
(
TEST_INCLUDE_DIRS
${
TEST_INCLUDE_DIRS
}
${
I_DIRS
}
...
...
src/fptree/FPTree.hpp
View file @
4adcc20d
...
...
@@ -53,8 +53,10 @@ using pptr = persistent_ptr<Object>;
*/
template
<
typename
KeyType
,
typename
ValueType
,
int
N
,
int
M
>
class
FPTree
{
/// we need at least t
wo
keys on a branch node to be able to split
/// we need at least t
hree
keys on a branch node to be able to split
static_assert
(
N
>
2
,
"number of branch keys has to be >2."
);
/// we need an even order for branch nodes to be able to merge
static_assert
(
N
%
2
==
0
,
"order of branch nodes must be even."
);
/// we need at least one key on a leaf node
static_assert
(
M
>
0
,
"number of leaf keys should be >0."
);
...
...
@@ -593,7 +595,7 @@ class FPTree {
* down to the leaf level starting at node @c node at depth @c depth.
*
* @param node the starting node for the insert
* @param d
epth
the current depth of the tree (0 == leaf level)
* @param d the current depth of the tree (0 == leaf level)
* @param key the key of the element
* @param val the actual value corresponding to the key
* @param splitInfo information about the split
...
...
@@ -887,8 +889,6 @@ class FPTree {
assert
(
node
!=
nullptr
);
assert
(
child
!=
nullptr
);
auto
&
nodeRef
=
*
node
;
auto
&
childRef
=
*
child
;
auto
newChild
=
child
;
constexpr
auto
middle
=
(
N
+
1
)
/
2
;
/// 1. we check whether we can rebalance with one of the siblings
...
...
@@ -1162,7 +1162,7 @@ class FPTree {
*
* @param leaf the leaf to insert
*/
void
recoveryInsert
(
const
pptr
<
LeafNode
>
&
leaf
){
void
recoveryInsert
(
const
pptr
<
LeafNode
>
&
leaf
)
{
assert
(
depth
>
0
);
assert
(
leaf
!=
nullptr
);
...
...
@@ -1194,7 +1194,7 @@ class FPTree {
* @return true if a split was performed
*/
bool
recoveryInsertInBranchNode
(
BranchNode
*
const
node
,
const
int
curr_depth
,
const
pptr
<
LeafNode
>
&
leaf
,
SplitInfo
*
splitInfo
){
const
pptr
<
LeafNode
>
&
leaf
,
SplitInfo
*
splitInfo
)
{
auto
&
nodeRef
=
*
node
;
auto
&
leafRef
=
*
leaf
;
auto
&
splitRef
=
*
splitInfo
;
...
...
src/pbptree/BitPBPTree.hpp
View file @
4adcc20d
...
...
@@ -52,6 +52,8 @@ template<typename KeyType, typename ValueType, size_t N, size_t M>
class
BitPBPTree
{
/// we need at least two keys on a branch node to be able to split
static_assert
(
N
>
2
,
"number of branch keys has to be >2."
);
/// we need an even order for branch nodes to be able to merge
static_assert
(
N
%
2
==
0
,
"order of branch nodes must be even."
);
/// we need at least one key on a leaf node
static_assert
(
M
>
0
,
"number of leaf keys should be >0."
);
...
...
@@ -181,7 +183,6 @@ class BitPBPTree {
currentPosition
=
0
;
const
auto
&
nodeRef
=
*
currentNode
;
while
(
!
nodeRef
.
bits
.
get_ro
().
test
(
currentPosition
))
++
currentPosition
;
}
iterator
&
operator
++
()
{
...
...
src/pbptree/CMakeLists.txt
View file @
4adcc20d
project
(
pbptree
)
include_directories
(
${
PROJECT_SOURCE_DIR
}
${
THIRD_PARTY_DIR
}
)
include_directories
(
${
PROJECT_SOURCE_DIR
}
)
get_property
(
I_DIRS DIRECTORY
${
CMAKE_CURRENT_SOURCE_DIR
}
PROPERTY INCLUDE_DIRECTORIES
)
set
(
TEST_INCLUDE_DIRS
${
TEST_INCLUDE_DIRS
}
${
I_DIRS
}
...
...
@@ -13,6 +12,7 @@ set(TEST_INCLUDE_DIRS ${TEST_INCLUDE_DIRS}
################
#
set
(
PROJECT_INCLUDES_F
${
PROJECT_INCLUDES_F
}
${
CMAKE_CURRENT_SOURCE_DIR
}
/BitPBPTree.hpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/PBPTree.hpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/UnsortedPBPTree.hpp
PARENT_SCOPE
)
src/pbptree/PBPTree.hpp
View file @
4adcc20d
...
...
@@ -52,6 +52,8 @@ template <typename KeyType, typename ValueType, int N, int M>
class
PBPTree
{
/// we need at least two keys on a branch node to be able to split
static_assert
(
N
>
2
,
"number of branch keys has to be >2."
);
/// we need an even order for branch nodes to be able to merge
static_assert
(
N
%
2
==
0
,
"order of branch nodes must be even."
);
/// we need at least one key on a leaf node
static_assert
(
M
>
0
,
"number of leaf keys should be >0."
);
...
...
@@ -382,7 +384,7 @@ class PBPTree {
auto
&
nodeRef
=
*
node
;
assert
(
pos
<=
nodeRef
.
numKeys
.
get_ro
());
const
auto
&
leafRef
=
*
leaf
;
const
auto
prevNumKeys
=
leafRef
.
prevLeaf
->
numKeys
.
get_ro
();
const
auto
prevNumKeys
=
pos
>
0
?
leafRef
.
prevLeaf
->
numKeys
.
get_ro
()
:
0
;
constexpr
auto
middle
=
(
M
+
1
)
/
2
;
/// 1. we check whether we can rebalance with one of the siblings but only if both nodes have
/// the same direct parent
...
...
@@ -573,7 +575,7 @@ class PBPTree {
sibRef
.
keys
.
get_rw
()[
sibRef
.
numKeys
.
get_ro
()
+
i
+
1
]
=
nodeRef
.
keys
.
get_ro
()[
i
];
sibRef
.
children
.
get_rw
()[
sibRef
.
numKeys
.
get_ro
()
+
i
+
2
]
=
nodeRef
.
children
.
get_ro
()[
i
+
1
];
}
sibRef
.
numKeys
.
get_rw
()
=
sibRef
.
numKeys
.
get_ro
()
+
nodeRef
.
numKeys
.
get_ro
()
+
1
;
sibRef
.
numKeys
.
get_rw
()
+
=
nodeRef
.
numKeys
.
get_ro
()
+
1
;
}
/**
...
...
@@ -973,7 +975,7 @@ class PBPTree {
/// the child node was split, thus we have to add a new entry to our branch node
if
(
nodeRef
.
numKeys
.
get_ro
()
==
N
)
{
splitBranchNode
(
node
,
childSplitInfo
.
key
,
splitInfo
);
const
auto
splitRef
=
*
splitInfo
;
const
auto
&
splitRef
=
*
splitInfo
;
host
=
(
key
<
splitRef
.
key
?
splitRef
.
leftChild
:
splitRef
.
rightChild
).
branch
;
split
=
true
;
pos
=
lookupPositionInBranchNode
(
host
,
key
);
...
...
src/pbptree/UnsortedPBPTree.hpp
View file @
4adcc20d
...
...
@@ -52,6 +52,8 @@ template<typename KeyType, typename ValueType, int N, int M>
class
UnsortedPBPTree
{
/// we need at least two keys on a branch node to be able to split
static_assert
(
N
>
2
,
"number of branch keys has to be >2."
);
/// we need an even order for branch nodes to be able to merge
static_assert
(
N
%
2
==
0
,
"order of branch nodes must be even."
);
/// we need at least one key on a leaf node
static_assert
(
M
>
0
,
"number of leaf keys should be >0."
);
...
...
@@ -614,7 +616,7 @@ class UnsortedPBPTree {
sibRef
.
keys
.
get_rw
()[
sibRef
.
numKeys
.
get_ro
()
+
i
+
1
]
=
nodeRef
.
keys
.
get_ro
()[
i
];
sibRef
.
children
.
get_rw
()[
sibRef
.
numKeys
.
get_ro
()
+
i
+
2
]
=
nodeRef
.
children
.
get_ro
()[
i
+
1
];
}
sibRef
.
numKeys
.
get_rw
()
=
sibRef
.
numKeys
.
get_ro
()
+
nodeRef
.
numKeys
.
get_ro
()
+
1
;
sibRef
.
numKeys
.
get_rw
()
+
=
nodeRef
.
numKeys
.
get_ro
()
+
1
;
}
/**
...
...
src/wbtree/CMakeLists.txt
View file @
4adcc20d
project
(
wbptree
)
include_directories
(
${
PROJECT_SOURCE_DIR
}
${
THIRD_PARTY_DIR
}
)
include_directories
(
${
PROJECT_SOURCE_DIR
}
)
get_property
(
I_DIRS DIRECTORY
${
CMAKE_CURRENT_SOURCE_DIR
}
PROPERTY INCLUDE_DIRECTORIES
)
set
(
TEST_INCLUDE_DIRS
${
TEST_INCLUDE_DIRS
}
${
I_DIRS
}
...
...
src/wbtree/wBPTree.hpp
View file @
4adcc20d
...
...
@@ -54,6 +54,8 @@ template<typename KeyType, typename ValueType, int N, int M>
class
wBPTree
{
/// we need at least two keys on a branch node to be able to split
static_assert
(
N
>
2
,
"number of branch keys has to be >2."
);
/// we need an even order for branch nodes to be able to merge
static_assert
(
N
%
2
==
0
,
"order of branch nodes must be even."
);
/// we need at least one key on a leaf node
static_assert
(
M
>
0
,
"number of leaf keys should be >0."
);
...
...
@@ -268,8 +270,8 @@ class wBPTree {
*/
wBPTree
()
:
depth
(
0
)
{
rootNode
=
newLeafNode
();
LOG
(
"created new wBPTree with sizeof(BranchNode) = "
<<
sizeof
(
BranchNode
)
<<
", sizeof(LeafNode) = "
<<
sizeof
(
LeafNode
));
LOG
(
"created new wBPTree with sizeof(BranchNode) = "
<<
sizeof
(
BranchNode
)
<<
", sizeof(LeafNode) = "
<<
sizeof
(
LeafNode
));
}
/**
...
...
@@ -379,9 +381,9 @@ class wBPTree {
auto
node
=
rootNode
;
auto
d
=
depth
.
get_ro
();
while
(
d
--
>
0
)
node
=
node
.
branch
->
children
.
get_ro
()[
0
];
auto
leaf
=
*
node
.
leaf
;
auto
&
leafRef
=
*
leaf
;
auto
leaf
=
node
.
leaf
;
while
(
leaf
!=
nullptr
)
{
auto
&
leafRef
=
*
leaf
;
/// for each key-value pair call func
for
(
auto
i
=
0u
;
i
<
M
;
i
++
)
{
if
(
!
leafRef
.
search
.
get_ro
().
b
.
test
(
i
))
continue
;
...
...
@@ -403,11 +405,11 @@ class wBPTree {
* @param func the function called for each entry
*/
void
scan
(
const
KeyType
&
minKey
,
const
KeyType
&
maxKey
,
ScanFunc
func
)
const
{
const
auto
leaf
=
findLeafNode
(
minKey
);
auto
&
leafRef
=
*
leaf
;
auto
leaf
=
findLeafNode
(
minKey
);
bool
higherThanMax
=
false
;
while
(
!
higherThanMax
&&
leaf
!=
nullptr
)
{
const
auto
&
leafRef
=
*
leaf
;
/// for each key-value pair within the range call func
for
(
auto
i
=
0u
;
i
<
M
;
i
++
)
{
if
(
!
leafRef
.
search
.
get_ro
().
b
.
test
(
i
))
continue
;
...
...
@@ -707,7 +709,7 @@ class wBPTree {
*/
auto
lookupPositionInLeafNode
(
const
pptr
<
LeafNode
>
&
node
,
const
KeyType
&
key
)
const
{
auto
pos
=
1u
;
auto
&
nodeRef
=
*
node
;
const
auto
&
nodeRef
=
*
node
;
const
auto
&
slotArray
=
nodeRef
.
search
.
get_ro
().
slot
;
const
auto
&
keys
=
nodeRef
.
keys
.
get_ro
();
auto
l
=
1
;
...
...
src/wbtree/wHBPTree.hpp
View file @
4adcc20d
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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