Commit 5036f0b6 by Evan Brown Committed by Copybara-Service

Use Layout::WithStaticSizes in btree.

PiperOrigin-RevId: 617877687
Change-Id: I29c52f9288f099255c4adb7c1f9fa8831ac55b05
parent 1cd7128b
...@@ -580,14 +580,12 @@ class btree_node { ...@@ -580,14 +580,12 @@ class btree_node {
using layout_type = using layout_type =
absl::container_internal::Layout<btree_node *, uint32_t, field_type, absl::container_internal::Layout<btree_node *, uint32_t, field_type,
slot_type, btree_node *>; slot_type, btree_node *>;
using leaf_layout_type = typename layout_type::template WithStaticSizes<
/*parent*/ 1,
/*generation*/ BtreeGenerationsEnabled() ? 1 : 0,
/*position, start, finish, max_count*/ 4>;
constexpr static size_type SizeWithNSlots(size_type n) { constexpr static size_type SizeWithNSlots(size_type n) {
return layout_type( return leaf_layout_type(/*slots*/ n, /*children*/ 0).AllocSize();
/*parent*/ 1,
/*generation*/ BtreeGenerationsEnabled() ? 1 : 0,
/*position, start, finish, max_count*/ 4,
/*slots*/ n,
/*children*/ 0)
.AllocSize();
} }
// A lower bound for the overhead of fields other than slots in a leaf node. // A lower bound for the overhead of fields other than slots in a leaf node.
constexpr static size_type MinimumOverhead() { constexpr static size_type MinimumOverhead() {
...@@ -619,27 +617,22 @@ class btree_node { ...@@ -619,27 +617,22 @@ class btree_node {
constexpr static size_type kNodeSlots = constexpr static size_type kNodeSlots =
kNodeTargetSlots >= kMinNodeSlots ? kNodeTargetSlots : kMinNodeSlots; kNodeTargetSlots >= kMinNodeSlots ? kNodeTargetSlots : kMinNodeSlots;
using internal_layout_type = typename layout_type::template WithStaticSizes<
/*parent*/ 1,
/*generation*/ BtreeGenerationsEnabled() ? 1 : 0,
/*position, start, finish, max_count*/ 4, /*slots*/ kNodeSlots,
/*children*/ kNodeSlots + 1>;
// The node is internal (i.e. is not a leaf node) if and only if `max_count` // The node is internal (i.e. is not a leaf node) if and only if `max_count`
// has this value. // has this value.
constexpr static field_type kInternalNodeMaxCount = 0; constexpr static field_type kInternalNodeMaxCount = 0;
constexpr static layout_type Layout(const size_type slot_count,
const size_type child_count) {
return layout_type(
/*parent*/ 1,
/*generation*/ BtreeGenerationsEnabled() ? 1 : 0,
/*position, start, finish, max_count*/ 4,
/*slots*/ slot_count,
/*children*/ child_count);
}
// Leaves can have less than kNodeSlots values. // Leaves can have less than kNodeSlots values.
constexpr static layout_type LeafLayout( constexpr static leaf_layout_type LeafLayout(
const size_type slot_count = kNodeSlots) { const size_type slot_count = kNodeSlots) {
return Layout(slot_count, 0); return leaf_layout_type(slot_count, 0);
}
constexpr static layout_type InternalLayout() {
return Layout(kNodeSlots, kNodeSlots + 1);
} }
constexpr static auto InternalLayout() { return internal_layout_type(); }
constexpr static size_type LeafSize(const size_type slot_count = kNodeSlots) { constexpr static size_type LeafSize(const size_type slot_count = kNodeSlots) {
return LeafLayout(slot_count).AllocSize(); return LeafLayout(slot_count).AllocSize();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment