}
/*
- * _mas_safe_pivot() - get the pivot at @piv or mas->max.
+ * mas_safe_pivot() - get the pivot at @piv or mas->max.
* @mas: The maple state
* @pivots: The pointer to the maple node pivots
* @piv: The pivot to fetch
* otherwise.
*/
static inline unsigned long
-_mas_safe_pivot(const struct ma_state *mas, unsigned long *pivots,
- unsigned char piv, enum maple_type type)
+mas_safe_pivot(const struct ma_state *mas, unsigned long *pivots,
+ unsigned char piv, enum maple_type type)
{
if (piv >= mt_pivots[type])
return mas->max;
return pivots[piv];
}
-/*
- * mas_safe_pivot() - Return pivot, implied or otherwise.
- * @mas: The maple state
- * @piv: the pivot location
- *
- * Return: The pivot (including mas->max for the final piv)
- */
-static inline unsigned long
-mas_safe_pivot(const struct ma_state *mas, unsigned char piv)
-{
- enum maple_type type = mte_node_type(mas->node);
- unsigned long *pivots = ma_pivots(mas_mn(mas), type);
-
- return _mas_safe_pivot(mas, pivots, piv, type);
-}
-
/*
* mas_safe_min() - Return the minimum for a given offset.
* @mas: The maple state
mas_logical_pivot(struct ma_state *mas, unsigned long *pivots,
unsigned char offset, enum maple_type type)
{
- unsigned long lpiv = _mas_safe_pivot(mas, pivots, offset, type);
+ unsigned long lpiv = mas_safe_pivot(mas, pivots, offset, type);
if (likely(lpiv))
return lpiv;
if (mas->offset)
mas->min = pivots[mas->offset - 1] + 1;
- mas->max = _mas_safe_pivot(mas, pivots, mas->offset, type);
+ mas->max = mas_safe_pivot(mas, pivots, mas->offset, type);
mas->node = mas_slot(mas, slots, mas->offset);
}
}
if (likely(i <= mas_end))
- b_node->pivot[j] = _mas_safe_pivot(mas, pivots, i, mt);
+ b_node->pivot[j] = mas_safe_pivot(mas, pivots, i, mt);
complete:
b_node->b_end = ++j;
}
/*
- * _mas_split_final_node() - Split the final node in a subtree operation.
+ * mas_split_final_node() - Split the final node in a subtree operation.
* @mast: the maple subtree state
* @mas: The maple state
* @height: The height of the tree in case it's a new root.
*/
-static inline bool _mas_split_final_node(struct maple_subtree_state *mast,
+static inline bool mas_split_final_node(struct maple_subtree_state *mast,
struct ma_state *mas, int height)
{
struct maple_enode *ancestor;
return true;
}
-/*
- * mas_split_final_node() - Check if a subtree state can be contained within a
- * single node and do so if possible.
- * @mast: The maple subtree state
- * @mas: The maple state
- * @height: The height in case of a new root.
- *
- * Return: True if this was the final node and it has been handled, false
- * otherwise.
- */
-static inline bool mas_split_final_node(struct maple_subtree_state *mast,
- struct ma_state *mas, int height)
-{
- if (mt_slots[mast->bn->type] <= mast->bn->b_end)
- return false;
-
- return _mas_split_final_node(mast, mas, height);
-}
-
/*
* mast_fill_bnode() - Copy data into the big node in the subtree state
* @mast: The maple subtree state
mast_split_data(mast, mas, split);
mast_fill_bnode(mast, mas, 2);
- _mas_split_final_node(mast, mas, height + 1);
+ mas_split_final_node(mast, mas, height + 1);
return true;
}
mast.bn = b_node;
while (height++ <= mas->depth) {
- if (mas_split_final_node(&mast, mas, height))
+ if (mt_slots[b_node->type] > b_node->b_end) {
+ mas_split_final_node(&mast, mas, height);
break;
+ }
l_mas = r_mas = *mas;
l_mas.node = mas_new_ma_node(mas, b_node);
} else if ((r_mas->last == r_wr_mas->r_max) &&
(r_mas->last < r_mas->max) &&
!mas_slot_locked(r_mas, r_wr_mas->slots, r_mas->offset + 1)) {
- r_mas->last = mas_safe_pivot(r_mas, r_mas->offset + 1);
+ r_mas->last = mas_safe_pivot(r_mas, r_wr_mas->pivots,
+ r_wr_mas->type, r_mas->offset + 1);
r_mas->offset++;
}
}
new_end++;
} else {
- if (_mas_safe_pivot(mas, wr_mas->pivots, wr_mas->offset_end, wr_mas->type) == mas->last)
+ if (mas_safe_pivot(mas, wr_mas->pivots, wr_mas->offset_end,
+ wr_mas->type) == mas->last)
wr_mas->offset_end++;
new_end -= wr_mas->offset_end - offset - 1;
new_end++;
} else {
- if (_mas_safe_pivot(mas, pivots, offset_end, mt) == mas->last)
+ if (mas_safe_pivot(mas, pivots, offset_end, mt) == mas->last)
offset_end++;
new_end -= offset_end - offset - 1;
mt = mte_node_type(mas->node);
slots = ma_slots(node, mt);
pivots = ma_pivots(node, mt);
- pivot = _mas_safe_pivot(mas, pivots, ++offset, mt);
+ pivot = mas_safe_pivot(mas, pivots, ++offset, mt);
while (unlikely(level > 1)) {
/* Descend, if necessary */
enode = mas_slot(mas, slots, offset);
return NULL;
}
- pivot = _mas_safe_pivot(mas, pivots, mas->offset, type);
+ pivot = mas_safe_pivot(mas, pivots, mas->offset, type);
entry = mas_slot(mas, slots, mas->offset);
if (ma_dead_node(node))
return NULL;
while (mas->last < min)
min = mas_safe_min(mas, pivots, --offset);
- max = _mas_safe_pivot(mas, pivots, offset, type);
+ max = mas_safe_pivot(mas, pivots, offset, type);
index = mas->index;
while (index <= max) {
gap = 0;
count = mt_slots[type];
min = mas_safe_min(mas, pivots, offset);
for (; offset < count; offset++) {
- pivot = _mas_safe_pivot(mas, pivots, offset, type);
+ pivot = mas_safe_pivot(mas, pivots, offset, type);
if (offset && !pivot)
break;
mas_ascend(mas);
ptype = mte_node_type(mas->node);
pivots = ma_pivots(mas_mn(mas), ptype);
- mas->max = _mas_safe_pivot(mas, pivots, pslot, ptype);
+ mas->max = mas_safe_pivot(mas, pivots, pslot, ptype);
mas->min = mas_safe_min(mas, pivots, pslot);
mas->node = mn;
mas->offset = slot;
return;
for (i = 0; i < mt_slot_count(mas->node); i++) {
- unsigned long piv = mas_safe_pivot(mas, i);
+ enum maple_type type = mte_node_type(mas->node);
+ unsigned long *pivots = ma_pivots(mas_mn(mas), type);
+ unsigned long piv = mas_safe_pivot(mas, pivots, type, i);
+
if (!piv)
break;