From ef6f0d372d8f57220025e273e2905271b5cd8093 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 7 Dec 2022 11:03:24 -0800 Subject: [PATCH] messing around --- c/tskit/tables.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/c/tskit/tables.c b/c/tskit/tables.c index d23bd41dd1..c5c414c6c2 100644 --- a/c/tskit/tables.c +++ b/c/tskit/tables.c @@ -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