Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions c/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

**Breaking changes**

- Removed ``TSK_NO_BUILD_INDEXES``.
Not building indexes is now the default behaviour of `tsk_table_collection_dump` and related functions.
(:user:`molpopgen`, :issue:`1327`, :pr:`1337`).

**Features**

- Add ``tsk_*_table_extend`` methods to append to a table from another
Expand Down
18 changes: 3 additions & 15 deletions c/tests/test_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -5080,11 +5080,11 @@ test_dump_unindexed_with_options(tsk_flags_t tc_options)
CU_ASSERT_FALSE(tsk_table_collection_has_index(&tables, 0));
ret = tsk_table_collection_dump(&tables, _tmp_file_name, 0);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT_TRUE(tsk_table_collection_has_index(&tables, 0));
CU_ASSERT_FALSE(tsk_table_collection_has_index(&tables, 0));

ret = tsk_table_collection_load(&loaded, _tmp_file_name, 0);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT_TRUE(tsk_table_collection_has_index(&loaded, 0));
CU_ASSERT_FALSE(tsk_table_collection_has_index(&loaded, 0));
CU_ASSERT_TRUE(tsk_node_table_equals(&tables.nodes, &loaded.nodes, 0));
CU_ASSERT_TRUE(tsk_edge_table_equals(&tables.edges, &loaded.edges, 0));

Expand Down Expand Up @@ -5165,16 +5165,7 @@ test_dump_load_unsorted_with_options(tsk_flags_t tc_options)
ret = tsk_table_collection_check_integrity(&t1, TSK_CHECK_EDGE_ORDERING);
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_EDGES_NOT_SORTED_PARENT_TIME);

/* Indexing should fail */
ret = tsk_table_collection_build_index(&t1, 0);
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_EDGES_NOT_SORTED_PARENT_TIME);
CU_ASSERT_FALSE(tsk_table_collection_has_index(&t1, 0));

/* Trying to dump without first sorting should also fail */
ret = tsk_table_collection_dump(&t1, _tmp_file_name, 0);
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_EDGES_NOT_SORTED_PARENT_TIME);

ret = tsk_table_collection_dump(&t1, _tmp_file_name, TSK_NO_BUILD_INDEXES);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT_FALSE(tsk_table_collection_has_index(&t1, 0));
ret = tsk_table_collection_load(&t2, _tmp_file_name, 0);
Expand Down Expand Up @@ -5272,9 +5263,6 @@ test_dump_fail_no_file(void)
unlink(_tmp_file_name);
errno = 0;

/* Trying to dump without first sorting fails */
ret = tsk_table_collection_dump(&t1, _tmp_file_name, 0);
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_EDGES_NOT_SORTED_PARENT_TIME);
CU_ASSERT_EQUAL(access(_tmp_file_name, F_OK), -1);

tsk_table_collection_free(&t1);
Expand Down Expand Up @@ -5303,7 +5291,7 @@ test_load_reindex(void)
ret = tsk_table_collection_drop_index(&tables, 0);
CU_ASSERT_EQUAL_FATAL(ret, 0);
/* Dump the unindexed version */
ret = tsk_table_collection_dump(&tables, _tmp_file_name, TSK_NO_BUILD_INDEXES);
ret = tsk_table_collection_dump(&tables, _tmp_file_name, 0);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = tsk_table_collection_free(&tables);
CU_ASSERT_EQUAL_FATAL(ret, 0);
Expand Down
22 changes: 7 additions & 15 deletions c/tskit/tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ typedef struct {

typedef struct {
const char *name;
void *array;
const void *array;
tsk_size_t len;
int type;
} write_table_col_t;
Expand Down Expand Up @@ -9325,7 +9325,8 @@ tsk_table_collection_load(
}

static int TSK_WARN_UNUSED
tsk_table_collection_write_format_data(tsk_table_collection_t *self, kastore_t *store)
tsk_table_collection_write_format_data(
const tsk_table_collection_t *self, kastore_t *store)
{
int ret = 0;
char format_name[TSK_FILE_FORMAT_NAME_LENGTH];
Expand All @@ -9335,7 +9336,7 @@ tsk_table_collection_write_format_data(tsk_table_collection_t *self, kastore_t *
write_table_col_t write_cols[] = {
{ "format/name", (void *) format_name, sizeof(format_name), KAS_INT8 },
{ "format/version", (void *) version, 2, KAS_UINT32 },
{ "sequence_length", (void *) &self->sequence_length, 1, KAS_FLOAT64 },
{ "sequence_length", (const void *) &self->sequence_length, 1, KAS_FLOAT64 },
{ "uuid", (void *) uuid, TSK_UUID_SIZE, KAS_INT8 },
{ "metadata", (void *) self->metadata, self->metadata_length, KAS_INT8 },
{ "metadata_schema", (void *) self->metadata_schema,
Expand All @@ -9356,7 +9357,7 @@ tsk_table_collection_write_format_data(tsk_table_collection_t *self, kastore_t *

int TSK_WARN_UNUSED
tsk_table_collection_dump(
tsk_table_collection_t *self, const char *filename, tsk_flags_t options)
const tsk_table_collection_t *self, const char *filename, tsk_flags_t options)
{
int ret = 0;
FILE *file = fopen(filename, "wb");
Expand Down Expand Up @@ -9386,23 +9387,14 @@ tsk_table_collection_dump(
}

int TSK_WARN_UNUSED
tsk_table_collection_dumpf(tsk_table_collection_t *self, FILE *file, tsk_flags_t options)
tsk_table_collection_dumpf(
const tsk_table_collection_t *self, FILE *file, tsk_flags_t TSK_UNUSED(options))
{
int ret = 0;
kastore_t store;

memset(&store, 0, sizeof(store));

/* By default we build indexes, if they are needed. Note that this will fail if
* the tables aren't sorted. */
if ((!(options & TSK_NO_BUILD_INDEXES))
&& (!tsk_table_collection_has_index(self, 0))) {
ret = tsk_table_collection_build_index(self, 0);
if (ret != 0) {
goto out;
}
}

ret = kastore_openf(&store, file, "w", 0);
if (ret != 0) {
ret = tsk_set_kas_error(ret);
Expand Down
7 changes: 2 additions & 5 deletions c/tskit/tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,6 @@ typedef struct {
/* Leave room for more positive check flags */
#define TSK_NO_CHECK_POPULATION_REFS (1 << 10)

/* Flags for dump tables */
#define TSK_NO_BUILD_INDEXES (1 << 0)

/* Flags for load tables */
#define TSK_BUILD_INDEXES (1 << 0)

Expand Down Expand Up @@ -2712,7 +2709,7 @@ TSK_NO_BUILD_INDEXES
@return Return 0 on success or a negative value on failure.
*/
int tsk_table_collection_dump(
tsk_table_collection_t *self, const char *filename, tsk_flags_t options);
const tsk_table_collection_t *self, const char *filename, tsk_flags_t options);

/**
@brief Write a table collection to a stream.
Expand Down Expand Up @@ -2744,7 +2741,7 @@ TSK_NO_BUILD_INDEXES
*/

int tsk_table_collection_dumpf(
tsk_table_collection_t *self, FILE *file, tsk_flags_t options);
const tsk_table_collection_t *self, FILE *file, tsk_flags_t options);

/**
@brief Record the number of rows in each table in the specified tsk_bookmark_t object.
Expand Down
4 changes: 2 additions & 2 deletions c/tskit/trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,13 @@ tsk_treeseq_loadf(tsk_treeseq_t *self, FILE *file, tsk_flags_t TSK_UNUSED(option
}

int TSK_WARN_UNUSED
tsk_treeseq_dump(tsk_treeseq_t *self, const char *filename, tsk_flags_t options)
tsk_treeseq_dump(const tsk_treeseq_t *self, const char *filename, tsk_flags_t options)
{
return tsk_table_collection_dump(self->tables, filename, options);
}

int TSK_WARN_UNUSED
tsk_treeseq_dumpf(tsk_treeseq_t *self, FILE *file, tsk_flags_t options)
tsk_treeseq_dumpf(const tsk_treeseq_t *self, FILE *file, tsk_flags_t options)
{
return tsk_table_collection_dumpf(self->tables, file, options);
}
Expand Down
5 changes: 3 additions & 2 deletions c/tskit/trees.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ int tsk_treeseq_init(
int tsk_treeseq_load(tsk_treeseq_t *self, const char *filename, tsk_flags_t options);
int tsk_treeseq_loadf(tsk_treeseq_t *self, FILE *file, tsk_flags_t options);

int tsk_treeseq_dump(tsk_treeseq_t *self, const char *filename, tsk_flags_t options);
int tsk_treeseq_dumpf(tsk_treeseq_t *self, FILE *file, tsk_flags_t options);
int tsk_treeseq_dump(
const tsk_treeseq_t *self, const char *filename, tsk_flags_t options);
int tsk_treeseq_dumpf(const tsk_treeseq_t *self, FILE *file, tsk_flags_t options);
int tsk_treeseq_copy_tables(
const tsk_treeseq_t *self, tsk_table_collection_t *tables, tsk_flags_t options);
int tsk_treeseq_free(tsk_treeseq_t *self);
Expand Down