Skip to content

Commit

Permalink
Fixes based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanMR committed Dec 4, 2023
1 parent 25d30fb commit 7307a85
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
7 changes: 2 additions & 5 deletions c/tskit/trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -4520,14 +4520,12 @@ tsk_tree_init(tsk_tree_t *self, const tsk_treeseq_t *tree_sequence, tsk_flags_t
{
int ret = TSK_ERR_NO_MEMORY;
tsk_size_t num_samples, num_nodes, N;
tsk_tree_position_t tree_pos;

tsk_memset(self, 0, sizeof(tsk_tree_t));
if (tree_sequence == NULL) {
ret = TSK_ERR_BAD_PARAM_VALUE;
goto out;
}
tsk_memset(&tree_pos, 0, sizeof(tree_pos));
num_nodes = tree_sequence->tables->nodes.num_rows;
num_samples = tree_sequence->num_samples;
self->num_nodes = num_nodes;
Expand All @@ -4536,7 +4534,6 @@ tsk_tree_init(tsk_tree_t *self, const tsk_treeseq_t *tree_sequence, tsk_flags_t
self->samples = tree_sequence->samples;
self->options = options;
self->root_threshold = 1;
self->tree_pos = tree_pos;

/* Allocate space in the quintuply linked tree for the virtual root */
N = num_nodes + 1;
Expand Down Expand Up @@ -4569,7 +4566,7 @@ tsk_tree_init(tsk_tree_t *self, const tsk_treeseq_t *tree_sequence, tsk_flags_t
}
}

ret = tsk_tree_position_init(&tree_pos, tree_sequence, 0);
ret = tsk_tree_position_init(&self->tree_pos, tree_sequence, 0);
if (ret != 0) {
goto out;

Check warning on line 4571 in c/tskit/trees.c

View check run for this annotation

Codecov / codecov/patch

c/tskit/trees.c#L4571

Added line #L4571 was not covered by tests
}
Expand Down Expand Up @@ -4621,7 +4618,7 @@ tsk_tree_free(tsk_tree_t *self)
tsk_safe_free(self->next_sample);
tsk_safe_free(self->num_children);
tsk_safe_free(self->edge);
tsk_safe_free(self->tree_pos);
tsk_tree_position_free(&self->tree_pos);
return 0;
}

Expand Down
18 changes: 9 additions & 9 deletions c/tskit/trees.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,6 @@ typedef struct {
const tsk_treeseq_t *tree_sequence;
} tsk_tree_position_t;

int tsk_tree_position_init(
tsk_tree_position_t *self, const tsk_treeseq_t *tree_sequence, tsk_flags_t options);
int tsk_tree_position_free(tsk_tree_position_t *self);
int tsk_tree_position_print_state(const tsk_tree_position_t *self, FILE *out);
bool tsk_tree_position_next(tsk_tree_position_t *self);
bool tsk_tree_position_prev(tsk_tree_position_t *self);
int tsk_tree_position_seek_forward(tsk_tree_position_t *self, tsk_id_t index);
int tsk_tree_position_seek_backward(tsk_tree_position_t *self, tsk_id_t index);

/**
@brief A single tree in a tree sequence.
Expand Down Expand Up @@ -1816,6 +1807,15 @@ bool tsk_tree_equals(const tsk_tree_t *self, const tsk_tree_t *other);
int tsk_diff_iter_init_from_ts(
tsk_diff_iter_t *self, const tsk_treeseq_t *tree_sequence, tsk_flags_t options);

int tsk_tree_position_init(
tsk_tree_position_t *self, const tsk_treeseq_t *tree_sequence, tsk_flags_t options);
int tsk_tree_position_free(tsk_tree_position_t *self);
int tsk_tree_position_print_state(const tsk_tree_position_t *self, FILE *out);
bool tsk_tree_position_next(tsk_tree_position_t *self);
bool tsk_tree_position_prev(tsk_tree_position_t *self);
int tsk_tree_position_seek_forward(tsk_tree_position_t *self, tsk_id_t index);
int tsk_tree_position_seek_backward(tsk_tree_position_t *self, tsk_id_t index);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ sphinx:
["c:identifier", "FILE"],
["c:identifier", "bool"],
# This is for the anonymous interval struct embedded in the tsk_tree_t.
["c:identifier", "tsk_tree_t.@1"],
["c:identifier", "tsk_tree_t.@4"],
["c:type", "int32_t"],
["c:type", "uint32_t"],
["c:type", "uint64_t"],
Expand Down

0 comments on commit 7307a85

Please sign in to comment.