*/
static inline bool mas_next_sibling(struct ma_state *mas)
{
- unsigned char p_slot = mte_parent_slot(mas->node) + 1;
-
MA_STATE(parent, mas->tree, mas->index, mas->last);
if (mte_is_root(mas->node))
mas_dup_state(&parent, mas);
mas_ascend(&parent);
+ parent.offset = mte_parent_slot(mas->node) + 1;
- if (p_slot == mt_slot_count(parent.node))
+ if (parent.offset == mt_slot_count(parent.node))
return false;
- if (!mas_get_slot(&parent, p_slot))
+ if (!mas_get_slot(&parent, parent.offset))
return false;
mas_dup_state(mas, &parent);
- mas->offset = p_slot;
mas_descend(mas);
return true;
}
{
unsigned long *pivots = ma_pivots(mas_mn(mas), type);
unsigned long min, pivot = 0;
- unsigned char i = mas->offset;
- min = mas_safe_min(mas, pivots, i);
+ min = mas_safe_min(mas, pivots, mas->offset);
if (ma_is_dense(type)) {
// Linear node.
// What if mas->index != mas->last?
pivot = min = mas->index;
- i = mas->index = mas->min;
+ mas->offset = mas->index = mas->min;
goto dense;
}
- while(i < mt_slots[type]) {
- pivot = _mas_safe_pivot(mas, pivots, i, type);
+ while(mas->offset < mt_slots[type]) {
+ pivot = _mas_safe_pivot(mas, pivots, mas->offset, type);
- if (!pivot && i) {
+ if (!pivot && mas->offset) {
if (mas->max < mas->index) {
mas->offset = MAPLE_NODE_SLOTS;
return false;
break;
min = pivot + 1;
- i++;
+ mas->offset++;
}
dense:
*range_min = min;
*range_max = pivot;
- mas->offset = i;
return true;
}
static inline bool mas_node_store(struct ma_state *mas, void *entry,
unsigned long min, unsigned long max,
- unsigned char end, void *content,
- unsigned char offset)
+ unsigned char end, void *content)
{
enum maple_type mt = mte_node_type(mas->node);
struct maple_node *node = mas_mn(mas);
void **dst_slots, **slots = ma_slots(node, mt);
unsigned long *dst_pivots, *pivots = ma_pivots(node, mt);
- unsigned char dst_offset, offset_end = offset, new_end = end;
+ unsigned char dst_offset, new_end = end;
+ unsigned char offset, offset_end;
struct maple_node reuse, *newnode;
unsigned char copy_size;
+ offset = offset_end = mas->offset;
if (mas->last == max) { // don't copy this offset
offset_end++;
} else if (mas->last < max) { // new range ends in this range.
static inline bool mas_slot_store(struct ma_state *mas, void *entry,
unsigned long min, unsigned long max,
- unsigned char end, void *content,
- unsigned char offset)
+ unsigned char end, void *content)
{
enum maple_type mt = mte_node_type(mas->node);
struct maple_node *node = mas_mn(mas);
void **slots = ma_slots(node, mt);
unsigned long *pivots = ma_pivots(node, mt);
- unsigned long lmax; // Logical max.
+ unsigned long offset = mas->offset, lmax; // Logical max.
if (min == mas->index && max == mas->last) { // exact fit.
slots[offset] = entry;
if (offset + 1 < mt_pivots[mt])
pivots[offset + 1] = mas->last;
slots[offset + 1] = entry;
- mas->offset = offset + 1;
pivots[offset] = mas->index - 1;
goto done;
}
return true;
try_node_store:
- return mas_node_store(mas, entry, min, max, end, content, offset);
+ return mas_node_store(mas, entry, min, max, end, content);
}
static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite)
{
unsigned long r_max, r_min;
- unsigned char end, offset;
+ unsigned char end;
void *content = NULL;
struct maple_big_node b_node;
/* At this point, we are at the leaf node that needs to be altered. */
/* Calculate needed space */
- offset = mas->offset;
- content = mas_get_slot(mas, offset);
+ content = mas_get_slot(mas, mas->offset);
if (!overwrite && ((mas->last > r_max) || content)) {
mas_set_err(mas, -EEXIST);
return content;
MA_STATE(r_mas, mas->tree, mas->last, mas->last);
- r_mas.offset = offset;
+ r_mas.offset = mas->offset;
r_mas.node = mas->node;
mas_node_walk(&r_mas, mte_node_type(r_mas.node), &rmin,
&rmax);
mas_extend_null(mas, &r_mas);
mas->last = r_mas.last;
- offset = mas->offset;
- r_min = mas_safe_min(mas, pivots, offset);
- r_max = _mas_safe_pivot(mas, pivots, offset, mt);
+ r_min = mas_safe_min(mas, pivots, mas->offset);
+ r_max = _mas_safe_pivot(mas, pivots, mas->offset, mt);
}
end = mas_data_end(mas);
- if (mas_slot_store(mas, entry, r_min, r_max, end, content, offset))
+ if (mas_slot_store(mas, entry, r_min, r_max, end, content))
return content;
if (mas_is_err(mas))