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
fca2bd43
Commit
fca2bd43
authored
Jul 02, 2020
by
Philipp Götze
Browse files
✨
Added custom Bitmap for individual handling of underlying words
parent
fb6ffc73
Changes
11
Expand all
Show whitespace changes
Inline
Side-by-side
bench/trees/tree_erase.cpp
View file @
fca2bd43
...
@@ -86,7 +86,7 @@ static void BM_TreeErase(benchmark::State &state) {
...
@@ -86,7 +86,7 @@ static void BM_TreeErase(benchmark::State &state) {
pop
.
drain
();
pop
.
drain
();
const
auto
pos
=
treeRef
.
lookupPositionInLeafNode
(
leaf
,
KEYPOS
);
const
auto
pos
=
treeRef
.
lookupPositionInLeafNode
(
leaf
,
KEYPOS
);
// const auto pos =
dbis::BitOperations::getFreeZero(
leaf->bits.get_ro());
// const auto pos = leaf->bits.get_ro()
.getFreeZero(
);
#ifdef ENABLE_PCM
#ifdef ENABLE_PCM
SocketCounterState
before_sstate
;
SocketCounterState
before_sstate
;
...
...
bench/trees/tree_insert.cpp
View file @
fca2bd43
...
@@ -93,7 +93,7 @@ static void BM_TreeInsert(benchmark::State &state) {
...
@@ -93,7 +93,7 @@ static void BM_TreeInsert(benchmark::State &state) {
const
auto
reqTup
=
MyTuple
(
KEYPOS
,
KEYPOS
*
100
,
KEYPOS
*
1.0
);
const
auto
reqTup
=
MyTuple
(
KEYPOS
,
KEYPOS
*
100
,
KEYPOS
*
1.0
);
const
auto
pos
=
treeRef
.
lookupPositionInLeafNode
(
leaf
,
KEYPOS
);
const
auto
pos
=
treeRef
.
lookupPositionInLeafNode
(
leaf
,
KEYPOS
);
//const auto pos =
dbis::BitOperations::getFreeZero(
leaf->bits.get_ro());
//
const auto pos = leaf->bits.get_ro()
.getFreeZero(
);
#ifdef ENABLE_PCM
#ifdef ENABLE_PCM
SocketCounterState
before_sstate
;
SocketCounterState
before_sstate
;
...
...
src/pbptrees/BitHPBPTree.hpp
View file @
fca2bd43
This diff is collapsed.
Click to expand it.
src/pbptrees/BitPBPTree.hpp
View file @
fca2bd43
...
@@ -18,10 +18,10 @@
...
@@ -18,10 +18,10 @@
#ifndef DBIS_BitPBPTree_hpp_
#ifndef DBIS_BitPBPTree_hpp_
#define DBIS_BitPBPTree_hpp_
#define DBIS_BitPBPTree_hpp_
#include
<libpmemobj/ctl.h>
#include
<array>
#include
<array>
#include
<iostream>
#include
<iostream>
#include
<libpmemobj/ctl.h>
#include
<libpmemobj++/make_persistent.hpp>
#include
<libpmemobj++/make_persistent.hpp>
#include
<libpmemobj++/p.hpp>
#include
<libpmemobj++/p.hpp>
#include
<libpmemobj++/persistent_ptr.hpp>
#include
<libpmemobj++/persistent_ptr.hpp>
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
#include
<libpmemobj++/utils.hpp>
#include
<libpmemobj++/utils.hpp>
#include
"config.h"
#include
"config.h"
#include
"utils/Bit
Operations
.hpp"
#include
"utils/Bit
map
.hpp"
#include
"utils/PersistEmulation.hpp"
#include
"utils/PersistEmulation.hpp"
#include
"utils/SearchFunctions.hpp"
#include
"utils/SearchFunctions.hpp"
...
@@ -41,7 +41,7 @@ using pmem::obj::make_persistent;
...
@@ -41,7 +41,7 @@ using pmem::obj::make_persistent;
using
pmem
::
obj
::
p
;
using
pmem
::
obj
::
p
;
using
pmem
::
obj
::
persistent_ptr
;
using
pmem
::
obj
::
persistent_ptr
;
using
pmem
::
obj
::
transaction
;
using
pmem
::
obj
::
transaction
;
template
<
typename
Object
>
template
<
typename
Object
>
using
pptr
=
persistent_ptr
<
Object
>
;
using
pptr
=
persistent_ptr
<
Object
>
;
/**
/**
...
@@ -52,7 +52,7 @@ using pptr = persistent_ptr<Object>;
...
@@ -52,7 +52,7 @@ using pptr = persistent_ptr<Object>;
* @tparam N the maximum number of keys on a branch node
* @tparam N the maximum number of keys on a branch node
* @tparam M the maximum number of keys on a leaf node
* @tparam M the maximum number of keys on a leaf node
*/
*/
template
<
typename
KeyType
,
typename
ValueType
,
size_t
N
,
size_t
M
>
template
<
typename
KeyType
,
typename
ValueType
,
size_t
N
,
size_t
M
>
class
BitPBPTree
{
class
BitPBPTree
{
/// we need at least two keys on a branch node to be able to split
/// 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."
);
static_assert
(
N
>
2
,
"number of branch keys has to be >2."
);
...
@@ -72,36 +72,43 @@ class BitPBPTree {
...
@@ -72,36 +72,43 @@ class BitPBPTree {
struct
BranchNode
;
struct
BranchNode
;
struct
Node
{
struct
Node
{
Node
()
:
tag
(
BLANK
)
{};
Node
()
:
tag
(
BLANK
){};
explicit
Node
(
const
pptr
<
LeafNode
>
&
leaf_
)
:
tag
(
LEAF
),
leaf
(
leaf_
)
{};
explicit
Node
(
const
pptr
<
LeafNode
>
&
leaf_
)
:
tag
(
LEAF
),
leaf
(
leaf_
){};
explicit
Node
(
const
pptr
<
BranchNode
>
&
branch_
)
:
tag
(
BRANCH
),
branch
(
branch_
)
{};
explicit
Node
(
const
pptr
<
BranchNode
>
&
branch_
)
:
tag
(
BRANCH
),
branch
(
branch_
){};
Node
(
const
Node
&
other
)
{
copy
(
other
);
};
Node
(
const
Node
&
other
)
{
copy
(
other
);
};
void
copy
(
const
Node
&
other
)
{
void
copy
(
const
Node
&
other
)
{
tag
=
other
.
tag
;
tag
=
other
.
tag
;
switch
(
tag
)
{
switch
(
tag
)
{
case
LEAF
:
{
case
LEAF
:
{
leaf
=
other
.
leaf
;
break
;
leaf
=
other
.
leaf
;
break
;
}
}
case
BRANCH
:
{
case
BRANCH
:
{
branch
=
other
.
branch
;
break
;
branch
=
other
.
branch
;
break
;
}
}
default:
;
default:
;
}
}
}
}
Node
&
operator
=
(
const
Node
&
other
)
{
copy
(
other
);
return
*
this
;
}
Node
&
operator
=
(
const
Node
&
other
)
{
copy
(
other
);
return
*
this
;
}
Node
&
operator
=
(
const
pptr
<
LeafNode
>
&
leaf_
)
{
Node
&
operator
=
(
const
pptr
<
LeafNode
>
&
leaf_
)
{
tag
=
LEAF
;
leaf
=
leaf_
;
return
*
this
;
tag
=
LEAF
;
leaf
=
leaf_
;
return
*
this
;
}
}
Node
&
operator
=
(
const
pptr
<
BranchNode
>
&
branch_
)
{
Node
&
operator
=
(
const
pptr
<
BranchNode
>
&
branch_
)
{
tag
=
BRANCH
;
branch
=
branch_
;
return
*
this
;
tag
=
BRANCH
;
branch
=
branch_
;
return
*
this
;
}
}
enum
NodeType
{
enum
NodeType
{
BLANK
,
LEAF
,
BRANCH
}
tag
;
BLANK
,
LEAF
,
BRANCH
}
tag
;
union
{
union
{
pptr
<
LeafNode
>
leaf
;
pptr
<
LeafNode
>
leaf
;
...
@@ -115,7 +122,6 @@ class BitPBPTree {
...
@@ -115,7 +122,6 @@ class BitPBPTree {
* A structure for representing a leaf node of a B+ tree.
* A structure for representing a leaf node of a B+ tree.
*/
*/
struct
alignas
(
64
)
LeafNode
{
struct
alignas
(
64
)
LeafNode
{
static
constexpr
auto
NUM_KEYS
=
M
;
static
constexpr
auto
NUM_KEYS
=
M
;
using
KEY_TYPE
=
KeyType
;
using
KEY_TYPE
=
KeyType
;
...
@@ -127,7 +133,7 @@ class BitPBPTree {
...
@@ -127,7 +133,7 @@ class BitPBPTree {
static
constexpr
auto
BitsetSize
=
((
M
+
63
)
/
64
)
*
8
;
///< number * size of words
static
constexpr
auto
BitsetSize
=
((
M
+
63
)
/
64
)
*
8
;
///< number * size of words
static
constexpr
auto
PaddingSize
=
(
64
-
(
BitsetSize
+
32
)
%
64
)
%
64
;
static
constexpr
auto
PaddingSize
=
(
64
-
(
BitsetSize
+
32
)
%
64
)
%
64
;
p
<
std
::
b
it
set
<
M
>>
bits
;
///< bit
set
for valid entries
p
<
dbis
::
B
it
map
<
M
>>
bits
;
///< bit
map
for valid entries
pptr
<
LeafNode
>
nextLeaf
;
///< pointer to the subsequent sibling
pptr
<
LeafNode
>
nextLeaf
;
///< pointer to the subsequent sibling
pptr
<
LeafNode
>
prevLeaf
;
///< pointer to the preceeding sibling
pptr
<
LeafNode
>
prevLeaf
;
///< pointer to the preceeding sibling
char
padding
[
PaddingSize
];
///< padding to align keys to 64 bytes
char
padding
[
PaddingSize
];
///< padding to align keys to 64 bytes
...
@@ -140,16 +146,15 @@ class BitPBPTree {
...
@@ -140,16 +146,15 @@ class BitPBPTree {
* The rightmost child is always at position N.
* The rightmost child is always at position N.
*/
*/
struct
alignas
(
64
)
BranchNode
{
struct
alignas
(
64
)
BranchNode
{
static
constexpr
auto
NUM_KEYS
=
N
;
static
constexpr
auto
NUM_KEYS
=
N
;
using
KEY_TYPE
=
KeyType
;
using
KEY_TYPE
=
KeyType
;
/**
/**
* Constructor for creating a new empty branch node.
* Constructor for creating a new empty branch node.
*/
*/
BranchNode
(){}
BranchNode
()
{}
p
<
std
::
b
it
set
<
N
>>
bits
;
///< bit
set
for valid entries
p
<
dbis
::
B
it
map
<
N
>>
bits
;
///< bit
map
for valid entries
p
<
std
::
array
<
KeyType
,
N
>>
keys
;
///< the actual keys
p
<
std
::
array
<
KeyType
,
N
>>
keys
;
///< the actual keys
p
<
std
::
array
<
Node
,
N
+
1
>>
children
;
///< pointers to child nodes (BranchNode or LeafNode)
p
<
std
::
array
<
Node
,
N
+
1
>>
children
;
///< pointers to child nodes (BranchNode or LeafNode)
};
};
...
@@ -173,7 +178,6 @@ class BitPBPTree {
...
@@ -173,7 +178,6 @@ class BitPBPTree {
This pointer is never @c nullptr. */
This pointer is never @c nullptr. */
public:
public:
/**
/**
* Iterator for iterating over the leaf nodes.
* Iterator for iterating over the leaf nodes.
*/
*/
...
@@ -193,16 +197,16 @@ class BitPBPTree {
...
@@ -193,16 +197,16 @@ class BitPBPTree {
currentNode
=
node
.
leaf
;
currentNode
=
node
.
leaf
;
currentPosition
=
0
;
currentPosition
=
0
;
const
auto
&
nodeBits
=
currentNode
->
bits
.
get_ro
();
const
auto
&
nodeBits
=
currentNode
->
bits
.
get_ro
();
while
(
!
nodeBits
.
test
(
currentPosition
))
++
currentPosition
;
while
(
!
nodeBits
.
test
(
currentPosition
))
++
currentPosition
;
}
}
iterator
&
operator
++
()
{
iterator
&
operator
++
()
{
if
(
currentPosition
>=
M
-
1
)
{
if
(
currentPosition
>=
M
-
1
)
{
currentNode
=
currentNode
->
nextLeaf
;
currentNode
=
currentNode
->
nextLeaf
;
currentPosition
=
0
;
currentPosition
=
0
;
if
(
currentNode
==
nullptr
)
return
*
this
;
if
(
currentNode
==
nullptr
)
return
*
this
;
const
auto
&
nodeBits
=
currentNode
->
bits
.
get_ro
();
const
auto
&
nodeBits
=
currentNode
->
bits
.
get_ro
();
while
(
!
nodeBits
.
test
(
currentPosition
))
{
while
(
!
nodeBits
.
test
(
currentPosition
))
{
++
currentPosition
;
++
currentPosition
;
};
};
}
else
{
}
else
{
...
@@ -241,7 +245,6 @@ class BitPBPTree {
...
@@ -241,7 +245,6 @@ class BitPBPTree {
iterator
end
()
{
return
iterator
();
}
iterator
end
()
{
return
iterator
();
}
/**
/**
* Alias for a function passed to the scan method.
* Alias for a function passed to the scan method.
*/
*/
...
@@ -253,8 +256,8 @@ class BitPBPTree {
...
@@ -253,8 +256,8 @@ class BitPBPTree {
explicit
BitPBPTree
(
struct
pobj_alloc_class_desc
_alloc
)
:
depth
(
0
),
alloc_class
(
_alloc
)
{
explicit
BitPBPTree
(
struct
pobj_alloc_class_desc
_alloc
)
:
depth
(
0
),
alloc_class
(
_alloc
)
{
// BitPBPTree() : depth(0) {
// BitPBPTree() : depth(0) {
rootNode
=
newLeafNode
();
rootNode
=
newLeafNode
();
LOG
(
"created new tree with sizeof(BranchNode) = "
<<
sizeof
(
BranchNode
)
<<
LOG
(
"created new tree with sizeof(BranchNode) = "
", sizeof(LeafNode) = "
<<
sizeof
(
LeafNode
));
<<
sizeof
(
BranchNode
)
<<
", sizeof(LeafNode) = "
<<
sizeof
(
LeafNode
));
}
}
/**
/**
...
@@ -346,11 +349,12 @@ class BitPBPTree {
...
@@ -346,11 +349,12 @@ class BitPBPTree {
* Print the structure and content of the B+ tree to stdout.
* Print the structure and content of the B+ tree to stdout.
*/
*/
void
print
()
const
{
void
print
()
const
{
if
(
depth
==
0
)
printLeafNode
(
0u
,
rootNode
.
leaf
);
if
(
depth
==
0
)
else
printBranchNode
(
0u
,
rootNode
.
branch
);
printLeafNode
(
0u
,
rootNode
.
leaf
);
else
printBranchNode
(
0u
,
rootNode
.
branch
);
}
}
/**
/**
* Perform a scan over all key-value pairs stored in the B+ tree.
* Perform a scan over all key-value pairs stored in the B+ tree.
* For each entry the given function @func is called.
* For each entry the given function @func is called.
...
@@ -404,7 +408,10 @@ class BitPBPTree {
...
@@ -404,7 +408,10 @@ class BitPBPTree {
const
auto
&
key
=
leafKeys
[
i
];
const
auto
&
key
=
leafKeys
[
i
];
if
(
key
<
minKey
)
continue
;
if
(
key
<
minKey
)
continue
;
if
(
key
>
maxKey
)
{
higherThanMax
=
true
;
continue
;
};
if
(
key
>
maxKey
)
{
higherThanMax
=
true
;
continue
;
};
const
auto
&
val
=
leafValues
[
i
];
const
auto
&
val
=
leafValues
[
i
];
func
(
key
,
val
);
func
(
key
,
val
);
...
@@ -549,7 +556,7 @@ class BitPBPTree {
...
@@ -549,7 +556,7 @@ class BitPBPTree {
const
auto
&
node2Values
=
node2Ref
.
values
.
get_ro
();
const
auto
&
node2Values
=
node2Ref
.
values
.
get_ro
();
for
(
auto
i
=
0u
;
i
<
M
;
++
i
)
{
for
(
auto
i
=
0u
;
i
<
M
;
++
i
)
{
if
(
node2Bits
.
test
(
i
))
{
if
(
node2Bits
.
test
(
i
))
{
const
auto
u
=
BitOperations
::
getFreeZero
(
node1Bits
);
const
auto
u
=
node1Bits
.
getFreeZero
();
node1Keys
[
u
]
=
node2Keys
[
i
];
node1Keys
[
u
]
=
node2Keys
[
i
];
node1Values
[
u
]
=
node2Values
[
i
];
node1Values
[
u
]
=
node2Values
[
i
];
node1Bits
.
set
(
u
);
node1Bits
.
set
(
u
);
...
@@ -597,7 +604,7 @@ class BitPBPTree {
...
@@ -597,7 +604,7 @@ class BitPBPTree {
/// move from one node to a node with larger keys
/// move from one node to a node with larger keys
for
(
auto
i
=
0u
;
i
<
toMove
;
++
i
)
{
for
(
auto
i
=
0u
;
i
<
toMove
;
++
i
)
{
const
auto
max
=
findMaxKeyPos
(
donorKeys
,
donorBits
);
const
auto
max
=
findMaxKeyPos
(
donorKeys
,
donorBits
);
const
auto
u
=
BitOperations
::
getFreeZero
(
receiverBits
);
const
auto
u
=
receiverBits
.
getFreeZero
(
);
/// move the donor's maximum key to the receiver
/// move the donor's maximum key to the receiver
receiverKeys
[
u
]
=
donorKeys
[
max
];
receiverKeys
[
u
]
=
donorKeys
[
max
];
receiverValues
[
u
]
=
donorValues
[
max
];
receiverValues
[
u
]
=
donorValues
[
max
];
...
@@ -608,7 +615,7 @@ class BitPBPTree {
...
@@ -608,7 +615,7 @@ class BitPBPTree {
/// move from one node to a node with smaller keys
/// move from one node to a node with smaller keys
for
(
auto
i
=
0u
;
i
<
toMove
;
++
i
)
{
for
(
auto
i
=
0u
;
i
<
toMove
;
++
i
)
{
const
auto
min
=
findMinKeyPos
(
donorKeys
,
donorBits
);
const
auto
min
=
findMinKeyPos
(
donorKeys
,
donorBits
);
const
auto
u
=
BitOperations
::
getFreeZero
(
receiverBits
);
const
auto
u
=
receiverBits
.
getFreeZero
(
);
/// move the donor's minimum key to the receiver
/// move the donor's minimum key to the receiver
receiverKeys
[
u
]
=
donorKeys
[
min
];
receiverKeys
[
u
]
=
donorKeys
[
min
];
receiverValues
[
u
]
=
donorValues
[
min
];
receiverValues
[
u
]
=
donorValues
[
min
];
...
@@ -689,7 +696,7 @@ class BitPBPTree {
...
@@ -689,7 +696,7 @@ class BitPBPTree {
const
auto
&
nodeChilds
=
nodeRef
.
children
.
get_ro
();
const
auto
&
nodeChilds
=
nodeRef
.
children
.
get_ro
();
auto
&
nodeBits
=
nodeRef
.
bits
.
get_rw
();
auto
&
nodeBits
=
nodeRef
.
bits
.
get_rw
();
const
auto
nMinKeyPos
=
findMinKeyPos
(
nodeKeys
,
nodeBits
);
const
auto
nMinKeyPos
=
findMinKeyPos
(
nodeKeys
,
nodeBits
);
const
auto
prevPos
=
findMaxKeyPosSmallerThan
(
nodeKeys
,
nodeBits
,
nodeKeys
[
pos
]);
//could be N
const
auto
prevPos
=
findMaxKeyPosSmallerThan
(
nodeKeys
,
nodeBits
,
nodeKeys
[
pos
]);
//
could be N
const
auto
prevNumKeys
=
nodeChilds
[
prevPos
].
branch
->
bits
.
get_ro
().
count
();
const
auto
prevNumKeys
=
nodeChilds
[
prevPos
].
branch
->
bits
.
get_ro
().
count
();
const
auto
nextPos
=
findMinKeyPosGreaterThan
(
nodeKeys
,
nodeBits
,
nodeKeys
[
pos
]);
const
auto
nextPos
=
findMinKeyPosGreaterThan
(
nodeKeys
,
nodeBits
,
nodeKeys
[
pos
]);
const
auto
nextNumKeys
=
nodeChilds
[
nextPos
].
branch
->
bits
.
get_ro
().
count
();
const
auto
nextNumKeys
=
nodeChilds
[
nextPos
].
branch
->
bits
.
get_ro
().
count
();
...
@@ -715,8 +722,7 @@ class BitPBPTree {
...
@@ -715,8 +722,7 @@ class BitPBPTree {
mergeBranchNodes
(
lSibling
,
nodeKeys
[
pos
],
child
);
mergeBranchNodes
(
lSibling
,
nodeKeys
[
pos
],
child
);
deleteBranchNode
(
child
);
deleteBranchNode
(
child
);
nodeBits
.
reset
(
pos
);
nodeBits
.
reset
(
pos
);
if
(
pos
==
N
)
if
(
pos
==
N
)
nodeRef
.
children
.
get_rw
()[
N
]
=
child
;
///< new rightmost child
nodeRef
.
children
.
get_rw
()[
N
]
=
child
;
///< new rightmost child
return
lSibling
;
return
lSibling
;
}
else
if
(
pos
<
N
&&
nextNumKeys
<=
middle
)
{
}
else
if
(
pos
<
N
&&
nextNumKeys
<=
middle
)
{
/// merge from right
/// merge from right
...
@@ -758,13 +764,13 @@ class BitPBPTree {
...
@@ -758,13 +764,13 @@ class BitPBPTree {
assert
(
key
<=
nodeKeys
[
findMinKeyPos
(
nodeKeys
,
nodeBits
)]);
assert
(
key
<=
nodeKeys
[
findMinKeyPos
(
nodeKeys
,
nodeBits
)]);
assert
(
sibKeys
[
findMaxKeyPos
(
sibKeys
,
sibBits
)]
<
key
);
assert
(
sibKeys
[
findMaxKeyPos
(
sibKeys
,
sibBits
)]
<
key
);
auto
u
=
BitOperations
::
getFreeZero
(
sibBits
);
auto
u
=
sibBits
.
getFreeZero
();
sibKeys
[
u
]
=
key
;
sibKeys
[
u
]
=
key
;
sibChilds
[
u
]
=
sibChilds
[
N
];
sibChilds
[
u
]
=
sibChilds
[
N
];
sibBits
.
set
(
u
);
sibBits
.
set
(
u
);
for
(
auto
i
=
0u
;
i
<
M
;
++
i
)
{
for
(
auto
i
=
0u
;
i
<
M
;
++
i
)
{
if
(
nodeBits
.
test
(
i
))
{
if
(
nodeBits
.
test
(
i
))
{
u
=
BitOperations
::
getFreeZero
(
sibBits
);
u
=
sibBits
.
getFreeZero
();
sibKeys
[
u
]
=
nodeKeys
[
i
];
sibKeys
[
u
]
=
nodeKeys
[
i
];
sibChilds
[
u
]
=
nodeChilds
[
i
];
sibChilds
[
u
]
=
nodeChilds
[
i
];
sibBits
.
set
(
u
);
sibBits
.
set
(
u
);
...
@@ -804,17 +810,16 @@ class BitPBPTree {
...
@@ -804,17 +810,16 @@ class BitPBPTree {
if
(
toMove
==
0
)
return
;
if
(
toMove
==
0
)
return
;
/// 1. move from one node to a node with larger keys
/// 1. move from one node to a node with larger keys
if
(
donorKeys
[
BitOperations
::
getFirstSet
(
donorBits
)]
<
if
(
donorKeys
[
donorBits
.
getFirstSet
()]
<
receiverKeys
[
receiverBits
.
getFirstSet
()])
{
receiverKeys
[
BitOperations
::
getFirstSet
(
receiverBits
)])
{
/// 1.1. copy parent key and rightmost child from donor
/// 1.1. copy parent key and rightmost child from donor
auto
u
=
BitOperations
::
getFreeZero
(
receiverBits
);
auto
u
=
receiverBits
.
getFreeZero
(
);
receiverKeys
[
u
]
=
parentKeys
[
pos
];
receiverKeys
[
u
]
=
parentKeys
[
pos
];
receiverChilds
[
u
]
=
donorChilds
[
N
];
receiverChilds
[
u
]
=
donorChilds
[
N
];
receiverBits
.
set
(
u
);
receiverBits
.
set
(
u
);
/// 1.2. move toMove-1 keys/children from donor to receiver
/// 1.2. move toMove-1 keys/children from donor to receiver
for
(
auto
i
=
1u
;
i
<
toMove
;
++
i
)
{
for
(
auto
i
=
1u
;
i
<
toMove
;
++
i
)
{
const
auto
max
=
findMaxKeyPos
(
donorKeys
,
donorBits
);
const
auto
max
=
findMaxKeyPos
(
donorKeys
,
donorBits
);
u
=
BitOperations
::
getFreeZero
(
receiverBits
);
u
=
receiverBits
.
getFreeZero
(
);
receiverKeys
[
u
]
=
donorKeys
[
max
];
receiverKeys
[
u
]
=
donorKeys
[
max
];
receiverChilds
[
u
]
=
donorChilds
[
max
];
receiverChilds
[
u
]
=
donorChilds
[
max
];
receiverBits
.
set
(
u
);
receiverBits
.
set
(
u
);
...
@@ -829,13 +834,13 @@ class BitPBPTree {
...
@@ -829,13 +834,13 @@ class BitPBPTree {
/// 2. move from one node to a node with smaller keys
/// 2. move from one node to a node with smaller keys
}
else
{
}
else
{
/// 2.1. copy parent key and rightmost child of receiver
/// 2.1. copy parent key and rightmost child of receiver
auto
u
=
BitOperations
::
getFreeZero
(
receiverBits
);
auto
u
=
receiverBits
.
getFreeZero
(
);
receiverKeys
[
u
]
=
parentKeys
[
pos
];
receiverKeys
[
u
]
=
parentKeys
[
pos
];
receiverChilds
[
u
]
=
receiverChilds
[
N
];
receiverChilds
[
u
]
=
receiverChilds
[
N
];
receiverBits
.
set
(
u
);
receiverBits
.
set
(
u
);
/// 2.2. move toMove-1 keys/children from donor to receiver
/// 2.2. move toMove-1 keys/children from donor to receiver
for
(
auto
i
=
1u
;
i
<
toMove
;
++
i
)
{
for
(
auto
i
=
1u
;
i
<
toMove
;
++
i
)
{
u
=
BitOperations
::
getFreeZero
(
receiverBits
);
u
=
receiverBits
.
getFreeZero
(
);
const
auto
min
=
findMinKeyPos
(
donorKeys
,
donorBits
);
const
auto
min
=
findMinKeyPos
(
donorKeys
,
donorBits
);
receiverKeys
[
u
]
=
donorKeys
[
min
];
receiverKeys
[
u
]
=
donorKeys
[
min
];
receiverChilds
[
u
]
=
donorChilds
[
min
];
receiverChilds
[
u
]
=
donorChilds
[
min
];
...
@@ -874,7 +879,7 @@ class BitPBPTree {
...
@@ -874,7 +879,7 @@ class BitPBPTree {
nodeRef
.
values
.
get_rw
()[
pos
]
=
val
;
nodeRef
.
values
.
get_rw
()[
pos
]
=
val
;
return
false
;
return
false
;
}
}
const
auto
u
=
BitOperations
::
getFreeZero
(
nodeRef
.
bits
.
get_ro
());
const
auto
u
=
nodeRef
.
bits
.
get_ro
()
.
getFreeZero
(
);
if
(
u
==
M
)
{
if
(
u
==
M
)
{
/// split the node
/// split the node
splitLeafNode
(
node
,
splitInfo
);
splitLeafNode
(
node
,
splitInfo
);
...
@@ -884,14 +889,15 @@ class BitPBPTree {
...
@@ -884,14 +889,15 @@ class BitPBPTree {
/// insert the new entry
/// insert the new entry
if
(
key
>
splitRef
.
key
)
{
if
(
key
>
splitRef
.
key
)
{
insertInLeafNodeAtPosition
(
sibling
,
BitOperations
::
getFreeZero
(
sibRef
.
bits
.
get_ro
()),
key
,
val
);
insertInLeafNodeAtPosition
(
sibling
,
sibRef
.
bits
.
get_ro
()
.
getFreeZero
(
),
key
,
val
);
}
else
{
}
else
{
if
(
key
>
nodeRef
.
keys
.
get_ro
()[
findMaxKeyPos
(
nodeRef
.
keys
.
get_ro
(),
nodeRef
.
bits
.
get_ro
())])
{
if
(
key
>
nodeRef
.
keys
.
get_ro
()[
findMaxKeyPos
(
nodeRef
.
keys
.
get_ro
(),
nodeRef
.
bits
.
get_ro
())])
{
/// Special case: new key would be the middle, thus must be right
/// Special case: new key would be the middle, thus must be right
insertInLeafNodeAtPosition
(
sibling
,
BitOperations
::
getFreeZero
(
sibRef
.
bits
.
get_ro
()),
key
,
val
);
insertInLeafNodeAtPosition
(
sibling
,
sibRef
.
bits
.
get_ro
()
.
getFreeZero
(
),
key
,
val
);
splitRef
.
key
=
key
;
splitRef
.
key
=
key
;
}
else
{
}
else
{
insertInLeafNodeAtPosition
(
node
,
BitOperations
::
getFreeZero
(
nodeRef
.
bits
.
get_ro
()),
key
,
val
);
insertInLeafNodeAtPosition
(
node
,
nodeRef
.
bits
.
get_ro
()
.
getFreeZero
(
),
key
,
val
);
}
}
}
}
/// inform the caller about the split
/// inform the caller about the split
...
@@ -950,15 +956,14 @@ class BitPBPTree {
...
@@ -950,15 +956,14 @@ class BitPBPTree {
// */
// */
/// setup the list of leaf nodes
/// setup the list of leaf nodes
if
(
nodeRef
.
nextLeaf
!=
nullptr
)
{
if
(
nodeRef
.
nextLeaf
!=
nullptr
)
{
sibRef
.
nextLeaf
=
nodeRef
.
nextLeaf
;
sibRef
.
nextLeaf
=
nodeRef
.
nextLeaf
;
nodeRef
.
nextLeaf
->
prevLeaf
=
sibling
;
nodeRef
.
nextLeaf
->
prevLeaf
=
sibling
;
PersistEmulation
::
writeBytes
<
16
*
2
>
();
PersistEmulation
::
writeBytes
<
16
*
2
>
();
}
}
nodeRef
.
nextLeaf
=
sibling
;
nodeRef
.
nextLeaf
=
sibling
;
sibRef
.
prevLeaf
=
node
;
sibRef
.
prevLeaf
=
node
;
PersistEmulation
::
writeBytes
<
16
*
2
>
();
PersistEmulation
::
writeBytes
<
16
*
2
>
();
/// set split information
/// set split information
auto
&
splitInfoRef
=
*
splitInfo
;
auto
&
splitInfoRef
=
*
splitInfo
;
...
@@ -1058,14 +1063,14 @@ class BitPBPTree {
...
@@ -1058,14 +1063,14 @@ class BitPBPTree {
const
auto
&
splitRef
=
*
splitInfo
;
const
auto
&
splitRef
=
*
splitInfo
;
host
=
(
key
<
splitRef
.
key
?
splitRef
.
leftChild
:
splitRef
.
rightChild
).
branch
;
host
=
(
key
<
splitRef
.
key
?
splitRef
.
leftChild
:
splitRef
.
rightChild
).
branch
;
split
=
true
;
split
=
true
;
//pos = lookupPositionInBranchNode(host, key);
//
pos = lookupPositionInBranchNode(host, key);
}
}
/// Insert new key and children
/// Insert new key and children
auto
&
hostRef
=
*
host
;
auto
&
hostRef
=
*
host
;
auto
&
hostKeys
=
hostRef
.
keys
.
get_rw
();
auto
&
hostKeys
=
hostRef
.
keys
.
get_rw
();
auto
&
hostChilds
=
hostRef
.
children
.
get_rw
();
auto
&
hostChilds
=
hostRef
.
children
.
get_rw
();
auto
&
hostBits
=
hostRef
.
bits
.
get_rw
();
auto
&
hostBits
=
hostRef
.
bits
.
get_rw
();
const
auto
u
=
BitOperations
::
getFreeZero
(
hostBits
);
const
auto
u
=
hostBits
.
getFreeZero
();
const
auto
nextPos
=
findMinKeyPosGreaterThan
(
hostKeys
,
hostBits
,
childSplitInfo
.
key
);
const
auto
nextPos
=
findMinKeyPosGreaterThan
(
hostKeys
,
hostBits
,
childSplitInfo
.
key
);
hostKeys
[
u
]
=
childSplitInfo
.
key
;
hostKeys
[
u
]
=
childSplitInfo
.
key
;
...
@@ -1161,7 +1166,7 @@ class BitPBPTree {
...
@@ -1161,7 +1166,7 @@ class BitPBPTree {
if
(
child
!=
nullptr
)
printBranchNode
(
d
+
1
,
child
);
if
(
child
!=
nullptr
)
printBranchNode
(
d
+
1
,
child
);
}
else
{
}
else
{
auto
leaf
=
(
nodeRef
.
children
.
get_ro
()[
k
]).
leaf
;
auto
leaf
=
(
nodeRef
.
children
.
get_ro
()[
k
]).
leaf
;
printLeafNode
(
d
+
1
,
leaf
);
printLeafNode
(
d
+
1
,
leaf
);
}
}
}
}
}
}
...
@@ -1179,7 +1184,7 @@ class BitPBPTree {
...
@@ -1179,7 +1184,7 @@ class BitPBPTree {
std
::
cout
<<
"[
\033
[1m"
<<
std
::
hex
<<
node
<<
std
::
dec
<<
"
\033
[0m #"
<<
nNumKeys
<<
": "
;
std
::
cout
<<
"[
\033
[1m"
<<
std
::
hex
<<
node
<<
std
::
dec
<<
"
\033
[0m #"
<<
nNumKeys
<<
": "
;
for
(
auto
i
=
0u
;
i
<
M
;
++
i
)
{
for
(
auto
i
=
0u
;
i
<
M
;
++
i
)
{
if
(
i
>
0
)
std
::
cout
<<
", "
;
if
(
i
>
0
)
std
::
cout
<<
", "
;
std
::
cout
<<
"{("
<<
nodeRef
.
bits
.
get_ro
()[
i
]
<<
')'
<<
nodeRef
.
keys
.
get_ro
()[
i
]
<<
"}"
;
std
::
cout
<<
"{("
<<
nodeRef
.
bits
.
get_ro
()[
i
]
<<
')'
<<
nodeRef
.
keys
.
get_ro
()[
i
]
<<
"}"
;
}
}
std
::
cout
<<
"]"
<<
std
::
endl
;
std
::
cout
<<
"]"
<<
std
::
endl
;
}
}
...
...
src/pbptrees/FPTree.hpp
View file @
fca2bd43
...
@@ -19,7 +19,6 @@
...
@@ -19,7 +19,6 @@
#define DBIS_FPTree_hpp_
#define DBIS_FPTree_hpp_
#include
<array>
#include
<array>
#include
<bitset>