return false;
}
-static inline void mas_prev_node(struct ma_state *mas, unsigned long limit);
-static inline unsigned long mas_next_node(struct ma_state *mas,
- unsigned long max);
+static inline int mas_prev_node(struct ma_state *mas, unsigned long min);
+static inline int mas_next_node(struct ma_state *mas, unsigned long max);
/*
* mast_cousin_rebalance_right() - Rebalance from nodes with different parents.
* Check the right side, then the left. Data is copied into the @mast->bn.
* mas_prev_node() - Find the prev non-null entry at the same level in the
* tree. The prev value will be mas->node[mas->offset] or MAS_NONE.
* @mas: The maple state
- * @limit: The lower limit to search
+ * @min: The lower limit to search
*
- * Result needs to be checked if the node is dead.
* The prev node value will be mas->node[mas->offset] or MAS_NONE.
+ * Returns: 1 if the node is dead, 0 otherwise.
*/
-static inline void mas_prev_node(struct ma_state *mas, unsigned long limit)
+static inline int mas_prev_node(struct ma_state *mas, unsigned long min)
{
enum maple_type mt;
int offset, level;
unsigned long *pivots;
if (mas_is_none(mas))
- return;
+ return 0;
if (mte_is_root(mas->node))
goto no_entry;
offset = mte_parent_slot(mas->node);
mas_ascend(mas);
if (unlikely(mte_dead_node(mas->node)))
- return;
+ return 1;
level++;
} while (!offset);
slots = ma_slots(node, mt);
pivots = ma_pivots(node, mt);
mas->max = pivots[offset];
- if (mas->max < limit)
+ if (mas->max < min)
goto no_entry;
while (level > 1) {
mas->node = mas_slot(mas, slots, offset);
if (unlikely(mte_dead_node(mas->node)))
- return;
+ return 1;
level--;
mt = mte_node_type(mas->node);
offset = mas_data_end(mas);
if (offset < mt_pivots[mt]) {
mas->max = pivots[offset];
- if (mas->max < limit)
+ if (mas->max < min)
goto no_entry;
}
}
mas->node = mas_slot(mas, slots, offset);
if (unlikely(mte_dead_node(mas->node)))
- return;
+ return 1;
mas->offset = offset;
if (offset)
mas->min = pivots[offset - 1] + 1;
- return;
+ return 0;
no_entry:
mas->node = MAS_NONE;
- return;
+ return 0;
}
* @mas: The maple state
* @max: The maximum pivot value to check.
*
- * Return needs to be checked for dead nodes.
- *
- * Return: The next value will be mas->node[mas->offset] or MAS_NONE.
+ * The next value will be mas->node[mas->offset] or MAS_NONE.
+ * Return: 1 on dead node, 0 otherwise.
*/
-static inline unsigned long mas_next_node(struct ma_state *mas,
- unsigned long max)
+static inline int mas_next_node(struct ma_state *mas, unsigned long max)
{
unsigned long min, pivot;
unsigned long *pivots;
goto no_entry;
mas_ascend(mas);
if (unlikely(mte_dead_node(mas->node)))
- return mas->max;
+ return 1;
level++;
end = mas_data_end(mas);
/* Descend, if necessary */
mas->node = mas_slot(mas, slots, offset);
if (unlikely(mte_dead_node(mas->node)))
- return mas->max;
+ return 1;
level--;
node = mas_mn(mas);
mas->node = mas_slot(mas, slots, offset);
if (unlikely(mte_dead_node(mas->node)))
- return mas->max;
+ return 1;
mas->min = min;
mas->max = pivot;
- return mas->max;
+ return 0;
no_entry:
mas->node = MAS_NONE;
- return mas->max;
+ return 0;
}
/*
if (unlikely((r_start > limit)))
break;
- if (likely(entry)) {
- if (unlikely(mas_dead_node(mas, last)))
- goto retry;
+ if (unlikely(mas_dead_node(mas, last)))
+ goto retry;
+ if (likely(entry)) {
mas->index = r_start;
return entry;
}
next_node:
prev_node = mas->node;
offset = mas->offset;
- mas_next_node(mas, limit);
- if (unlikely(mas_dead_node(mas, last)))
+ if (unlikely(mas_next_node(mas, limit))) {
+ mas_dead_node(mas, last);
goto retry;
+ }
mas->offset = 0;
mt = mte_node_type(mas->node);
if (likely(entry))
return entry;
- mas_prev_node(mas, limit);
- if (unlikely(mas_dead_node(mas, index)))
+ if (unlikely(mas_prev_node(mas, limit))) {
+ mas_dead_node(mas, index);
goto retry;
+ }
mas->offset = mt_slot_count(mas->node);
}