/*
* mab_calc_split() - Calculate the split location and if there needs to be two
* splits.
- * @b_node: The maple_big_node with the data
+ * @bn: The maple_big_node with the data
* @mid_split: The second split, if required. 0 otherwise.
*
- * Return: The first split location.
+ * Return: The first split location. The middle split is set in @mid_split.
*/
static inline int mab_calc_split(struct ma_state *mas,
- struct maple_big_node *b_node,
+ struct maple_big_node *bn,
unsigned char *mid_split)
{
- unsigned char b_end = b_node->b_end;
+ unsigned char b_end = bn->b_end;
int split = b_end / 2; // Assume equal split.
- unsigned char min, slot_count = mt_slots[b_node->type];
+ unsigned char min, slot_count = mt_slots[bn->type];
if (unlikely((mas->mas_flags & MA_STATE_BULK))) {
*mid_split = 0;
- if (ma_is_leaf(b_node->type))
+ if (ma_is_leaf(bn->type))
min = 2;
else
- return b_end - mt_min_slots[b_node->type];
+ return b_end - mt_min_slots[bn->type];
split = b_end - min;
mas->mas_flags |= MA_STATE_REBALANCE;
- if (!b_node->slot[split])
+ if (!bn->slot[split])
split--;
return split;
}
- if (unlikely(mab_middle_node(b_node, split, slot_count))) {
+ if (unlikely(mab_middle_node(bn, split, slot_count))) {
split = b_end / 3;
*mid_split = split * 2;
} else {
- min = mt_min_slots[b_node->type];
+ min = mt_min_slots[bn->type];
*mid_split = 0;
/* Avoid having a range less than the slot count unless it
* causes one node to be deficient.
* NOTE: mt_min_slots is 1 based, b_end and split are zero.
*/
- while (((b_node->pivot[split] - b_node->min) < slot_count - 1) &&
+ while (((bn->pivot[split] - bn->min) < slot_count - 1) &&
(split < slot_count - 1) && (b_end - split > min))
split++;
}
/* Avoid ending a node on a NULL entry */
- split = mab_no_null_split(b_node, split, slot_count);
+ split = mab_no_null_split(bn, split, slot_count);
if (!(*mid_split))
return split;
- *mid_split = mab_no_null_split(b_node, *mid_split, slot_count);
+ *mid_split = mab_no_null_split(bn, *mid_split, slot_count);
return split;
}