}
}
+struct split_data {
+ /*
+ * Used to split the data between two nodes.
+ * The user of this struct, mt_wr_split_data(), must keep track of the
+ * offset into the entire data (up to two nodes worth), so that the
+ * insert can be placed in the correct place while the source data that
+ * is overwritten is skipped.
+ */
+ unsigned char offset; /* Offset into destination data (entire set) */
+ unsigned char space; /* The space left in the current destination node */
+ unsigned char split; /* Proposed split of data */
+ unsigned char insert; /* Insert location of destination */
+ unsigned char new_end; /* Total data */
+ unsigned char src_ins_end;
+ struct ma_node_state *state;
+ struct ma_node_state states[5];
+ int len;
+};
+
static inline void mas_wr_converged(struct ma_node_info *src,
struct ma_node_info *dst, struct ma_node_part *ma_part,
- struct ma_state *mas)
-
+ struct ma_state *mas, struct split_data *sd)
{
- struct ma_node_state converged[3];
- unsigned char i = 0;
unsigned char off = 0;
+ sd->len = 0;
mni_node_init(dst, mas_pop_node(mas), src->type);
if (src->insert_off) {
- mns_mni_init(&converged[i], dst, 0, src->insert_off);
- converged[i].info = src;
+ mns_mni_init(&sd->states[sd->len], dst, 0, src->insert_off);
+ sd->states[sd->len].info = src;
+ sd->len++;
off = src->insert_off;
- i++;
}
- mns_mni_init(&converged[i], dst, 0, ma_part->size);
- converged[i].part = ma_part;
- converged[i].use_part = true;
+ mns_mni_init(&sd->states[sd->len], dst, 0, ma_part->size);
+ sd->states[sd->len].part = ma_part;
+ sd->states[sd->len].use_part = true;
+ sd->len++;
off += ma_part->skip;
- i++;
if (src->end >= off) {
unsigned char start = off;
unsigned char size = src->end - start + 1;
- mns_mni_init(&converged[i], dst, start, size);
- converged[i].info = src;
- i++;
+ mns_mni_init(&sd->states[sd->len], dst, start, size);
+ sd->states[sd->len].info = src;
+ sd->len++;
off += size - 1;
}
- mns_assemble(converged, i);
+ mns_assemble(sd->states, sd->len);
dst->node->parent = src->node->parent;
mni_finalise(dst);
}
-struct split_data {
- /*
- * Used to split the data between two nodes.
- * The user of this struct, mt_wr_split_data(), must keep track of the
- * offset into the entire data (up to two nodes worth), so that the
- * insert can be placed in the correct place while the source data that
- * is overwritten is skipped.
- */
- unsigned char offset; /* Offset into destination data (entire set) */
- unsigned char space; /* The space left in the current destination node */
- unsigned char split; /* Proposed split of data */
- unsigned char insert; /* Insert location of destination */
- unsigned char new_end; /* Total data */
- unsigned char src_ins_end;
- struct ma_node_state *state;
- int i;
-};
-
/*
*
* @src: The node information of the source
struct ma_node_info *to;
state = sd->state;
- i = sd->i;
+ i = sd->len;
/* Offset into the destination data where the insert ends */
insert_end = sd->insert + ma_part->size - 1;
state[i].info = &src2;
mns_mni_init(&state[i], left, 0, src2.end + 1);
i++;
- sd->i++;
+ sd->len++;
}
/*
mas->end = parent.end;
mas->offset = parent.insert_off;
ma_part->skip = 2;
- mas_wr_converged(&parent, &new_parent, ma_part, mas);
+ mas_wr_converged(&parent, &new_parent, ma_part, mas, sd);
src->enode = parent.enode;
mas->node = new_parent.enode;
return true;
mns_node_part_leaf_init(&part, wr_mas, &src);
sd.new_end = mas->end + part.size; /* - skip + 1 */
sd.src_ins_end = wr_mas->offset_end;
- sd.i = 0;
+ sd.len = 0;
if (height > 1 &&
mas_wr_try_rebalance(mas, &src, &left, &right, &part, &sd))
goto rebalanced;
mni_node_init(&left, mas_pop_node(mas), src.type);
mni_node_init(&right, mas_pop_node(mas), src.type);
sd.src_ins_end = src.insert_off;
- sd.i = 0;
+ sd.len = 0;
if ((height > 1) &&
(mas_wr_try_rebalance(mas, &src, &left, &right, &part, &sd)))
goto rebalanced;
* set the skip to high enough to avoid using any data
*/
converged:
- mas_wr_converged(&src, &parent, &part, mas);
+ mas_wr_converged(&src, &parent, &part, mas, &sd);
mas->node = parent.enode;
rebalanced:
mas_wmb_replace(mas, src.enode);