/*
- * rebalance_data_calc() - Calculate the size of the data (1 indexed).
+ * cp_data_calc() - Calculate the size of the data (1 indexed).
* @cp: The maple copy struct with the new data populated.
* @l_wr_mas: The maple write state containing the data to the left of the write
* @r_wr_mas: The maple write state containing the data to the right of the
sib->end = 0;
}
-static inline void rebalance_data_calc(struct maple_copy *cp,
+/*
+ * rebalance_data() - Calculate the @cp data, populate @sib if insufficient or
+ * if the data can be pushed into a sibling.
+ * @cp: The maple copy node
+ * @wr_mas: The left write maple state
+ * @sib: The maple state of the sibling.
+ *
+ * Note: @cp->data is a size and not indexed by 0. @sib->end may be set to 0 to
+ * indicate it will not be used.
+ *
+ */
+static inline void rebalance_data(struct maple_copy *cp,
struct ma_wr_state *wr_mas, struct ma_state *sib)
{
cp_data_calc(cp, wr_mas, wr_mas);
}
/*
- * cp->data will not be 0 indexed.
+ * spanning_data() - Calculate the @cp data and populate @sib if insufficient
+ * @cp: The maple copy node
+ * @l_wr_mas: The left write maple state
+ * @r_wr_mas: The right write maple state
+ * @sib: The maple state of the sibling.
+ *
+ * Note: @cp->data is a size and not indexed by 0. @sib->end may be set to 0 to
+ * indicate it will not be used.
*/
-static inline void spanning_data_calc(struct maple_copy *cp,
+static inline void spanning_data(struct maple_copy *cp,
struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas,
struct ma_state *sib)
{
}
/*
- * dst_setup() - Set up multiple destinations for the new data. This is
- * called when the node is split or rebalanced.
+ * dst_setup() - Set up one or more destinations for the new data.
+ * @cp: The maple copy node
+ * @mas: The maple state
+ * @mt: The source node type
*/
static inline
void dst_setup(struct maple_copy *cp, struct ma_state *mas, enum maple_type mt)
}
-static inline void spanning_init_cp_src(struct maple_copy *cp)
+/* init_cp_src() - Initialize the next source as @cp itself
+ * @cp: The maple copy node.
+ *
+ * Append the data within the maple_copy node itself to the sources
+ */
+static inline void init_cp_src(struct maple_copy *cp)
{
cp->src[cp->s_count].node = ma_mnode_ptr(cp);
cp->src[cp->s_count].mt = maple_copy;
}
/*
- * src->start and end are 0 indexed
+ * multi_src_setup() - Set the @cp node up with multiple sources to copy from.
+ * @cp: The maple copy node
+ * @l_wr_mas: The left write maple state
+ * @r_wr_mas: The right write maple state
+ * @sib: The sibling maple state
+ *
+ * Note: @sib->end == 0 indicates no sibling will be used.
*/
static inline
void multi_src_setup(struct maple_copy *cp, struct ma_wr_state *l_wr_mas,
cp->src[cp->s_count - 1].max = cp->min - 1;
}
- spanning_init_cp_src(cp);
+ init_cp_src(cp);
/* Copy right either from offset or offset + 1 pending on r_max */
if (r_wr_mas->mas->end != r_wr_mas->offset_end)
cp->max = max;
}
-static inline void rebalance_new_root(struct maple_copy *cp, struct ma_state *mas)
+static inline void cp_new_root(struct maple_copy *cp, struct ma_state *mas)
{
if (cp->d_count != 1) {
enum maple_type mt = maple_arange_64;
cp->data = cp->d_count;
cp->s_count = 0;
dst_setup(cp, mas, mt);
- spanning_init_cp_src(cp);
+ init_cp_src(cp);
node_copy(mas, cp->src[0].node, 0, cp->data, cp->max, maple_copy,
cp->dst[0].node, 0, mt);
node_finalise(cp->dst[0].node, mt, cp->end + 1);
cp_dst_to_slots(cp, l_wr_mas->mas->min, r_wr_mas->mas->max, mas);
if (!cp->min && cp->max == ULONG_MAX) {
- rebalance_new_root(cp, mas);
+ cp_new_root(cp, mas);
return false;
}
cp_leaf_init(&cp, mas, l_wr_mas, r_wr_mas);
do {
- spanning_data_calc(&cp, l_wr_mas, r_wr_mas, &sib);
+ spanning_data(&cp, l_wr_mas, r_wr_mas, &sib);
multi_src_setup(&cp, l_wr_mas, r_wr_mas, &sib);
dst_setup(&cp, mas, l_wr_mas->type);
cp_data_write(&cp, mas);
cp_dst_to_slots(cp, min, r->max, mas);
if (!cp->min && cp->max == ULONG_MAX) {
- rebalance_new_root(cp, mas);
+ cp_new_root(cp, mas);
return false;
}
cp_dst_to_slots(cp, min, max, mas);
if (!cp->min && cp->max == ULONG_MAX) {
- rebalance_new_root(cp, mas);
+ cp_new_root(cp, mas);
return false;
}
return true;
}
-static void split_data_calc(struct maple_copy *cp,
+/*
+ * split_data() - Calculate the @cp data, populate @sib if the data can be
+ * pushed into a sibling.
+ * @cp: The maple copy node
+ * @wr_mas: The left write maple state
+ * @sib: The maple state of the sibling.
+ *
+ * Note: @cp->data is a size and not indexed by 0. @sib->end may be set to 0 to
+ * indicate it will not be used.
+ *
+ */
+static void split_data(struct maple_copy *cp,
struct ma_wr_state *wr_mas, struct ma_state *sib)
{
cp_data_calc(cp, wr_mas, wr_mas);
}
/*
- * mas_wr_split() - Expand one node into two
+ * mas_wr_split() - Split the data of one node across two nodes.
* @wr_mas: The write maple state
*/
static void mas_wr_split(struct ma_wr_state *wr_mas)
mas = wr_mas->mas;
cp_leaf_init(&cp, mas, wr_mas, wr_mas);
do {
- split_data_calc(&cp, wr_mas, &sib);
+ split_data(&cp, wr_mas, &sib);
multi_src_setup(&cp, wr_mas, wr_mas, &sib);
dst_setup(&cp, mas, wr_mas->type);
cp_data_write(&cp, mas);
mas = wr_mas->mas;
cp_leaf_init(&cp, mas, wr_mas, wr_mas);
do {
- rebalance_data_calc(&cp, wr_mas, &sib);
+ rebalance_data(&cp, wr_mas, &sib);
multi_src_setup(&cp, wr_mas, wr_mas, &sib);
dst_setup(&cp, mas, wr_mas->type);
cp_data_write(&cp, mas);