Skip to content

Add "takeset" methods to Tables API #2016

Closed

Description

@jeromekelleher

We want to provide a way to hand over buffers to tskit, so that we can avoid the overhead of having two copies of the same data.

In #2006 we discussed the idea of adding a TSK_TAKE_OWNERSHIP flag to the existing x_table_set_columns and x_table_set_metadata (etc) methods. However, this would require adding an options parameter and removing the const qualifiers from all the parameters. This would break peoples code, make the library less easy to analyse by compilers and static analysis tools, and wreak utter havoc on our test suite (unless we turned off lots of warnings).

As discussed here and in following comments, we decided it was simpler to add new methods, which would be the same as the existing x_set_y methods, but would take the buffer(s) instead of copying them.

We also considered renaming the current x_set_y methods to x_copy_y, to better convey their semantics. This would be an annoying and noisy change to library users, though.

On reflection, I suggest the following.

  • We keep the current methods like tsk_node_table_set_columns and tsk_reference_sequence_set_data, documenting them as "set the properties of the object to copies of the specified values"
  • We add new methods like tsk_node_table_takeset_columns and tsk_reference_sequence_takeset_data, documenting them as "set the properties of the object to the specified values and take ownership of the buffers". These would (correctly) have non-const arguments.

I like this because it doesn't break any existing code. I prefer takeset to just take because it makes it a bit clearer that we're doing the equivalent of set except we're also taking control of the buffer. If we're being purists it should be take_set rather than takeset, but I like the compound because it emphasises that it's one action, and given that there's four underscores in the name above, it makes it a bit clearer. We could say "settake", but it doesn't roll off the tongue quite as easily for me.

I've done an initial pass on doing this for the reference sequence over in #2011

Any thoughts @benjeffery @bhaller @molpopgen ?

Activity

  1. added
    C API
    on Dec 5, 2021
  2. added this to the C API 1.0.0 milestone on Dec 5, 2021
  3. bhaller commented on Dec 5, 2021

    @bhaller

    This all sounds good to me. Not sure about takeset vs. just take, but no real objection to it. :->

  4. benjeffery commented on Dec 6, 2021

    @benjeffery
    Member

    I like this, as I said elsewhere takeset is great as it seems a bit odd and unfamiliar, which it should be as you can shoot yourself in the foot and will help to get people to read the docs to know what it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C API

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions