Skip to content

Commit

Permalink
messing around
Browse files Browse the repository at this point in the history
  • Loading branch information
petrelharp committed Dec 7, 2022
1 parent 77620e1 commit ef6f0d3
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion c/tskit/tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -12341,7 +12341,57 @@ tsk_table_collection_add_and_remap_node(tsk_table_collection_t *self,
int
forward_extend(tsk_table_collection_t *self)
{
// TODO: use `tsk_diff_iter_X` to iterate over edges?
int ret = 0;
double *new_left, *new_right;
tsk_id_t tj, tk;
const tsk_id_t *I, *O;
const tsk_id_t M = (tsk_id_t) edges.num_rows;
tsk_id_t *parent = NULL;

new_left = tsk_malloc(self->edges.num_rows * sizeof(*new_left));
new_right = tsk_malloc(self->edges.num_rows * sizeof(*new_right));
if (new_left == NULL || new_right == NULL) {
ret = TSK_ERR_NO_MEMORY;
goto out;
}
memcpy(new_left, self->edges.left, self->edges.num_rows * sizeof(*new_left));
memcpy(new_right, self->edges.right, self->edges.num_rows * sizeof(*new_right));

parent = tsk_malloc(nodes.num_rows * sizeof(*parent));
if (parent == NULL) {
ret = TSK_ERR_NO_MEMORY;
goto out;
}
tsk_memset(parent, 0xff, nodes.num_rows * sizeof(*parent));

I = self->indexes.edge_insertion_order;
O = self->indexes.edge_removal_order;
tj = 0;
tk = 0;
left = 0;
while (tj < M || left < self->sequence_length) {
while (tk < M && edges.right[O[tk]] == left) {
parent[edges.child[O[tk]]] = TSK_NULL;
tk++;
}
while (tj < M && edges.left[I[tj]] == left) {
parent[edges.child[I[tj]]] = edges.parent[I[tj]];
tj++;
}
right = self->sequence_length;
if (tj < M) {
right = TSK_MIN(right, edges.left[I[tj]]);
}
if (tk < M) {
right = TSK_MIN(right, edges.right[O[tk]]);
}


}


out:
return ret;
}

int TSK_WARN_UNUSED
Expand Down

0 comments on commit ef6f0d3

Please sign in to comment.