summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-11-02 13:13:11 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-11-02 13:59:58 +0000
commit38f3c0c47d005fff498a4b7686492bf2640a3f69 (patch)
treed3051177001af8691cec9303b26c0cc68ef0dcf6 /vespalib
parent4677de8f0e2603078bd4c76e4e4fd4a621708124 (diff)
- deinline foreach in btree leaf nodes.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/btree/btreenode.h39
-rw-r--r--vespalib/src/vespa/vespalib/btree/btreenode.hpp36
2 files changed, 45 insertions, 30 deletions
diff --git a/vespalib/src/vespa/vespalib/btree/btreenode.h b/vespalib/src/vespa/vespalib/btree/btreenode.h
index f7e0b535b33..0e214eff83b 100644
--- a/vespalib/src/vespa/vespalib/btree/btreenode.h
+++ b/vespalib/src/vespa/vespalib/btree/btreenode.h
@@ -39,7 +39,7 @@ public:
static constexpr uint8_t LEAF_LEVEL = 0;
protected:
uint16_t _validSlots;
- BTreeNode(uint8_t level) noexcept
+ explicit BTreeNode(uint8_t level) noexcept
: _level(level),
_isFrozen(false),
_validSlots(0)
@@ -161,7 +161,7 @@ class BTreeNodeAggregatedWrap<NoAggregated>
static NoAggregated _instance;
public:
- BTreeNodeAggregatedWrap() noexcept {}
+ BTreeNodeAggregatedWrap() noexcept = default;
NoAggregated &getAggregated() { return _instance; }
const NoAggregated &getAggregated() const { return _instance; }
@@ -174,7 +174,7 @@ template <typename KeyT, uint32_t NumSlots>
class BTreeNodeT : public BTreeNode {
protected:
KeyT _keys[NumSlots];
- BTreeNodeT(uint8_t level) noexcept
+ explicit BTreeNodeT(uint8_t level) noexcept
: BTreeNode(level),
_keys()
{}
@@ -247,7 +247,7 @@ public:
using DataWrapType::setData;
using DataWrapType::copyData;
protected:
- BTreeNodeTT(uint8_t level) noexcept
+ explicit BTreeNodeTT(uint8_t level) noexcept
: ParentType(level),
DataWrapType()
{}
@@ -490,44 +490,23 @@ public:
const DataT &getLastData() const { return this->getData(validSlots() - 1); }
void writeData(uint32_t idx, const DataT &data) { this->setData(idx, data); }
- uint32_t validLeaves() const { return validSlots(); }
+ uint32_t validLeaves() const noexcept { return validSlots(); }
template <typename FunctionType>
- void foreach_key(FunctionType func) const {
- const KeyT *it = _keys;
- const KeyT *ite = it + _validSlots;
- for (; it != ite; ++it) {
- func(*it);
- }
- }
+ void foreach_key(FunctionType func) const;
/**
* Call func with leaf entry key value as argument for leaf entries [start_idx, end_idx).
*/
template <typename FunctionType>
- void foreach_key_range(uint32_t start_idx, uint32_t end_idx, FunctionType func) const {
- const KeyT *it = _keys;
- const KeyT *ite = it + end_idx;
- it += start_idx;
- for (; it != ite; ++it) {
- func(*it);
- }
- }
+ void foreach_key_range(uint32_t start_idx, uint32_t end_idx, FunctionType func) const;
template <typename FunctionType>
- void foreach(FunctionType func) const {
- const KeyT *it = _keys;
- const KeyT *ite = it + _validSlots;
- uint32_t idx = 0;
- for (; it != ite; ++it) {
- func(*it, this->getData(idx++));
- }
- }
+ void foreach(FunctionType func) const;
};
-template <typename KeyT, typename DataT, typename AggrT,
- uint32_t NumSlots = 16>
+template <typename KeyT, typename DataT, typename AggrT, uint32_t NumSlots = 16>
class BTreeLeafNodeTemp : public BTreeLeafNode<KeyT, DataT, AggrT, NumSlots>
{
public:
diff --git a/vespalib/src/vespa/vespalib/btree/btreenode.hpp b/vespalib/src/vespa/vespalib/btree/btreenode.hpp
index ab33fd2c059..52e83dd6f72 100644
--- a/vespalib/src/vespa/vespalib/btree/btreenode.hpp
+++ b/vespalib/src/vespa/vespalib/btree/btreenode.hpp
@@ -376,4 +376,40 @@ BTreeLeafNode(const KeyDataType *smallArray, uint32_t arraySize) noexcept
freeze();
}
+
+template <typename KeyT, typename DataT, typename AggrT, uint32_t NumSlots>
+template <typename FunctionType>
+void BTreeLeafNode<KeyT, DataT, AggrT, NumSlots>::foreach_key(FunctionType func) const {
+ const KeyT *it = _keys;
+ const KeyT *ite = it + _validSlots;
+ for (; it != ite; ++it) {
+ func(*it);
+ }
+}
+
+/**
+ * Call func with leaf entry key value as argument for leaf entries [start_idx, end_idx).
+ */
+template <typename KeyT, typename DataT, typename AggrT, uint32_t NumSlots>
+template <typename FunctionType>
+void BTreeLeafNode<KeyT, DataT, AggrT, NumSlots>::foreach_key_range(uint32_t start_idx, uint32_t end_idx, FunctionType func) const {
+ const KeyT *it = _keys;
+ const KeyT *ite = it + end_idx;
+ it += start_idx;
+ for (; it != ite; ++it) {
+ func(*it);
+ }
+}
+
+template <typename KeyT, typename DataT, typename AggrT, uint32_t NumSlots>
+template <typename FunctionType>
+void BTreeLeafNode<KeyT, DataT, AggrT, NumSlots>::foreach(FunctionType func) const {
+ const KeyT *it = _keys;
+ const KeyT *ite = it + _validSlots;
+ uint32_t idx = 0;
+ for (; it != ite; ++it) {
+ func(*it, this->getData(idx++));
+ }
+}
+
}