Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to overwrite a bitset. #200

Merged
merged 2 commits into from
Jul 17, 2024
Merged

Conversation

plietar
Copy link
Member

@plietar plietar commented Jul 15, 2024

This copies the value from one bitset to another one.

Copy link
Member

@giovannic giovannic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally this is fine.

I'm guessing this is to avoid memory allocation in $copy? If so, we could we make those implications clear in the docs for $copy and $assign

@plietar
Copy link
Member Author

plietar commented Jul 16, 2024

Somehow it hadn't even crossed my mind to just use copy for this. This does have a slight difference in behaviour in the case where the bitset is aliased, not that it matters much for the usecase I want it:

This will modify both x and y (since they are the same bitset):

x <- Bitset$new(10)
y <- x
x$assign(z)

Where as this will only modify x, by creating a new bitset:

x <- Bitset$new(10)
y <- x
x <- z$copy()

I still think this is useful to have. I'm not sure I love the name though. An alternative could be copy_from, inspired by Rust's clone_from.

I'll add the extra note to the docs you suggested.

This copies the value from one bitset to another one.
@plietar
Copy link
Member Author

plietar commented Jul 16, 2024

I've changed my mind and renamed to copy_from. Let me know what you think.

@plietar plietar requested a review from giovannic July 16, 2024 12:06
@plietar plietar merged commit 1e4b602 into mrc-ide:dev Jul 17, 2024
6 checks passed
@plietar plietar deleted the assign-bitset branch July 17, 2024 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants